Make knobs size requests dynamic
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Sat, 20 Aug 2016 16:12:49 +0000 (18:12 +0200)
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Sat, 20 Aug 2016 16:12:49 +0000 (18:12 +0200)
At the point of creation, the automate_button size request is wrong
since it has not the correct style yet. Instead of trying ugly hacks to
fix that, connect to the knob's size_request signal and get the button's
requisition only when needed. If the system font changes to one that has
different extents (even if the point size is the same), the UI will thus
correctly update.

gtk2_ardour/generic_pluginui.cc
gtk2_ardour/plugin_ui.h

index f7b30e2d18a5b8877007f99c7424df243302c170..14d05df344050442d0ec5ed5f9ba5cbce8a95fdb 100644 (file)
@@ -664,8 +664,6 @@ GenericPluginUI::build_control_ui (const Evoral::Parameter&             param,
        control_ui->label.set_name ("PluginParameterLabel");
        control_ui->set_spacing (5);
 
-       Gtk::Requisition req (control_ui->automate_button.size_request());
-
        if (is_input) {
 
                if (desc.datatype == Variant::PATH) {
@@ -764,7 +762,9 @@ GenericPluginUI::build_control_ui (const Evoral::Parameter&             param,
                                assert(but);
                                but->set_tweaks(ArdourButton::Square);
                        } else if (use_knob) {
-                               control_ui->controller->set_size_request (req.height * 1.5, req.height * 1.5);
+                               /* Delay size request so that styles are gotten right */
+                               control_ui->controller->widget()->signal_size_request().connect(
+                                               sigc::bind (sigc::mem_fun (*this, &GenericPluginUI::knob_size_request), control_ui));
                        } else {
                                control_ui->controller->set_size_request (200, -1);
                                control_ui->controller->set_name (X_("ProcessorControlSlider"));
@@ -937,6 +937,15 @@ GenericPluginUI::build_control_ui (const Evoral::Parameter&             param,
        return control_ui;
 }
 
+void
+GenericPluginUI::knob_size_request(Gtk::Requisition* req, ControlUI* cui) {
+       Gtk::Requisition astate_req (cui->automate_button.size_request());
+       const int size = (int) (astate_req.height * 1.5);
+       req->width = max(req->width, size);
+       req->height = max(req->height, size);
+}
+
+
 bool
 GenericPluginUI::astate_button_event (GdkEventButton* ev, ControlUI* cui)
 {
index 57aa138af78dda3d727bf01aedd137852ad50042..4fb052b5f5b271a1ee06a8a96aa86657b33cca82 100644 (file)
@@ -292,6 +292,8 @@ class GenericPluginUI : public PlugUIBase, public Gtk::VBox
        void set_automation_state (ARDOUR::AutoState state, ControlUI* cui);
        void set_all_automation (ARDOUR::AutoState state);
 
+       void knob_size_request(Gtk::Requisition* req, ControlUI* cui);
+
        /* XXX: remove */
        void print_parameter (char *buf, uint32_t len, uint32_t param);
        bool integer_printer (char* buf, Gtk::Adjustment &, ControlUI *);