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;
|
||||
#endif
|
||||
typedef CTextButton ValueButton;
|
||||
typedef SHoverButton LoadFileButton;
|
||||
typedef SHoverButton CCButton;
|
||||
typedef SHoverButton HomeButton;
|
||||
typedef SHoverButton SettingsButton;
|
||||
typedef SHoverButton EditFileButton;
|
||||
typedef STextButton LoadFileButton;
|
||||
typedef STextButton CCButton;
|
||||
typedef STextButton HomeButton;
|
||||
typedef STextButton SettingsButton;
|
||||
typedef STextButton EditFileButton;
|
||||
typedef SPiano Piano;
|
||||
|
||||
auto createLogicalGroup = [](const CRect& bounds, int, const char*, CHoriTxtAlign, int) {
|
||||
|
|
@ -482,7 +482,7 @@ void Editor::Impl::createFrameContents()
|
|||
return vm;
|
||||
};
|
||||
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->setTextColor(theme->icon);
|
||||
btn->setHoverColor(theme->iconHighlight);
|
||||
|
|
|
|||
|
|
@ -428,20 +428,33 @@ void SValueMenu::onItemClicked(int32_t index)
|
|||
valueChanged();
|
||||
}
|
||||
|
||||
void SHoverButton::setHoverColor (const CColor& color)
|
||||
void STextButton::setHoverColor (const CColor& color)
|
||||
{
|
||||
hoverColor_ = color;
|
||||
}
|
||||
|
||||
CMouseEventResult SHoverButton::onMouseEntered (CPoint& where, const CButtonState& buttons)
|
||||
void STextButton::draw(CDrawContext* context)
|
||||
{
|
||||
backupColor_ = getTextColor();
|
||||
setTextColor(hoverColor_);
|
||||
backupColor_ = textColor;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,15 +149,17 @@ private:
|
|||
};
|
||||
|
||||
///
|
||||
class SHoverButton: public CTextButton {
|
||||
class STextButton: public CTextButton {
|
||||
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) {}
|
||||
|
||||
void setHoverColor(const CColor& color);
|
||||
CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) override;
|
||||
CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override;
|
||||
void draw(CDrawContext* context) override;
|
||||
private:
|
||||
CColor hoverColor_;
|
||||
CColor backupColor_;
|
||||
bool hovered { false };
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue