|
|
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Is it possible to set the Font type for the arrayctrl?
|
|
|
|
Re: Is it possible to set the Font type for the arrayctrl? [message #3108 is a reply to message #3104] |
Sun, 07 May 2006 19:44 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
forlano wrote on Sun, 07 May 2006 14:45 | This time the composite widget should not be a problem because I do not need to retrieve data. But I am afraid of the array cursor that could be not aware that I clicked on the label.
Ok, I'll do some experiment... but gime ve time and I'll post a test case.
Luigi
|
Well, I was too optimistic .
You can see how it looks the twolabel widget. It is very nice (I would add the national flag of the player one day), but the array cursor as usual is unsensitive to the click on the embedded ctrl. So when the array is covered by label I hope to move this damned cursor.
Moreover, and most important, I was not able to set these labels as I wanted! You can see the two edits that wait to be sent in the twolabel widget and then in the array but the callback is absent
I attach the code, maybe some volunter will retouch it. So we returned again on the set method of the previous thread. If I can see how work the "Set" maybe I'll catch the "Get" one.
Thank you
#include <CtrlLib/CtrlLib.h>
#define LAYOUTFILE <twolabelwidget/a.lay>
#include <CtrlCore/lay.h>
//--------------------- begin class -----------------
class TwoLabel : public WithTwoLabel<ParentCtrl> {
String str1;
String str2;
public:
typedef TwoLabel CLASSNAME;
void WriteLabel(String s1, String s2);
TwoLabel();
};
void TwoLabel::WriteLabel(String s1, String s2) //should be the Constructor?
{ str1 = s1;
str2 = s2;
}
TwoLabel::TwoLabel()
{ CtrlLayout(*this);
str1 = "left";
str2 = "right";
lbl1.SetLabel( str1 );
lbl2.SetLabel( str2 );
}
void Extra2(One<Ctrl>& ctrl)
{ ctrl.Create<TwoLabel>();
}
//--------------------- end class -------------------
//--------------------- begin class MyApp-----------------
class MyApp : public TopWindow {
TopWindow w;
ArrayCtrl arr;
Button btn;
EditString edit1, edit2;
public:
typedef MyApp CLASSNAME;
MyApp();
void SetIntoArray();
};
void MyApp::SetIntoArray()
{ TwoLabel twolbl;
String s1, s2;
s1 = ~edit1;
s2 = ~edit2;
arr.Add("aaa", Null/* ??? */);
}
MyApp::MyApp()
{ Add(arr);
arr.SizePos();
arr.AddColumn("col1",20);
arr.AddColumn("col2",20).Ctrls(Extra2);
arr.SetLineCy(20);
arr.Add("aaa");
arr.Add("bbb");
arr.Add("ccc");
arr.Inserting(true);
Add(edit1);
Add(edit2);
edit1.LeftPosZ(48, 76).TopPosZ(280, 19);
edit2.LeftPosZ(140, 76).TopPosZ(280, 19);
Add(btn);
btn.SetLabel("set into array").LeftPosZ(236, 88).TopPosZ(280, 20);
btn.WhenAction = THISBACK(SetIntoArray);
}
//--------------------- end MyApp -------------------
GUI_APP_MAIN
{ MyApp a;
a.Sizeable().Run();
}
/////////////////////////
layout file: a.lay
LAYOUT(TwoLabel, 188, 20)
ITEM(Label, lbl1, SetFont(StdFont(13).Bold()).SetInk(SLtBlue).LeftPosZ(4, 128).VCenterPosZ(17, 1))
ITEM(Label, lbl2, SetAlign(ALIGN_CENTER).SetFont(StdFont(13).Bold()).SetInk(SLtRed).LeftPosZ(132, 56).VCenterPosZ(17, 1))
END_LAYOUT
-
Attachment: swiss4.jpg
(Size: 11.88KB, Downloaded 1516 times)
|
|
|
|
|
|
Re: Is it possible to set the Font type for the arrayctrl? [message #3852 is a reply to message #3840] |
Sat, 01 July 2006 09:38 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
luzr wrote on Thu, 29 June 2006 20:16 |
And yes, you can of course use Display to change the font. Alternatively, you can use AttrText as Value to do the same.
Mirek
|
I believed it was easy, and maybe it is, but I was unable to set the font of the column of the array. Below there is the code that set in red some cell of the arrayctrl. Does anybody know how to modify it to set the font, say Curier, of the column using one of the method listed above by Mirek?
Thanks a lot.
Luigi
#include <CtrlLib/CtrlLib.h>
class NumbersOnRed : public Display
{
public:
static bool numberString(String s);
void PaintBackground(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const;
};
bool NumbersOnRed::numberString(String s)
{
if(s.GetCount() == 0)
return false;
int i = 0;
if(s[0] == '+' || s[0] == '-')
i++;
while(i < s.GetCount() && s[i] >= '0' && s[i] <= '9')
i++;
return i == s.GetCount();
}
void NumbersOnRed::PaintBackground(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const
{
if(IsNumber(q) || (IsString(q) && numberString(AsString(q))))
paper = Color(255, 150, 150);
Display::PaintBackground(w, r, q, ink, paper, style);
}
GUI_APP_MAIN
{
ArrayCtrl array;
array.AddColumn("value").SetDisplay(Single<NumbersOnRed>());
array.Add("test1");
array.Add("2test");
array.Add("3 test");
array.Add("4");
array.Add("test");
array.Add("-99");
TopWindow win;
win.Zoomable().Sizeable();
win.Add(array.SizePos());
win.Run();
}
|
|
|
|
Re: Is it possible to set the Font type for the arrayctrl? [message #3943 is a reply to message #3920] |
Mon, 10 July 2006 15:46 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
luzr wrote on Sun, 09 July 2006 16:04 | Please check reference/Display.
|
It does work!
Let me show the steps done for the next generations:
1. create a column of the arrayctrl in this way:
arrp.AddColumn("wname", "White Player", 19).SetDisplay(Single<FontDisplay>());
Here should be noted the SetDisplay() method that does the job.
2. Create the following singletone ( ) derived by Display:
struct FontDisplay : Display {
virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const
{
Font fnt = Courier(14);
String txt = AsString(q);
w.DrawRect(r, paper);
w.DrawText(r.left + 2, r.top + (r.Height() - GetTextSize(txt, fnt).cy) / 2, txt, fnt, ink);
}
};
Of course one may want to set a different foreground color (ink), different font size and so on.
Quote: |
If all you need is different font, you can also use
AttrText("My cell text").SetFont(Courier(14));
as the value you put inside the ArrayCtrl.
Mirek
|
I've not understood what to do in this last case, but it doesn't matter. For today it's enough. Now I want to study the singletone to really understand what I've done
Luigi
[Updated on: Mon, 10 July 2006 15:47] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Thu May 16 19:48:00 CEST 2024
Total time taken to generate the page: 0.03634 seconds
|
|
|