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 » how align a column?
how align a column? [message #5394] Mon, 18 September 2006 14:16 Go to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
Hey

I have a ArrayCtrl in which a column represents money and I build it thus:

 theList.AddColumn("donativo").SetFormat("%2!nl").HeaderTab().SetAlign(ALIGN_RIGHT); 


The numerical columns see far better if they are aligned to right.

Nevertheless the alignment only affects to the header, not to the data in the column.

index.php?t=getfile&id=266&private=0

I believe that it must be possible that all a column is aligned, but encounter the function or the method not to do it.

Somebody can give an instructions to me.

Nico
  • Attachment: align.png
    (Size: 4.51KB, Downloaded 3330 times)
Re: how align a column? [message #5396 is a reply to message #5394] Mon, 18 September 2006 14:26 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
You can create a member in your class:
AlignDisplay m_right_align_display;


Set it up in constructor:
m_right_align_display.Align(ALIGN_RIGHT);


and setup the arrayctrl column:
theList.AddColumn("donativo").SetFormat("%2!nl").HeaderTab().SetDisplay(m_right_align_display);
Re: how align a column? [message #5397 is a reply to message #5394] Mon, 18 September 2006 14:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
nicomesas wrote on Mon, 18 September 2006 08:16

Hey

I have a ArrayCtrl in which a column represents money and I build it thus:

 theList.AddColumn("donativo").SetFormat("%2!nl").HeaderTab().SetAlign(ALIGN_RIGHT); 


The numerical columns see far better if they are aligned to right.

Nevertheless the alignment only affects to the header, not to the data in the column.

index.php?t=getfile&id=266&private=0

I believe that it must be possible that all a column is aligned, but encounter the function or the method not to do it.

Somebody can give an instructions to me.

Nico




Using Display.

In my commercial apps, I am using this one:

class DisplayMoney : public Display {
public:
	void Paint(Draw& w, const Rect& r, const Value& q,
		       Color ink, Color paper, dword style) const;

protected:
	Font   font;
	bool   red;

public:
	static DisplayMoney Normal;
	static DisplayMoney Bold;
	static DisplayMoney NormalRed;


	DisplayMoney& SetFont(Font _font)  { font = _font; return *this; }
	DisplayMoney& Red(bool b)          { red = b; return *this; }
	DisplayMoney& NoRed()              { return Red(false); }

	DisplayMoney(Font font = GuiFont(), bool red = true) : font(font), red(red) {}
};

void DisplayMoney::Paint(Draw& w, const Rect& r, const Value& q,
						 Color ink, Color paper, dword s) const {
	String text;
	if(!IsNull(q)) text = FormatMoney(q);
	int cx = GetSmartTextSize(w, text, font).cx;
	w.DrawRect(r, paper);
	DrawSmartText(w, r.left + r.Width() - cx, r.top, r.Width(), text, font,
		          double(q) < 0 ? (s & CURSOR) && (s & FOCUS) ? SLtRed: SRed : ink);
}



You can achieve pretty much any appearance using Display. To use it, make instance that outlives ArrayCtrl (static variable is enough) and assign it to the ArrayCtrl columns using SetDisplay.
Re: how align a column? [message #5401 is a reply to message #5397] Mon, 18 September 2006 15:06 Go to previous messageGo to next message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
Thanks

Your code will be to me of much aid in the future

Nico
Re: how align a column? [message #10496 is a reply to message #5397] Thu, 12 July 2007 21:21 Go to previous messageGo to next message
kfeng is currently offline  kfeng
Messages: 18
Registered: July 2007
Location: Tokyo, Japan
Promising Member
Hi,

This code is extremely useful.

May I ask how or where GuiFont() and FormatMoney() are defined?

It seems that the code base may have changed somewhat since the original posting:

f:\myapps\testapp\TestApp.h(38) : error C2660: 'Upp::GetSmartTextSize' : function does not take 3 arguments
f:\myapps\testapp\TestApp.h(38) : error C2228: left of '.cx' must have class/struct/union

Thx.

- Ken

[Updated on: Thu, 12 July 2007 21:29]

Report message to a moderator

Re: how align a column? [message #10502 is a reply to message #10496] Thu, 12 July 2007 21:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Not in uppsrc, only in my apps.

GuiFont is just an old name for StdFont, provided in my commercial apps lib to achieve backward compatibility.

inline Font GuiFont() { return StdFont(); }

String FormatMoney(double money) {
	return IsNull(money) ? EmptyString : Format("%.2f", money);
}


Mirek
Re: how align a column? [message #10506 is a reply to message #10502] Thu, 12 July 2007 23:54 Go to previous messageGo to next message
kfeng is currently offline  kfeng
Messages: 18
Registered: July 2007
Location: Tokyo, Japan
Promising Member
Hi Mirek,

Thanks for the quick reply. BTW, I scoured the code base and found another thread which talked about changes to the code. For others, this apparently works now:

myArrayCtrl.AddColumn( "colName" ).SetDisplay( StdRightDisplay() );

Other possibilities are StdDisplay() and StdCenterDisplay().

I will look at your Money code closely this weekend and see if I can get it to compile/run on my machine.

Another question: is there a standard format for displaying %d or %f like this:

$58,782,398.23

with commas? If not, maybe you can guide me to where I can add code for this feature with any suggestions on the protocol. If you do, I can code it up and submit it for addition to the code base.

Thank you.

Regards,
Ken

Re: how align a column? [message #10507 is a reply to message #10506] Fri, 13 July 2007 00:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kfeng wrote on Thu, 12 July 2007 17:54


Another question: is there a standard format for displaying %d or %f like this:

$58,782,398.23

with commas?



No.

Quote:


If not, maybe you can guide me to where I can add code for this feature with any suggestions on the protocol. If you do, I can code it up and submit it for addition to the code base.



But you in fact do not need to fix uppsrc code to get it: Format is extensible, you can add your own formatters quite easily, see RegisterFormatter (it is even documented Wink.

In the same time, would be nice to have it in Core too later, but for that purpose it would best be done configurable via translations... (means it should be described by some string literal, just like date or time).

Mirek

[Updated on: Fri, 13 July 2007 00:57]

Report message to a moderator

Re: how align a column? [message #10532 is a reply to message #10507] Sat, 14 July 2007 09:36 Go to previous messageGo to next message
kfeng is currently offline  kfeng
Messages: 18
Registered: July 2007
Location: Tokyo, Japan
Promising Member
luzr wrote on Fri, 13 July 2007 00:55

kfeng wrote on Thu, 12 July 2007 17:54


Another question: is there a standard format for displaying %d or %f like this:

$58,782,398.23

with commas?



No.

Quote:


If not, maybe you can guide me to where I can add code for this feature with any suggestions on the protocol. If you do, I can code it up and submit it for addition to the code base.



But you in fact do not need to fix uppsrc code to get it: Format is extensible, you can add your own formatters quite easily, see RegisterFormatter (it is even documented Wink.

In the same time, would be nice to have it in Core too later, but for that purpose it would best be done configurable via translations... (means it should be described by some string literal, just like date or time).

Mirek



Hi Mirek,

Internationalization is a little beyond me for now, so I will just submit a little snipplet for others to use/incorporate into their code:
String CommaFormatter(const Formatting& f)
{
  int    commaSpacing = 3;  // fix at 3 for now
  String res          = Format( "%" + f.format + "f", f.arg );  // replace our format with "f"
  int    period       = res.Find( '.' );
  int    idx          = (period<0) ? res.GetLength() : period;
  while( (idx-=commaSpacing)>0 )
    res.Insert( idx, ',' );	
  return res;
}

// Test it
RegisterNumberFormatter("C",  CommaFormatter);
String test = Format( "%.2C", 35829123.4253 );
// 35,829,123.43


- Ken
Re: how align a column? [message #10572 is a reply to message #10532] Mon, 16 July 2007 23:53 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kfeng wrote on Sat, 14 July 2007 03:36


Hi Mirek,
Internationalization is a little beyond me for now, so I will just submit a little snipplet for others to use/incorporate into their code:



Nothing magic there, just remember that each text literal marked by "t_" can be replaced for another language... Smile

In this case, you can e.g. try to "describe" the situation by

t_(",3.2")

- first character is "integer character separator", second number of digits to separate, third decimal point character and last number of decimal digits.

For e.g. Czech it would be translated to:

" 3,2"

which would lead to:

35 829 123,43

(just an idea!)

Mirek

Mirek
Previous Topic: GridCtrl and non contigous cells
Next Topic: Can I center an Option control in an ArrayCtrl column?
Goto Forum:
  


Current Time: Mon Apr 29 03:47:27 CEST 2024

Total time taken to generate the page: 0.03208 seconds