Merge pull request #1057 from paulfd/button-hints

Button hints and closing the about dialog with Esc
This commit is contained in:
Paul Ferrand 2021-12-30 12:35:23 +01:00 committed by GitHub
commit 3d50afc794
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 16 deletions

View file

@ -3,7 +3,7 @@ version 1.0304
header_name {.h}
code_name {.cxx}
widget_class mainView {open
xywh {607 439 800 475} type Double
xywh {624 612 800 475} type Double
class LogicalGroup visible
} {
Fl_Box imageContainer_ {
@ -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,9 @@ widget_class mainView {open
xywh {5 110 790 285} hide
class LogicalGroup
} {}
Fl_Box lblHover_ {
comment {palette=invertedPalette} selected
xywh {5 105 170 25} labelsize 12 hide
class HoverBox
}
}

View file

@ -223,6 +223,24 @@ CMouseEventResult SAboutDialog::onMouseDown(CPoint& where, const CButtonState& b
return result;
}
int32_t SAboutDialog::onKeyDown (const VstKeyCode& keyCode, CFrame* frame)
{
if (keyCode.virt == VKEY_ESCAPE) {
setVisible(false);
frame->unregisterKeyboardHook(this);
return 1;
}
return -1;
}
int32_t SAboutDialog::onKeyUp (const VstKeyCode& keyCode, CFrame* frame)
{
(void)keyCode;
(void)frame;
return -1;
}
void SAboutDialog::valueChanged(CControl *ctl)
{
int32_t tag = ctl->getTag();

View file

@ -13,7 +13,7 @@
using namespace VSTGUI;
class SAboutDialog : public CViewContainer, public IControlListener {
class SAboutDialog : public CViewContainer, public IControlListener, public IKeyboardHook{
enum {
kTagButtonSfztools,
@ -28,6 +28,8 @@ public:
void setPluginFormat(const std::string& pluginFormat);
void setPluginHost(const std::string& pluginHost);
int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) override;
int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) override;
protected:
CMouseEventResult onMouseDown(CPoint& where, const CButtonState& buttons) override;

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,19 @@ 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->valueBackground);
lbl->setFrameColor(palette->valueText);
});
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 +900,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 +1741,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_;
@ -2076,7 +2127,10 @@ void Editor::Impl::valueChanged(CControl* ctl)
if (value != 1)
break;
Call::later([this]() { aboutDialog_->setVisible(true); });
Call::later([this]() {
aboutDialog_->setVisible(true);
frame_->registerKeyboardHook(aboutDialog_);
});
break;
case kTagThemeMenu:

View file

@ -238,3 +238,9 @@ 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);
enterPalette(invertedPalette);
auto* const view__92 = createHoverBox(CRect(5, 105, 175, 130), -1, "", kCenterText, 12);
lblHover_ = view__92;
view__0->addView(view__92);
view__92->setVisible(false);
enterPalette(defaultPalette);