From 0516c12694747168b18e3fa2b740e7cfd79f175c Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 28 Jan 2025 22:14:30 +0100 Subject: [PATCH] MetaButton: handle boxy theme, separate active state from menu index --- libs/widgets/metabutton.cc | 49 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/libs/widgets/metabutton.cc b/libs/widgets/metabutton.cc index 503565443d..9809b98f1d 100644 --- a/libs/widgets/metabutton.cc +++ b/libs/widgets/metabutton.cc @@ -78,11 +78,9 @@ MetaButton::on_button_press_event (GdkEventButton* ev) if (ev->type == GDK_BUTTON_PRESS && ev->button == 3) { 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); - } - else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) { + } else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) { if (current_active) { current_active->activate (); } @@ -107,6 +105,14 @@ MetaButton::activate_item (MetaMenuItem const* e) { update_button (e); e->activate (); + + _active = 0; + for (auto& i : _menu.items ()) { + if (e == dynamic_cast (&i)) { + break; + } + ++_active; + } } void @@ -118,26 +124,16 @@ MetaButton::update_button (MetaMenuItem const* e) void MetaButton::set_active (std::string const& menulabel) { - guint c = 0; - bool found = false; - - for (auto& i : _menu.items ()) { - if (i.get_label () == menulabel) { - if (_menu.get_active () != &i) { - _menu.set_active (c); - } - update_button (dynamic_cast (&i)); - set_active_state (Gtkmm2ext::ExplicitActive); - _active = c; - found = true; - break; - } - ++c; + MetaMenuItem const* current_active = dynamic_cast (_menu.get_active ()); + if (!current_active) { + set_active_state (Gtkmm2ext::Off); + return; } - if (!found) { + if (current_active->menutext () == menulabel) { + set_active_state (Gtkmm2ext::ExplicitActive); + } else { set_active_state (Gtkmm2ext::Off); } - StateChanged (); /* EMIT SIGNAL */ } void @@ -147,6 +143,7 @@ MetaButton::set_index (guint index) for (auto& i : _menu.items ()) { if (c == index) { _menu.set_active (c); + _active = c; update_button (dynamic_cast (&i)); break; } @@ -161,12 +158,14 @@ MetaButton::render (Cairo::RefPtr const& ctx, cairo_rectangle_t* PBD::Unwinder uw (_hovering, false); ArdourButton::render (ctx, rect); } - if (_hovering && UIConfigurationBase::instance().get_widget_prelight()) { - cairo_t* cr = ctx->cobj(); + 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 (); 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 { - 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_fill (cr);