From 2066f7018d96ccab01b7574b437736b9c7a817ac Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 9 Nov 2024 04:49:11 +0100 Subject: [PATCH] ArdourButton: add option to expand buttons to be square --- libs/widgets/ardour_button.cc | 15 ++++++++++++++- libs/widgets/widgets/ardour_button.h | 14 ++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/libs/widgets/ardour_button.cc b/libs/widgets/ardour_button.cc index f31ed74827..8d8023b213 100644 --- a/libs/widgets/ardour_button.cc +++ b/libs/widgets/ardour_button.cc @@ -763,7 +763,10 @@ ArdourButton::on_size_request (Gtk::Requisition* req) req->width = wh; req->height = wh; } - else if (_tweaks & Square) { + else if (_tweaks & (Square | ExpandtoSquare)) { + if (_squaresize.has_value ()) { + req->width = std::max (req->width, _squaresize.value ()); + } // currerntly unused (again) if (req->width < req->height) req->width = req->height; @@ -1074,6 +1077,15 @@ ArdourButton::on_size_allocate (Allocation& alloc) /* re-center text */ //_layout->get_pixel_size (_text_width, _text_height); } + if (_tweaks & ExpandtoSquare && alloc.get_width () != alloc.get_height ()) { + if (!_squaresize.has_value ()) { + _squaresize = std::max (alloc.get_width (), alloc.get_height ()); + queue_resize (); + } else { + /* allow widget to shink next time */ + _squaresize.reset (); + } + } } void @@ -1334,6 +1346,7 @@ ArdourButton::set_tweaks (Tweaks t) { if (_tweaks != t) { _tweaks = t; + _squaresize.reset (); if (get_realized()) { queue_resize (); } diff --git a/libs/widgets/widgets/ardour_button.h b/libs/widgets/widgets/ardour_button.h index 3681acaa9b..6ee0a65768 100644 --- a/libs/widgets/widgets/ardour_button.h +++ b/libs/widgets/widgets/ardour_button.h @@ -61,12 +61,13 @@ class LIBWIDGETS_API ArdourButton : public CairoWidget , public Gtkmm2ext::Activ virtual ~ArdourButton (); enum Tweaks { - Square = 0x1, - TrackHeader = 0x2, - OccasionalText = 0x4, - OccasionalLED = 0x8, - ForceBoxy = 0x10, - ForceFlat = 0x20, + Square = 0x01, + TrackHeader = 0x02, + OccasionalText = 0x04, + OccasionalLED = 0x08, + ForceBoxy = 0x10, + ForceFlat = 0x20, + ExpandtoSquare = 0x40, }; static Tweaks default_tweaks; @@ -202,6 +203,7 @@ class LIBWIDGETS_API ArdourButton : public CairoWidget , public Gtkmm2ext::Activ uint32_t outline_color; + std::optional _squaresize; cairo_pattern_t* convex_pattern; cairo_pattern_t* concave_pattern;