Update the button
This commit is contained in:
parent
fa548a6193
commit
1ea6918cd5
3 changed files with 29 additions and 14 deletions
|
|
@ -375,11 +375,11 @@ void Editor::Impl::createFrameContents()
|
||||||
typedef CTextButton Button;
|
typedef CTextButton Button;
|
||||||
#endif
|
#endif
|
||||||
typedef CTextButton ValueButton;
|
typedef CTextButton ValueButton;
|
||||||
typedef SHoverButton LoadFileButton;
|
typedef STextButton LoadFileButton;
|
||||||
typedef SHoverButton CCButton;
|
typedef STextButton CCButton;
|
||||||
typedef SHoverButton HomeButton;
|
typedef STextButton HomeButton;
|
||||||
typedef SHoverButton SettingsButton;
|
typedef STextButton SettingsButton;
|
||||||
typedef SHoverButton EditFileButton;
|
typedef STextButton EditFileButton;
|
||||||
typedef SPiano Piano;
|
typedef SPiano Piano;
|
||||||
|
|
||||||
auto createLogicalGroup = [](const CRect& bounds, int, const char*, CHoriTxtAlign, int) {
|
auto createLogicalGroup = [](const CRect& bounds, int, const char*, CHoriTxtAlign, int) {
|
||||||
|
|
@ -482,7 +482,7 @@ void Editor::Impl::createFrameContents()
|
||||||
return vm;
|
return vm;
|
||||||
};
|
};
|
||||||
auto createGlyphButton = [this, &theme](UTF8StringPtr glyph, const CRect& bounds, int tag, int fontsize) {
|
auto createGlyphButton = [this, &theme](UTF8StringPtr glyph, const CRect& bounds, int tag, int fontsize) {
|
||||||
SHoverButton* btn = new SHoverButton(bounds, this, tag, glyph);
|
STextButton* btn = new STextButton(bounds, this, tag, glyph);
|
||||||
btn->setFont(new CFontDesc("Fluent System Regular W20", fontsize));
|
btn->setFont(new CFontDesc("Fluent System Regular W20", fontsize));
|
||||||
btn->setTextColor(theme->icon);
|
btn->setTextColor(theme->icon);
|
||||||
btn->setHoverColor(theme->iconHighlight);
|
btn->setHoverColor(theme->iconHighlight);
|
||||||
|
|
|
||||||
|
|
@ -428,20 +428,33 @@ void SValueMenu::onItemClicked(int32_t index)
|
||||||
valueChanged();
|
valueChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHoverButton::setHoverColor (const CColor& color)
|
void STextButton::setHoverColor (const CColor& color)
|
||||||
{
|
{
|
||||||
hoverColor_ = color;
|
hoverColor_ = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMouseEventResult SHoverButton::onMouseEntered (CPoint& where, const CButtonState& buttons)
|
void STextButton::draw(CDrawContext* context)
|
||||||
{
|
{
|
||||||
backupColor_ = getTextColor();
|
backupColor_ = textColor;
|
||||||
setTextColor(hoverColor_);
|
if (hovered) {
|
||||||
|
textColor = hoverColor_; // textColor is protected
|
||||||
|
}
|
||||||
|
CTextButton::draw(context);
|
||||||
|
if (hovered)
|
||||||
|
textColor = backupColor_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CMouseEventResult STextButton::onMouseEntered (CPoint& where, const CButtonState& buttons)
|
||||||
|
{
|
||||||
|
hovered = true;
|
||||||
|
setDirty();
|
||||||
return CTextButton::onMouseEntered(where, buttons);
|
return CTextButton::onMouseEntered(where, buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMouseEventResult SHoverButton::onMouseExited (CPoint& where, const CButtonState& buttons)
|
CMouseEventResult STextButton::onMouseExited (CPoint& where, const CButtonState& buttons)
|
||||||
{
|
{
|
||||||
setTextColor(backupColor_);
|
hovered = false;
|
||||||
|
setDirty();
|
||||||
return CTextButton::onMouseExited(where, buttons);
|
return CTextButton::onMouseExited(where, buttons);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,15 +149,17 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
class SHoverButton: public CTextButton {
|
class STextButton: public CTextButton {
|
||||||
public:
|
public:
|
||||||
SHoverButton(const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, UTF8StringPtr title = nullptr)
|
STextButton(const CRect& size, IControlListener* listener = nullptr, int32_t tag = -1, UTF8StringPtr title = nullptr)
|
||||||
: CTextButton(size, listener, tag, title) {}
|
: CTextButton(size, listener, tag, title) {}
|
||||||
|
|
||||||
void setHoverColor(const CColor& color);
|
void setHoverColor(const CColor& color);
|
||||||
CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override;
|
CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override;
|
||||||
CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override;
|
CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override;
|
||||||
|
void draw(CDrawContext* context) override;
|
||||||
private:
|
private:
|
||||||
CColor hoverColor_;
|
CColor hoverColor_;
|
||||||
CColor backupColor_;
|
CColor backupColor_;
|
||||||
|
bool hovered { false };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue