How use different font styles and icon in a Firemonkey stringgrid cell - delphi

There seems to be not much information available about this subject so hopefully someone can give some suggestions.
I would like to change color and style of different parts of text in a stringgrid cell.
Example:
20-02-2011 - Document Title
Would it also be possible to show an icon in a stringgrid cell?

It is indeed possible to show icons or bitmaps in a string grid, the Monkey Styler blog includes an example of how to customise cell display in a FMX grid.
http://monkeystyler.com/blog/entry/firemonkey-grid-basics-custom-cells-and-columns
Thinking about the other part of your question though, you will have to build a style up to display text in different fonts, as yet FMX does not have a richtext equivalent or HTML rendering components (I'm sure the latter will come, the former I am not confident on getting for a while!). You would have to have a text component in the style for each different font size/style etc, you would need to name the text elements (using binding or stylename properties) and handle the setting of the text contents using code in the ongetvalue and onsetvalue events (I guess you could also use a onapplystyle event) to display some text in bold and some not.
The event handler would then use either a binding - which is easier to set but - in my experience - buggy;
mycell.binding['boldtext']:='sometext';
Or find a style element by stylename by using findstyleresource;
tempobj:=mycell.findstyleresource('boldtext');
if tempobj is ttext then
ttext(tempobj).text='sometext';
Excuse any bad coding style there, but you get the general idea (I hope) if you set autosize to true for the ttext components in the style and align them left you get - mostly - what you are after. The only issue is that the resulting text doesn't look quite seamless because autosizing and aligning left doesn't really give you the same space between the fonts that you would get with a richtext or HTML display. You should be able to fiddle with the padding (giving it a negative number for the left padding should allow you to remove any extra space) but you have to live with that not being entirely perfect compared to proper font hinting and alignment.

Related

Make TMemo show partially visible lines

Is it possible to make TMemo show partially visible lines? I'm looking for a native way to do that, without custom rendering.
I made an example screenshot for those who not familiar with this issue:
As you can see,, in the area I marked with red, there is enough space to display some part of the next line that is not visible by default.
There are some components, like TListBox, which show partially visible lines, so I want to make TMemo do the same.
P.S. I'm not interested in other suggestions, like enlarging the TMemo size, that's off-topic.
It's not possible to make a TMemo to show partial lines. For what you can do natively to a memo, which is a multiline edit control, see edit controls on MSDN.
You could use a TRichEdit instead.
You can access the Lines and Text properties, just like for a TMemo. It also has the WordWrap, ReadOnly and ScrollBars properties, just like TMemo, so it could be a drop-in replacement, but showing partial lines at the bottom as required.
Tested in Delphi 10.1 Berlin as well.

FMX progressbar color

Please be kind, I did my best with google, and found some guidance (also on StackOverflow), but none of it works for me.
FMX form with FMX Progressbar;
I only want to change the progressbar color from ugly yellow to cool skyBlue.
So far I've dropped a stylebook on the form;
I've added "progresscellstyle.htrack.hindicator" to the stylesheet designer;
It's the only one that even provides me with a color option (vs everything in "progressbarstyle treeitem") and that color does not influence my progressbar colour.
Please, a next step to decoding this problem if you could be so kind
Drop a TProgressBar on the form. Right click it and select Edit Custom Style. It should give you the style designer with a ProgressBar1Style1 object which contains htrack and vtrack.
htrack contains hindicator. Drop a TRectangle on the hindicator. Set the TRectangle to align Client. Change the Fill color as desired. Change the Stroke Kind to None.
vtrack contains vindicator. Drop a TRectangle on the vindicator. Set the TRectangle to align Client. Change the Fill color as desired. Change the Stroke Kind to None.
Close the style designer and save when it asks. This is one way to do it.
This may be a title old question, but the content about this is so rare that I think will be useful to future generations to have some info here.
To simply put, to change the color that will fill your bar you have to select a area in your BitmapLinks. To do that double click in the SourceLink property in the hindicator (a child of htrack in the tree view).
Then select a are that you will want to use as the filling, if none of the option pleases you, you may add a new BitMap to your StyleBook.
For the background color, just insert a rectangle inside htrack with a Client Alignment

Icon in header row for column setup

I would like to add an icon to the header of my data grid as it is done in Thunderbird.
There is an icon that is above the vertical scrollbar, no matter the position of the horizontal scrollbar. This icon allows the setup of the columns.
In Delphi there a lot of different grid components, that allow customizations and adding icons to there cells / header cells. But I could not find any component that has an area above the vertical scrollbar that is fixed, which when clicked allows some action. I could even use the VirtualTreeView component to emulate the grid, if it turns out to be easier to customize that component.
I am looking for some guidance on what need to be done to get that functionality.
Thanks,
Thomas
VirtualTreeView in Listbox mode would be nice, because of it's speed, great documentation and ease use in MVC-like patterns. Delphi tempts to store data in the visual components themselves, which letter causes troubles. While VTW allwos the same, it also allows to acutally separate data from GUI, and i like it.
But i am surprised by your claim "which when clicked allows some action.".
Even most basic components allow it:
http://docwiki.embarcadero.com/Libraries/XE2/en/Vcl.Grids.TCustomGrid.OnFixedCellClick
So could you make more detaiils, why you cannot use standard components ? with screenshot and editors, how u want it rendered, where you want to click and what kind of action should happen ?

Delphi XE2 Firemonkey - Setting the grid display colour and alignment

I am struggling to assign a style to a TGrid within Delphi Firemonkey. Styling required is quite basic (ie. Align the text in a column and colour per value).
For background, I have created a TGrid, set the rows (eg 200), and added the number of columns (3 in this case). The columns have been labeled as "Code", "Company" and "Balance". As the grid does not contain values (like a TStringGrid), I am able to set the display value via the "GetValue" method (where I retrieve data from an external source). - The result is a list that is fast, and able to cope with a lot of data, the downside is I can not format the design at run time...
I am thinking that I may have to use "Styles"; that are new in FM. If this is the case however, I am not sure how I can reference the cell as it does not really exist as it is painted via the GetValue method when it needs to be drawn?
Any help appreciated,
Regards
Ian.
Ray Konopka's blog might help you here:
http://www.raize.com/Articles/FmxStringGridCellFonts.asp
You can apply a style to a Column by creating the OnApplyStyleLookup event to the column, but to set the font style and color etc you would still need to implement a OnApplyStyleLookup for the TTextCell's themselves too.
I posted a very similar query on Stackoverflow and then found a workable solution which I added here
firemonkey mobile grid with livebindings - changing TextCell text color at runtime XE5

Display simple markup in a Label in Delphi

I am currently displaying some text in a TLabel. I would now like to emphasise certain words within the text by displaying them in bold or perhaps italic. What is the recommended way to do this in Delphi? Is there a TLabel-like component that can display simple HTML or markup?
I am imagining some code like this:
label.text:='This information is <b>important</b>';
I am using Delphi 2010
JvHTLabel in the JVCL will do the trick very nicely. Download the whole library from http://jvcl.delphi-jedi.org/
Check the THtmlViewer components are free and compatible with delphi 2010.
One more:
Delphi Markup Label
The Delphi Markup Label is a label component for Delphi that supports some HTML-like tags to format the displayed text. Amongst others, it supports tags for hyperlinks, tabs, font size, color and styles. The full list of tags can be found in the accompanying test tool.
http://www.infintuary.org/stlabel.php
Single pas file, compiled demo included. Some formatting is implemented via self-made tags so it won't be classic HTML. Has no transparence.
If you are already using a newer version of Delphi (at least the XE2 version), you can take a look at my TDzHTMLText component at: https://github.com/digao-dalpiaz/DzHTMLText
This component is a label with some HTML tags support, allowing you to format the text with Bold, Italic, Underline, Font Color, Font Size, Background Color, Tab Alignment, Text Alignment (left, center, right).
Check a print example:
DzHTMLText component example at design-time
The list below describes all possible tags to format label text:
<A[:abc]></A> - Link
<B></B> - Bold
<I></I> - Italic
<U></U> - Underline
<S></S> - Strike out
<FN:abc></FN> - Font Name
<FS:123></FS> - Font Size
<FC:clColor|$999999></FC> - Font Color
<BC:clColor|$999999></BC> - Background Color
<BR> - Line Break
<L></L> - Align Left
<C></C> - Align Center
<R></R> - Aligh Right
<T:123></T> - Tab
<TF:123></TF> - Tab with aligned break
Some ideas:
Have a look at TLinkLabel in ExtCtrls.
It lets you add links.. it paints the linked part underlined. Maybe you can steal the code and add support for other tags like <b> <i> <strong> <em>?
You can use a TRichEdit component.. It's not HTML as you describe, but it should do the trick of formatting your text.
Use TjanMarkupLabel from this page.
"TjanMarkupLabel is a TGraphicControl descendant that renders its Text property in HTML style. Supported tags: Bold, Italic, Underline, Font (face, size and color) and Break."

Resources