Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » how align a column?
|
|
Re: how align a column? [message #5397 is a reply to message #5394] |
Mon, 18 September 2006 14:26 |
|
mirek
Messages: 13984 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.
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 #10496 is a reply to message #5397] |
Thu, 12 July 2007 21:21 |
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 #10506 is a reply to message #10502] |
Thu, 12 July 2007 23:54 |
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 |
|
mirek
Messages: 13984 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 .
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 |
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 .
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 |
|
mirek
Messages: 13984 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...
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
|
|
|
Goto Forum:
Current Time: Sat Jun 08 08:03:54 CEST 2024
Total time taken to generate the page: 0.02114 seconds
|