Add hover hints on main buttons

This commit is contained in:
Paul Fd 2021-12-30 11:11:48 +01:00
parent 5f982cf64f
commit aa1b79936f
3 changed files with 73 additions and 13 deletions

View file

@ -161,7 +161,7 @@ widget_class mainView {open
}
}
}
Fl_Group {subPanels_[kPanelInfo]} {open
Fl_Group {subPanels_[kPanelInfo]} {
xywh {5 110 790 285} hide
class LogicalGroup
} {
@ -221,7 +221,7 @@ widget_class mainView {open
}
}
}
Fl_Group {subPanels_[kPanelControls]} {open
Fl_Group {subPanels_[kPanelControls]} {
xywh {5 110 790 285} hide
class LogicalGroup
} {
@ -235,7 +235,7 @@ widget_class mainView {open
} {}
}
}
Fl_Group {subPanels_[kPanelSettings]} {open
Fl_Group {subPanels_[kPanelSettings]} {
xywh {0 110 825 360}
class LogicalGroup
} {
@ -366,7 +366,7 @@ widget_class mainView {open
class Label
}
Fl_Check_Button sustainCancelsReleaseCheckbox_ {
comment {tag=kTagSetSustainCancelsRelease} selected
comment {tag=kTagSetSustainCancelsRelease}
xywh {200 220 25 25} down_box DOWN_BOX
class Checkbox
}
@ -456,4 +456,8 @@ widget_class mainView {open
xywh {5 110 790 285} hide
class LogicalGroup
} {}
Fl_Box lblHover_ {selected
xywh {15 105 155 25} labelsize 12 hide
class HoverBox
}
}

View file

@ -139,6 +139,7 @@ struct Editor::Impl : EditorController::Receiver,
CTextLabel* keyswitchLabel_ = nullptr;
CTextLabel* keyswitchInactiveLabel_ = nullptr;
CTextLabel* keyswitchBadge_ = nullptr;
CTextLabel* lblHover_ = nullptr;
COptionMenu* themeMenu_ = nullptr;
std::unique_ptr<Theme> theme_;
@ -232,6 +233,8 @@ struct Editor::Impl : EditorController::Receiver,
void updatePreloadSizeLabel(int preloadSize);
void updateScalaRootKeyLabel(int rootKey);
void updateStretchedTuningLabel(float stretchedTuning);
void buttonHoverEnter(CControl* btn, const char* text);
void buttonHoverLeave(CControl* btn);
absl::string_view getCurrentKeyswitchName() const;
void updateKeyswitchNameLabel();
@ -871,6 +874,20 @@ void Editor::Impl::createFrameContents()
cb->setRoundRectRadius(5.0);
return cb;
};
auto createHoverBox = [this, &palette](const CRect& bounds, int, const char* label, CHoriTxtAlign align, int fontsize) {
CTextLabel* lbl = new CTextLabel(bounds, label);
auto font = makeOwned<CFontDesc>("Roboto", fontsize);
OnThemeChanged.push_back([lbl, palette]() {
lbl->setFontColor(palette->valueText);
lbl->setBackColor(palette->boxBackground);
lbl->setFrameColor(palette->valueText);
});
lbl->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
lbl->setHoriAlign(align);
lbl->setFont(font);
lbl->setAutosizeFlags(kAutosizeAll);
return lbl;
};
auto createGlyphButton = [this, &palette](UTF8StringPtr glyph, const CRect& bounds, int tag, int fontsize) {
STextButton* btn = new STextButton(bounds, this, tag, glyph);
btn->setFont(makeOwned<CFontDesc>("Sfizz Fluent System F20", fontsize));
@ -884,18 +901,29 @@ void Editor::Impl::createFrameContents()
btn->setGradientHighlighted(nullptr);
return btn;
};
auto createHomeButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
return createGlyphButton(u8"\ue1d6", bounds, tag, fontsize);
auto createHomeButton = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
auto* btn = createGlyphButton(u8"\ue1d6", bounds, tag, fontsize);
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Home"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createInfoButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
return createGlyphButton(u8"\ue1e7", bounds, tag, fontsize);
auto createInfoButton = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
auto* btn = createGlyphButton(u8"\ue1e7", bounds, tag, fontsize);
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Information"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createCCButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
// return createGlyphButton(u8"\ue240", bounds, tag, fontsize);
return createGlyphButton(u8"\ue253", bounds, tag, fontsize);
auto createCCButton = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
auto* btn = createGlyphButton(u8"\ue253", bounds, tag, fontsize);
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Controls"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createSettingsButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
return createGlyphButton(u8"\ue2e4", bounds, tag, fontsize);
auto createSettingsButton = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
auto* btn = createGlyphButton(u8"\ue2e4", bounds, tag, fontsize);
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Settings"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
#if 0
auto createEditFileButton = [&createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
@ -1714,6 +1742,30 @@ void Editor::Impl::updateStretchedTuningLabel(float stretchedTuning)
label->setText(text);
}
void Editor::Impl::buttonHoverEnter(CControl* btn, const char* text)
{
lblHover_->setText(text);
lblHover_->sizeToFit();
CRect rect = lblHover_->getViewSize();
CRect btnRect = btn->getViewSize();
auto height = rect.getHeight();
auto width = rect.getWidth();
rect.left = btnRect.left;
rect.top = btnRect.bottom + 2;
rect.setWidth(width + 10);
rect.setHeight(height);
lblHover_->setViewSize(rect);
lblHover_->setVisible(true);
lblHover_->invalid();
}
void Editor::Impl::buttonHoverLeave(CControl* btn)
{
(void)btn;
lblHover_->setVisible(false);
lblHover_->invalid();
}
absl::string_view Editor::Impl::getCurrentKeyswitchName() const
{
int sw = currentKeyswitch_;

View file

@ -238,3 +238,7 @@ auto* const view__91 = createLogicalGroup(CRect(5, 110, 795, 395), -1, "", kCent
subPanels_[kPanelGeneral] = view__91;
view__0->addView(view__91);
view__91->setVisible(false);
auto* const view__92 = createHoverBox(CRect(15, 105, 170, 130), -1, "", kCenterText, 12);
lblHover_ = view__92;
view__0->addView(view__92);
view__92->setVisible(false);