13
0

ArdourButton: add option to expand buttons to be square

This commit is contained in:
Robin Gareus 2024-11-09 04:49:11 +01:00
parent 0254e7e6b0
commit 2066f7018d
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 22 additions and 7 deletions

View File

@ -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 ();
}

View File

@ -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<int> _squaresize;
cairo_pattern_t* convex_pattern;
cairo_pattern_t* concave_pattern;