From 7033b34a656978601fcc23a434c403e91ec73508 Mon Sep 17 00:00:00 2001 From: "Julien \"_FrnchFrgg_\" RIVAUD" Date: Wed, 30 Aug 2017 20:03:24 +0200 Subject: Ensure a plugin generic UI doesn't exceed screen width Do that by wrapping the packed controls box in a ScrolledWindow and making it request the same width than the box but capped to 90% of the screen width. Also, when the box width exceeds the maximum value, try again with one-letter automation buttons in case the reduced width avoids showing a scroll bar. --- gtk2_ardour/generic_pluginui.cc | 70 ++++++++++++++++++++++++++++------------- gtk2_ardour/plugin_ui.h | 2 ++ 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/gtk2_ardour/generic_pluginui.cc b/gtk2_ardour/generic_pluginui.cc index bc169afe4f..9e0f605cd9 100644 --- a/gtk2_ardour/generic_pluginui.cc +++ b/gtk2_ardour/generic_pluginui.cc @@ -138,23 +138,29 @@ GenericPluginUI::GenericPluginUI (boost::shared_ptr pi, bool scrol main_contents.pack_start (*constraint_hbox, false, false); - if (is_scrollable) { - Gtk::ScrolledWindow *scroller = manage (new Gtk::ScrolledWindow()); - scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); - scroller->set_name ("PluginEditor"); - scroller->add (hpacker); - main_contents.pack_start (*scroller, true, true); - } else { - main_contents.pack_start (hpacker, false, false); - } - pi->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&GenericPluginUI::processor_active_changed, this, boost::weak_ptr(pi)), gui_context()); bypass_button.set_active (!pi->enabled()); + /* ScrolledWindow will wrap hpacker in a Viewport */ + scroller.add (hpacker); + Viewport* view = static_cast(scroller.get_child()); + view->set_shadow_type(Gtk::SHADOW_NONE); + + main_contents.pack_start (scroller, true, true); + prefheight = 0; build (); + if (is_scrollable) { + scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); + scroller.set_name ("PluginEditor"); + } else { + scroller.signal_size_request().connect (sigc::mem_fun(*this, &GenericPluginUI::scroller_size_request)); + scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER); + } + + /* Listen for property changes that are not notified normally because * AutomationControl has only support for numeric values currently. * The only case is Variant::PATH for now */ @@ -172,6 +178,39 @@ GenericPluginUI::~GenericPluginUI () } } +void +GenericPluginUI::scroller_size_request (Gtk::Requisition* a) +{ + Glib::RefPtr screen = get_screen(); + if (!screen) + screen = Gdk::Screen::get_default(); + + int maximum_width; + { + Gdk::Rectangle monitor; + const int monitor_num = screen->get_monitor_at_window (get_window ()); + screen->get_monitor_geometry ( + (monitor_num < 0) ? 0 : monitor_num, + monitor); + + maximum_width = monitor.get_width() * 0.9; + } + + GtkRequisition request = hpacker.size_request(); + + if (request.width > maximum_width) { + for (vector::const_iterator cuip = input_controls.cbegin(); + cuip != input_controls.cend(); + ++cuip) { + if (!(*cuip)->short_autostate) + set_short_autostate(*cuip, true); + } + request = hpacker.size_request(); + } + + a->width = min(request.width, maximum_width); +} + // Some functions for calculating the 'similarity' of two plugin // control labels. @@ -220,7 +259,6 @@ std::size_t s1pos, s2pos, n = 0; static const guint32 min_controls_per_column = 17, max_controls_per_column = 24; static const float default_similarity_threshold = 0.3; -static const guint32 max_columns_for_big_autostate = 2; void GenericPluginUI::build () @@ -475,7 +513,6 @@ GenericPluginUI::automatic_layout (const std::vector& control_uis) // starting a new column when necessary. i = 0; - size_t columns = 1; for (vector::iterator cuip = cui_controls_list.begin(); cuip != cui_controls_list.end(); ++cuip, ++i) { ControlUI* cui = *cuip; @@ -495,7 +532,6 @@ GenericPluginUI::automatic_layout (const std::vector& control_uis) frame->add (*box); hpacker.pack_start(*frame, true, true); x = 0; - ++columns; } else { HSeparator *split = new HSeparator(); split->set_size_request(-1, 5); @@ -506,14 +542,6 @@ GenericPluginUI::automatic_layout (const std::vector& control_uis) box->pack_start (*cui, false, false); } - if (columns > max_columns_for_big_autostate) { - for (vector::const_iterator cuip = control_uis.cbegin(); - cuip != control_uis.cend(); - ++cuip) { - set_short_autostate(*cuip, true); - } - } - if (is_scrollable) { prefheight = 30 * i; } diff --git a/gtk2_ardour/plugin_ui.h b/gtk2_ardour/plugin_ui.h index 3b374298ac..ed1c722605 100644 --- a/gtk2_ardour/plugin_ui.h +++ b/gtk2_ardour/plugin_ui.h @@ -301,6 +301,8 @@ private: Gtk::FileChooserButton* widget); void path_property_changed (uint32_t key, const ARDOUR::Variant& value); + void scroller_size_request (Gtk::Requisition*); + Gtk::ScrolledWindow scroller; }; class PluginUIWindow : public ArdourWindow -- cgit v1.2.3