From aa1b79936f6f7a147e89377c37b5e8b542d4768c Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Thu, 30 Dec 2021 11:11:48 +0100 Subject: [PATCH] Add hover hints on main buttons --- plugins/editor/layout/main.fl | 12 ++-- plugins/editor/src/editor/Editor.cpp | 70 ++++++++++++++++++++--- plugins/editor/src/editor/layout/main.hpp | 4 ++ 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/plugins/editor/layout/main.fl b/plugins/editor/layout/main.fl index 78bf50ce..67c8bd25 100644 --- a/plugins/editor/layout/main.fl +++ b/plugins/editor/layout/main.fl @@ -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 + } } diff --git a/plugins/editor/src/editor/Editor.cpp b/plugins/editor/src/editor/Editor.cpp index fc5e0357..2ac5a35b 100644 --- a/plugins/editor/src/editor/Editor.cpp +++ b/plugins/editor/src/editor/Editor.cpp @@ -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_; @@ -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("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("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_; diff --git a/plugins/editor/src/editor/layout/main.hpp b/plugins/editor/src/editor/layout/main.hpp index 54660166..03e5e579 100644 --- a/plugins/editor/src/editor/layout/main.hpp +++ b/plugins/editor/src/editor/layout/main.hpp @@ -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);