From aa524ec6b3e87ba1fadb6b293802fdd7b36646a4 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 5 Jun 2019 20:45:28 +0200 Subject: Use a flowbox when there are more than two options for font feature settings. Improves display of options. --- src/ui/widget/font-variants.cpp | 95 ++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/ui/widget/font-variants.cpp b/src/ui/widget/font-variants.cpp index b4f991863..b81f809b2 100644 --- a/src/ui/widget/font-variants.cpp +++ b/src/ui/widget/font-variants.cpp @@ -35,12 +35,31 @@ namespace Widget { { Gtk::Label* table_name = Gtk::manage (new Gtk::Label()); table_name->set_markup ("\"" + name + "\" "); + grid.attach (*table_name, 0, row, 1, 1); + Gtk::FlowBox* flow_box = nullptr; + Gtk::ScrolledWindow* scrolled_window = nullptr; + if (options > 2) { + // If there are more than 2 option, pack them into a flowbox instead of directly putting them in the grid. + // Some fonts might have a table with many options (Bungee Hairline table 'ornm' has 113 entries). + flow_box = Gtk::manage (new Gtk::FlowBox()); + flow_box->set_selection_mode(); // Turn off selection + flow_box->set_homogeneous(); + flow_box->set_max_children_per_line (100); // Override default value + flow_box->set_min_children_per_line (10); // Override default value + + // We pack this into a scrollbar... otherwise the minimum height is set to what is required to fit all + // flow box children into the flow box when the flow box has minimum width. (Crazy if you ask me!) + scrolled_window = Gtk::manage (new Gtk::ScrolledWindow()); + scrolled_window->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); + scrolled_window->add(*flow_box); + } + Gtk::RadioButton::Group group; for (int i = 0; i < options; ++i) { - int col = i%10; // Some fonts might have a table with many options (Bungee Hairline table 'ornm' has 113 entries). - if (i > 10 && col == 0) row++; + + // Create radio button and create or add to button group. Gtk::RadioButton* button = Gtk::manage (new Gtk::RadioButton()); if (i == 0) { group = button->get_group(); @@ -48,9 +67,9 @@ namespace Widget { button->set_group (group); } button->signal_clicked().connect ( sigc::mem_fun(*parent, &FontVariants::feature_callback) ); - grid.attach (*button, 2*col+1, row, 1, 1); buttons.push_back (button); + // Create label. Gtk::Label* label = Gtk::manage (new Gtk::Label()); // Restrict label width (some fonts have lots of alternatives). @@ -58,6 +77,7 @@ namespace Widget { label->set_line_wrap_mode( Pango::WRAP_WORD_CHAR ); label->set_ellipsize( Pango::ELLIPSIZE_END ); label->set_lines(3); + label->set_hexpand(); Glib::ustring markup; markup += "