From 5db59b9fd6d172b5a60217939a0ee1c54769c976 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 2 Jun 2022 22:01:56 +0200 Subject: [PATCH] Update scroll-window policy of Lua dialog windows Better version of 817fccb3e5bcd, the visibility should not depend on the number of items in the dialog, but its requested height vs screen height. The main use-case is to not show the scroll-bar if the dialog has only a few rows. Then again if the scrollbar is visible, the dialog should not shrink below a reasonable min. height. --- gtk2_ardour/luadialog.cc | 16 ++++++++++------ gtk2_ardour/luadialog.h | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gtk2_ardour/luadialog.cc b/gtk2_ardour/luadialog.cc index 9058f57b1b..a35d84849e 100644 --- a/gtk2_ardour/luadialog.cc +++ b/gtk2_ardour/luadialog.cc @@ -30,9 +30,10 @@ #include "widgets/slider_controller.h" #include "stripable_colorpicker.h" -#include "ardour_dialog.h" #include "luadialog.h" +#include "public_editor.h" #include "splash.h" +#include "ui_config.h" #include "utils.h" using namespace LuaDialog; @@ -763,7 +764,7 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr) Gtk::Table* table = Gtk::manage (new Gtk::Table ()); table->set_col_spacings (20); table->set_row_spacings (8); - table->signal_size_allocate ().connect (sigc::mem_fun (this, &Dialog::table_size_alloc)); + table->signal_size_request ().connect (sigc::mem_fun (this, &Dialog::table_size_request)); _scroller.set_shadow_type(Gtk::SHADOW_NONE); _scroller.set_border_width(0); @@ -833,12 +834,15 @@ Dialog::run (lua_State *L) } void -Dialog::table_size_alloc (Gtk::Allocation& allocation) +Dialog::table_size_request (Gtk::Requisition* req) { - /* XXX: consider using 0.75 * screen-height instead of 512 */ - if (allocation.get_height () > 512) { + int h = Gtkmm2ext::physical_screen_height (PublicEditor::instance ().current_toplevel()->get_window()); + + int max_height = std::max (400., std::min (768.0 * UIConfiguration::instance().get_ui_scale(), h * .7)); + + if (req->height > max_height) { _scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); - _ad.set_size_request (-1, 512); + _ad.set_size_request (-1, max_height); } } diff --git a/gtk2_ardour/luadialog.h b/gtk2_ardour/luadialog.h index 2ff616f348..2f4d0884c3 100644 --- a/gtk2_ardour/luadialog.h +++ b/gtk2_ardour/luadialog.h @@ -20,11 +20,13 @@ #define _gtk2ardour_luadialog_h_ #include +#include #include #include #include "LuaBridge/LuaBridge.h" +#include "ardour_dialog.h" #include "ardour_message.h" namespace LuaDialog { @@ -91,7 +93,7 @@ public: private: Dialog (Dialog const&); // prevent copy construction - void table_size_alloc (Gtk::Allocation&); + void table_size_request (Gtk::Requisition*); ArdourDialog _ad; Gtk::ScrolledWindow _scroller;