CtrlLib: Optimized ToolBar refreshes

git-svn-id: svn://ultimatepp.org/upp/trunk@7938 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-12-01 15:28:45 +00:00
parent dfb80fe504
commit c844ab87cd
8 changed files with 51 additions and 13 deletions

View file

@ -289,7 +289,7 @@ Bar::Item& Bar::Add(bool enable, KeyInfo& (*key)(), const UPP::Image& image, Ca
Bar::Item& Bar::Add(const char *text, const UPP::Image& image, Callback callback)
{
return Add(true, text, image, callback);
return AddItem(callback).Text(text).Image(image);
}
Bar::Item& Bar::Add(const String& text, const UPP::Image& image, Callback callback)
@ -299,7 +299,10 @@ Bar::Item& Bar::Add(const String& text, const UPP::Image& image, Callback callba
Bar::Item& Bar::Add(KeyInfo& (*key)(), const UPP::Image& image, Callback callback)
{
return Add(true, key, image, callback);
const char *text = (*key)().name;
if(*text == '\3')
text = t_GetLngString(text + 1);
return Add(text, image, callback).Key(key);
}
Bar::Item& Bar::Add(bool enable, const char *text, Callback callback)

View file

@ -426,6 +426,7 @@ private:
public:
enum Kind { NOLABEL, RIGHTLABEL, BOTTOMLABEL };
void ResetKeepStyle();
void Reset();
static const Style& StyleDefault();
@ -434,10 +435,10 @@ public:
bool IsChecked() { return checked; }
UPP::Image GetImage() const;
ToolButton& SetStyle(const Style& s) { style = &s; Refresh(); return *this; }
ToolButton& SetStyle(const Style& s);
ToolButton& MinSize(Size sz) { minsize = sz; return *this; }
ToolButton& MaxIconSize(Size sz) { maxiconsize = sz; return *this; }
ToolButton& Kind(int _kind) { kind = _kind; Refresh(); return *this; }
ToolButton& Kind(int _kind);
ToolButton& Label(const char *text, int kind);
ToolButton& Label(const char *text);
ToolButton& NoDarkAdjust(bool b = true) { nodarkadjust = b; return *this; }

View file

@ -35,8 +35,8 @@ file
DropList.cpp,
DropChoice.cpp,
StaticCtrl.h,
Static.cpp,
Splitter.h,
Static.cpp,
Splitter.cpp,
FrameSplitter.cpp,
SliderCtrl.h,

View file

@ -331,6 +331,15 @@ SeparatorCtrl& SeparatorCtrl::SetSize(int w)
return *this;
}
SeparatorCtrl& SeparatorCtrl::SetStyle(const Style& s)
{
if(&s != style) {
style = &s;
Refresh();
}
return *this;
}
SeparatorCtrl::SeparatorCtrl()
{
NoWantFocus();

View file

@ -162,7 +162,7 @@ public:
SeparatorCtrl& Margin(int l, int r);
SeparatorCtrl& Margin(int w) { return Margin(w, w); }
SeparatorCtrl& SetSize(int w);
SeparatorCtrl& SetStyle(const Style& s) { style = &s; Refresh(); return *this; }
SeparatorCtrl& SetStyle(const Style& s);
SeparatorCtrl();
};

View file

@ -55,7 +55,7 @@ void ToolBar::Paint(Draw& w)
Bar::Item& ToolBar::AddItem(Callback cb)
{
ToolButton& m = item.DoIndex(ii++);
m.Reset();
m.ResetKeepStyle();
m.WhenAction = cb;
m.MinSize(IsNull(buttonminsize) ? style->buttonminsize : buttonminsize);
m.MaxIconSize(IsNull(maxiconsize) ? style->maxiconsize : maxiconsize);

View file

@ -52,7 +52,7 @@ ToolButton::ToolButton()
ToolButton::~ToolButton() {}
void ToolButton::Reset()
void ToolButton::ResetKeepStyle()
{
repeat = false;
accel = 0;
@ -60,13 +60,18 @@ void ToolButton::Reset()
NoWantFocus();
minsize = Size(0, 0);
maxiconsize = Size(INT_MAX, INT_MAX);
style = &StyleDefault();
Tip("");
Help("");
Topic("");
Description("");
}
void ToolButton::Reset()
{
ResetKeepStyle();
style = &StyleDefault();
}
void ToolButton::UpdateTip()
{
LTIMING("UpdateTip");
@ -83,9 +88,22 @@ void ToolButton::UpdateTip()
Bar::Item& ToolButton::Text(const char *txt)
{
ExtractAccessKey(txt, text);
UpdateTip();
Refresh();
String newtext;
ExtractAccessKey(txt, newtext);
if(newtext != text) {
text = newtext;
UpdateTip();
Refresh();
}
return *this;
}
ToolButton& ToolButton::SetStyle(const Style& s)
{
if(style != &s) {
style = &s;
Refresh();
}
return *this;
}
@ -134,6 +152,13 @@ ToolButton& ToolButton::Label(const char *text)
return *this;
}
ToolButton& ToolButton::Kind(int _kind)
{
if(kind != _kind)
Refresh();
return *this;
}
Image ToolButton::GetImage() const
{
UPP::Image m = img;

View file

@ -707,7 +707,7 @@ void AppMain___()
#endif
#ifdef _DEBUG
// Ctrl::ShowRepaint(50);
Ctrl::ShowRepaint(50);
#endif
#ifdef PLATFORM_WIN32