MetaButton: handle boxy theme, separate active state from menu index

This commit is contained in:
Robin Gareus 2025-01-28 22:14:30 +01:00
parent 7bb4ae2cb8
commit 0516c12694
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04

View file

@ -78,11 +78,9 @@ MetaButton::on_button_press_event (GdkEventButton* ev)
if (ev->type == GDK_BUTTON_PRESS && ev->button == 3) { if (ev->type == GDK_BUTTON_PRESS && ev->button == 3) {
Gtkmm2ext::anchored_menu_popup (&_menu, this, current_active ? current_active->menutext () : "", ev->button, ev->time); Gtkmm2ext::anchored_menu_popup (&_menu, this, current_active ? current_active->menutext () : "", ev->button, ev->time);
} } else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1 && ev->x > (get_width () - _diameter - 7)) {
else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1 && ev->x > (get_width () - _diameter - 7)) {
Gtkmm2ext::anchored_menu_popup (&_menu, this, current_active ? current_active->menutext () : "", ev->button, ev->time); Gtkmm2ext::anchored_menu_popup (&_menu, this, current_active ? current_active->menutext () : "", ev->button, ev->time);
} } else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) {
else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) {
if (current_active) { if (current_active) {
current_active->activate (); current_active->activate ();
} }
@ -107,6 +105,14 @@ MetaButton::activate_item (MetaMenuItem const* e)
{ {
update_button (e); update_button (e);
e->activate (); e->activate ();
_active = 0;
for (auto& i : _menu.items ()) {
if (e == dynamic_cast<MetaMenuItem*> (&i)) {
break;
}
++_active;
}
} }
void void
@ -118,26 +124,16 @@ MetaButton::update_button (MetaMenuItem const* e)
void void
MetaButton::set_active (std::string const& menulabel) MetaButton::set_active (std::string const& menulabel)
{ {
guint c = 0; MetaMenuItem const* current_active = dynamic_cast<MetaMenuItem*> (_menu.get_active ());
bool found = false; if (!current_active) {
set_active_state (Gtkmm2ext::Off);
for (auto& i : _menu.items ()) { return;
if (i.get_label () == menulabel) {
if (_menu.get_active () != &i) {
_menu.set_active (c);
} }
update_button (dynamic_cast<MetaMenuItem*> (&i)); if (current_active->menutext () == menulabel) {
set_active_state (Gtkmm2ext::ExplicitActive); set_active_state (Gtkmm2ext::ExplicitActive);
_active = c; } else {
found = true;
break;
}
++c;
}
if (!found) {
set_active_state (Gtkmm2ext::Off); set_active_state (Gtkmm2ext::Off);
} }
StateChanged (); /* EMIT SIGNAL */
} }
void void
@ -147,6 +143,7 @@ MetaButton::set_index (guint index)
for (auto& i : _menu.items ()) { for (auto& i : _menu.items ()) {
if (c == index) { if (c == index) {
_menu.set_active (c); _menu.set_active (c);
_active = c;
update_button (dynamic_cast<MetaMenuItem*> (&i)); update_button (dynamic_cast<MetaMenuItem*> (&i));
break; break;
} }
@ -162,11 +159,13 @@ MetaButton::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*
ArdourButton::render (ctx, rect); ArdourButton::render (ctx, rect);
} }
if (_hovering && UIConfigurationBase::instance ().get_widget_prelight ()) { if (_hovering && UIConfigurationBase::instance ().get_widget_prelight ()) {
const bool boxy = (_tweaks & ForceBoxy) | boxy_buttons ();
const float corner_radius = boxy ? 0 : std::max (2.f, _corner_radius * UIConfigurationBase::instance ().get_ui_scale ());
cairo_t* cr = ctx->cobj (); cairo_t* cr = ctx->cobj ();
if (_hover_dropdown) { if (_hover_dropdown) {
Gtkmm2ext::rounded_right_half_rectangle (cr, get_width () - _diameter - 6, 1, _diameter + 5, get_height() - 2, _corner_radius); Gtkmm2ext::rounded_right_half_rectangle (cr, get_width () - _diameter - 6, 1, _diameter + 5, get_height () - 2, corner_radius);
} else { } else {
Gtkmm2ext::rounded_left_half_rectangle (cr, 1, 1, get_width() -_diameter - 7 , get_height() - 2, _corner_radius); Gtkmm2ext::rounded_left_half_rectangle (cr, 1, 1, get_width () - _diameter - 7, get_height () - 2, corner_radius);
} }
cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2); cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2);
cairo_fill (cr); cairo_fill (cr);