Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Is it possible to set the Font type for the arrayctrl?
Is it possible to set the Font type for the arrayctrl? [message #3091] Sat, 06 May 2006 14:56 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

how can be seen in the following picture the numbers are not aligned vertically although each row has been formatted and contains always the same numbers of chars.
If I could use the Courier font the problem would disappear. Unfortunately I was not able (I used even Navigate...) to found something useful to set the font and maybe the color.
A workaround is to use label inside each cell. Another is to assign a new column to the number but I do not like the vertical line between the name and the number.

Luigi
  • Attachment: arrfont.png
    (Size: 13.37KB, Downloaded 1149 times)
Re: Is it possible to set the Font type for the arrayctrl? [message #3092 is a reply to message #3091] Sat, 06 May 2006 15:10 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
I guess something like this could be helpful:
http://www.arilect.com/upp/forum/index.php?t=msg&th=234& amp;start=0&
Re: Is it possible to set the Font type for the arrayctrl? [message #3101 is a reply to message #3092] Sun, 07 May 2006 13:00 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
One more idea. What if to use composite ctrl (2 labels inside one cell?) once again?
Re: Is it possible to set the Font type for the arrayctrl? [message #3104 is a reply to message #3101] Sun, 07 May 2006 14:45 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
fudadmin wrote on Sun, 07 May 2006 13:00

One more idea. What if to use composite ctrl (2 labels inside one cell?) once again?

I thought about one label for cell and set the font courier. But your idea seems better because I can format each of them in different manner (style and color)... yes, good idea Smile
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.
BTW, is there a label that can be formatted in QTF? I couldn't found it. Perhaps should be easy to do it spying in the code of some Prompt method in which the QTF string can be set.

Luigi
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 Go to previous messageGo to next message
forlano is currently offline  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 Smile .
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 Confused
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 1513 times)
Re: Is it possible to set the Font type for the arrayctrl? [message #3111 is a reply to message #3091] Sun, 07 May 2006 19:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Sat, 06 May 2006 08:56

Hello,

how can be seen in the following picture the numbers are not aligned vertically although each row has been formatted and


If they look "vertically unaligned", it is decision of font designer, not U++ - it does vertical centering based on font height (in StdDisplay, which is relevant here).

Mirek
Re: Is it possible to set the Font type for the arrayctrl? [message #3826 is a reply to message #3108] Wed, 28 June 2006 18:45 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Let's come back on this old topic about font and arrayctrl.

Here http://www.arilect.com/upp/forum/index.php?t=msg&th=234& amp;start=0& we've seen how powerful is the singleton technique and how it is used in conjuction with SetDisplay to set the color of a cell/column.
The question now is: can the same technique be applied to change the font (to curier for example) of one column of the arrayctrl?

I do not need to change the font of the overall application, but only locally in the arrayctrl.

Luigi
Re: Is it possible to set the Font type for the arrayctrl? [message #3840 is a reply to message #3826] Thu, 29 June 2006 20:16 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Wed, 28 June 2006 12:45

Let's come back on this old topic about font and arrayctrl.

Here http://www.arilect.com/upp/forum/index.php?t=msg&th=234& amp; amp;start=0& we've seen how powerful is the singleton technique and how it is used in conjuction with SetDisplay to set the color of a cell/column.
The question now is: can the same technique be applied to change the font (to curier for example) of one column of the arrayctrl?

I do not need to change the font of the overall application, but only locally in the arrayctrl.

Luigi



Tehchnical note: It is not singleton what is powerful here. Display does not have to be singleton, often it is not.

And yes, you can of course use Display to change the font. Alternatively, you can use AttrText as Value to do the same.

Mirek
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 Go to previous messageGo to next message
forlano is currently offline  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 #3920 is a reply to message #3091] Sun, 09 July 2006 16:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Please check reference/Display.

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
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 Go to previous messageGo to next message
forlano is currently offline  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! Very Happy

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 ( Rolling Eyes ) 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 Smile

Luigi

[Updated on: Mon, 10 July 2006 15:47]

Report message to a moderator

Re: Is it possible to set the Font type for the arrayctrl? [message #3947 is a reply to message #3943] Mon, 10 July 2006 17:31 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
arrp.Add(AttrText("My cell text").SetFont(Courier(14)));


Mirek
Previous Topic: Combine Cells?
Next Topic: About the movement of a row in a ArrayCtrl
Goto Forum:
  


Current Time: Sun Apr 28 23:26:25 CEST 2024

Total time taken to generate the page: 0.02816 seconds