Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Substring formating in ArrayCtrl (SqlCtrl)
|
|
Re: Substring formating in ArrayCtrl (SqlCtrl) [message #22817 is a reply to message #22807] |
Wed, 19 August 2009 03:58 |
|
bushman
Messages: 134 Registered: February 2009
|
Experienced Member |
|
|
If you meant,
ArrayCtrl arr;
arr.AddColumn("Highlighted");
...
arr.Add("[* Ultimate++] is great!");
Iīve tried that, but unfortunately it didnīt work.
Iīve devised a way, but I donīt know wheather thereīs some simpler solution. It requires overwriting the Display::Paint method, like in the code below:
struct HighlightDisplay : public Display {
static String term;
virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
{
w.DrawRect(r, paper);
Font font = StdFont();
String s(q);
/* check if thereīs any substring to highlight in text passed to display*/
int ix = ToLower(s).Find(ToLower(term));
if(ix >= 0) {
Font bold = StdFont().Bold();
/* break down text into highlighted and plain strings */
String s0 = s.Mid(0, ix);
String s1 = s.Mid(ix, term.GetCount()); // <-- substring to highlight
String s2 = s.Mid(ix + term.GetCount());
/* draw highlighted and plain strings */
w.DrawText(r.left, r.top, s0, font, ink);
w.DrawText(r.left + GetTextSize(s0, font).cx, r.top, s1, bold, Blue()); // <-- highlights in bold and blue
w.DrawText(r.left + GetTextSize(s0, font).cx + GetTextSize(s1, bold).cx, r.top, s2, font, ink);
return;
}
w.DrawText(r.left, r.top, s, font, ink);
}
};
String HighlightDisplay::term = "";
Then I can write
ArrCtrl arr;
arr.AddColumn("Highlighted").SetDisplay(Single<HighlightDisplay>());
...
//set term to highlight through HighlightDisplay::term static member:
HighlightDisplay::term = "Ultimate++";
arr.Add("Ultimate++ is great!");
Iīve been using this code and it has worked fine. I just thought there must be another SIMPLER way of doing it.
Thanks anyway.
[Updated on: Wed, 19 August 2009 04:08] Report message to a moderator
|
|
|
Re: Substring formating in ArrayCtrl (SqlCtrl) [message #22819 is a reply to message #22817] |
Wed, 19 August 2009 06:22 |
Novo
Messages: 1358 Registered: December 2006
|
Ultimate Contributor |
|
|
Sorry, I mislead you. I checked with my code where I use text attributes with TreeCtrl. I use AttrText, which is handled by all standard Display classes. The code looks like
vf_id = wtree.Add(parent_id, TreeCtrl::Node(AttrText("Verb frames").Ink(LtBlue())));
AttrText is not that flexible as QTF is. It just lets you set attributes for the whole text.
If I need to display a QTF text as a node I create a RichTextCtrl and set it as a node of a tree. The same technique should work with ArrayCtrl.
My code looks similar to an example below.
Array<RichTextCtrl> rt_ctrl;
rt_ctrl.Add().SetZoom(zoom).NoSb().SetQTF(tree_str);
rt_ctrl.Top().WhenLink = THISBACK(on_link);
// Zoom related suff ...
int x = rt_ctrl.Top().GetWidth();
Size sz(x, rt_ctrl.Top().GetHeight(x));
sz = zoom * sz;
sz.cx += 1;
wtree.Add(parent_id, TreeCtrl::Node(rt_ctrl.Top()).SetSize(sz));
Regards,
Novo
|
|
|
|
|
Goto Forum:
Current Time: Thu Mar 28 10:26:38 CET 2024
Total time taken to generate the page: 0.01215 seconds
|