From e6758b6ba81e440e95fae2c0f0a055708f989123 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 5 Nov 2024 14:56:37 -0700 Subject: [PATCH] Canvas; make button handle dynamic size allocation --- libs/canvas/button.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/canvas/button.cc b/libs/canvas/button.cc index b9a4b212b9..cb04c4294c 100644 --- a/libs/canvas/button.cc +++ b/libs/canvas/button.cc @@ -101,6 +101,8 @@ Button::init () Rect r = _label->bounding_box (); _label->set_position (Duple ((width - r.width())/2.0, (height - r.height())/2.0)); + + set_size_request (width, height); } void @@ -129,9 +131,16 @@ void Button::set_label (std::string const & str) { _label->set (str); - /* move to recenter */ + Rect r = _label->bounding_box (); + + /* alter our own size request to fit text + padding */ + set_size_request (r.width(), r.height()); + + /* move to recenter */ + _label->set_position (Duple ((width - r.width())/2.0, (height - r.height())/2.0)); + redraw (); }