Home » U++ Library support » Look and Chameleon Technology » Chameleon-ized EditField
Chameleon-ized EditField [message #9190] |
Fri, 20 April 2007 13:30 |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
I would like EditFields to change color when they have focus (as they do when they have invalid data). However, because so many controls are derived from EditField it is unpleasant to modify the Paint method.
Instead I have given the control a simple Chameleon style that functions identically to the original but exposes a Color that can be set when it has focus. My version is attatched.
Would it be possible to have something similar incorporated into the Upp::CtrlLib package so that I don't have to update the source myself?
[Updated on: Fri, 20 April 2007 13:31] Report message to a moderator
|
|
|
|
|
Re: Chameleon-ized EditField [message #10352 is a reply to message #9193] |
Tue, 03 July 2007 18:41 |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
Currently disabled EditFields show pink if they have invalid data, which doesn't make sense to me, so I've added an extra check (and it now caches the result of IsShowEnabled since it's called 5 times):
void EditField::Paint(Draw& w)
{
Size sz = GetSize();
bool f = HasBorder();
bool enabled = IsShowEnabled();
const EditField::Style *st = style ? style : &StyleDefault();
Color paper = enabled && !IsReadOnly() ? (HasFocus() ? st->focus : st->paper) : st->disabled;
if(nobg)
paper = Null;
Color ink = enabled ? st->text : st->textdisabled;
if(convert && enabled && convert->Scan(text).IsError())
paper = st->invalid;
int fcy = font.Info().GetHeight();
int yy = GetTy();
w.DrawRect(0, 0, 2, sz.cy, paper);
w.DrawRect(0, 0, sz.cx, yy, paper);
w.DrawRect(0, yy + fcy, sz.cx, sz.cy - yy - fcy, paper);
w.DrawRect(sz.cx - 2, 0, 2, sz.cy, paper);
w.Clipoff(2, yy, sz.cx - 4, fcy);
int x = -sc;
if(IsNull(text) && !IsNull(nulltext)) {
const wchar *txt = nulltext;
Paints(w, x, fcy, txt, nullink, paper, nulltext.GetLength(), false);
}
else {
const wchar *txt = text;
int l, h;
if(GetSelection(l, h)) {
Paints(w, x, fcy, txt, ink, paper, l, password);
Paints(w, x, fcy, txt, enabled ? st->selectedtext : paper,
enabled ? st->selected : ink, h - l, password);
Paints(w, x, fcy, txt, ink, paper, text.GetLength() - h, password);
}
else
Paints(w, x, fcy, txt, ink, paper, text.GetLength(), password);
}
w.DrawRect(x, 0, 9999, fcy, paper);
w.End();
// w.DrawRect(dropcaret, LtBlue());
DrawTiles(w, dropcaret, CtrlImg::checkers());
}
Could this be added to Uppsrc please?
James
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 01:01:26 CET 2024
Total time taken to generate the page: 0.03008 seconds
|