Difference between revisions of "GTK+ 4 issues"

From Inkscape Wiki
Jump to navigation Jump to search
(Created page with " == Specific Issues == === Toolbars === Gtk::Toolbar and related widgets have been removed as "outdated". The suggested replacement is a Gtk::Box with normal widgets. This...")
 
 
(7 intermediate revisions by the same user not shown)
Line 24: Line 24:
# Snapping (750 - Vertical)
# Snapping (750 - Vertical)


We need to decide on the minimum size window we should target. The current minimum window size is about 811x524 pixels with main toolbar on top. Most modern budget displays are 1366x768. Older displays might be 1024x768.
We need to decide on the minimum size window we should target. The current minimum window size is about 811x524 pixels with main toolbar on top. Most modern budget displays are 1366x768 and are used by about 20% of desktops. A smaller fraction of about 5% use 1280x720. See [https://gs.statcounter.com/screen-resolution-stats/desktop/worldwide Screen Resolution Stats] . Gnome recommends a minimum display size of [https://developer.gnome.org/hig/guidelines/adaptive.html 1024x600].
 
==== SpinButtonToolItem ====
This tool item is a heavily customized widget derived from Gtk::ToolItem. It is used multiple times in most toolbars.
 
===== Structure =====
(Ink == Inkscape::UI::Widget)
 
<pre>
Ink::SpinButtonToolItem: public GtkToolItem
  └ Gtk::Box
    ├ Gtk::Image (optional icon)
    ├ Gtk::Label
    └ Ink::SpinButton: pubic Gtk::SpinButton
</pre>
 
===== Functionality =====
 
* on_btn_focus_in_event: Saves current value to be restored if focus is lost, set transfer_focus flag which controls if focus is returned to "focus widget" (i.e. canvas).
* on_btn_focus_out_event: Unset transfer_focus flag.
* on_btn_key_press_event (must be replaced by controller).
** ESC: reset old value, set focus to "focus widget".
** Return: set focus to "focus widget".
** Tab: move to next SpinButton in toolbar (probably not needed as moving to next widget is default behavior, and this breaks accessibilty).
** Left-Tab: move to previous SpinButton in toolbar.
** Key-up: Increase value by one (should be increment value, this is default behavior of Gtk::SpinButton).
** Key-down: Decrease value by one.
** Page-up: Increase value by ten (should be page increment value).
** Page-down: Decrease value by ten.
* on_numeric_menu_item_toggled: set new value.
* on_btn_button_press_event: Pop-up context menu.
* on_grab_focus: Set focus on Ink:SpinButton
* misc functions that are not actually used: show_limits, ... , sort_decreasing.
 
===== Ink::SpinButton Functionality =====
Some of this functionality duplicates that in SpinButtonTooltem.
 
* on_input: Handles math in entry and units.
* on_focus_in_event: Saves current value
* on_key_press_event (SpinButtonToolItem appears to handle these)
** ESC: reset old value, defocus (set focus to canvas if stay flag false).
** Return: defocus
** Tab: Sets "stay" flag (do not leave toolbar).
** Ctrl-Z: reset old value.


=== Menus ===
=== Menus ===
GTK4 uses menus based on Gio::Menu using Gio::Actions. These are easy to construct with .ui files. They automatically keep in sync with action states and with shortcuts. We have moved to them for the main menu bar in GTK3.
Gio::Menus do have some issues. The first, and perhaps the most important, is with icons. Icons can be specified in the .ui files. In GTK3 they are always shown while in GTK4 they are never shown (by default).
Icons visibility must be enabled for GTK4 using a callback when a menu is opened (similar to how we shift icons with GTK3). To allow a user to choose between:
# Showing all icons.
# Showing only icons tagged with 'use-icon' attribute in the .ui file.
# Never showing icons.
we must resort to rebuilding the Gio::Menu constructed from the .ui file. This is due to a series of unfortunate events including Gio::MenuItem's being immutable and the limited passing of attributes from Gio::Menu's to Gtk::Menu's (GTK3) or Gtk::PopoverMenu's (GTK4). The rebuilding is complicated but doable. See the "Toy program" linked to below. The menu,, once set, is not changeable so Inkscape must be restarted when a user changes their icon preference. Note that GTK discourages the use of "Verb" icons. See: https://discourse.gnome.org/t/toggling-on-off-icon-visibility-in-gmenu-items/7234/2 .
A second problem is that shifting icons into the space reserved for check and toggle button icons in GTK4 doesn't work properly. The "allocation" of widget space seems to have some kind of feedback loop based on the previous icons shift.
A third problem is changing menu labels on the fly as was done for the Undo and Redo entries.


== Useful Links ==
== Useful Links ==
# [https://docs.gtk.org/gtk4/migrating-3to4.html Migrating from Gtk3 to Gtk4]
# [https://docs.gtk.org/gtk4/migrating-3to4.html Migrating from Gtk3 to Gtk4]
# [https://developer-old.gnome.org/gtkmm-tutorial/stable/changes-gtkmm4.html.en Changes in gtkmm-4.0 and glibmm-2.68]
# [https://developer-old.gnome.org/gtkmm-tutorial/stable/changes-gtkmm4.html.en Changes in gtkmm-4.0 and glibmm-2.68]
#[https://gitlab.com/Tavmjong/gtk_sandbox/-/tree/master/gtkmm_ui Toy program for testing UI, supports both GTK3 and GTK4]

Latest revision as of 13:35, 19 December 2021


Specific Issues

Toolbars

Gtk::Toolbar and related widgets have been removed as "outdated". The suggested replacement is a Gtk::Box with normal widgets. This means that toolbars will have a minimum width defined by the sum of the widths of their child widgets rather being allowed to shrink to a smaller width with "over-flowing" widgets being replaced by a drop-down menu at the end of the toolbar. This requires us to re-think our toolbars.

In practice, many of the replacement menu items for dropped widgets are not very practical. Having toolbars that are quite wide probably is a sign of poor design. Many of the current toolbar widgets could be packed in non-modal popovers, that is, pop-up menus that stay open until dismissed. It would be relatively easy to then reduce most toolbar widths to less than 1000 pixels. The most difficult toolbar to reduce in size is the main toolbar. This could be dealt with by removing all the dialog buttons. One might think of putting all dialogs into a new menu bar sub-menu or into a modal popover.

Example of replacing some toolbar widgets with a popover.

The longest toolbars (width):

  1. Text (1650)
  2. Calligraphy (1450)
  3. Main Toolbar (1350 - Horizontal, 950 - Vertical)
  4. Selector (1300)
  5. Spray Paint (1300)
  6. Node (1250)
  7. Ruler (1100)
  8. Eraser (1050)
  9. Tweak (1050)
  10. Tool Toolbar (800 - Vertical)
  11. Snapping (750 - Vertical)

We need to decide on the minimum size window we should target. The current minimum window size is about 811x524 pixels with main toolbar on top. Most modern budget displays are 1366x768 and are used by about 20% of desktops. A smaller fraction of about 5% use 1280x720. See Screen Resolution Stats . Gnome recommends a minimum display size of 1024x600.

SpinButtonToolItem

This tool item is a heavily customized widget derived from Gtk::ToolItem. It is used multiple times in most toolbars.

Structure

(Ink == Inkscape::UI::Widget)

Ink::SpinButtonToolItem: public GtkToolItem
  └ Gtk::Box
    ├ Gtk::Image (optional icon)
    ├ Gtk::Label
    └ Ink::SpinButton: pubic Gtk::SpinButton
Functionality
  • on_btn_focus_in_event: Saves current value to be restored if focus is lost, set transfer_focus flag which controls if focus is returned to "focus widget" (i.e. canvas).
  • on_btn_focus_out_event: Unset transfer_focus flag.
  • on_btn_key_press_event (must be replaced by controller).
    • ESC: reset old value, set focus to "focus widget".
    • Return: set focus to "focus widget".
    • Tab: move to next SpinButton in toolbar (probably not needed as moving to next widget is default behavior, and this breaks accessibilty).
    • Left-Tab: move to previous SpinButton in toolbar.
    • Key-up: Increase value by one (should be increment value, this is default behavior of Gtk::SpinButton).
    • Key-down: Decrease value by one.
    • Page-up: Increase value by ten (should be page increment value).
    • Page-down: Decrease value by ten.
  • on_numeric_menu_item_toggled: set new value.
  • on_btn_button_press_event: Pop-up context menu.
  • on_grab_focus: Set focus on Ink:SpinButton
  • misc functions that are not actually used: show_limits, ... , sort_decreasing.
Ink::SpinButton Functionality

Some of this functionality duplicates that in SpinButtonTooltem.

  • on_input: Handles math in entry and units.
  • on_focus_in_event: Saves current value
  • on_key_press_event (SpinButtonToolItem appears to handle these)
    • ESC: reset old value, defocus (set focus to canvas if stay flag false).
    • Return: defocus
    • Tab: Sets "stay" flag (do not leave toolbar).
    • Ctrl-Z: reset old value.

Menus

GTK4 uses menus based on Gio::Menu using Gio::Actions. These are easy to construct with .ui files. They automatically keep in sync with action states and with shortcuts. We have moved to them for the main menu bar in GTK3.

Gio::Menus do have some issues. The first, and perhaps the most important, is with icons. Icons can be specified in the .ui files. In GTK3 they are always shown while in GTK4 they are never shown (by default).

Icons visibility must be enabled for GTK4 using a callback when a menu is opened (similar to how we shift icons with GTK3). To allow a user to choose between:

  1. Showing all icons.
  2. Showing only icons tagged with 'use-icon' attribute in the .ui file.
  3. Never showing icons.

we must resort to rebuilding the Gio::Menu constructed from the .ui file. This is due to a series of unfortunate events including Gio::MenuItem's being immutable and the limited passing of attributes from Gio::Menu's to Gtk::Menu's (GTK3) or Gtk::PopoverMenu's (GTK4). The rebuilding is complicated but doable. See the "Toy program" linked to below. The menu,, once set, is not changeable so Inkscape must be restarted when a user changes their icon preference. Note that GTK discourages the use of "Verb" icons. See: https://discourse.gnome.org/t/toggling-on-off-icon-visibility-in-gmenu-items/7234/2 .

A second problem is that shifting icons into the space reserved for check and toggle button icons in GTK4 doesn't work properly. The "allocation" of widget space seems to have some kind of feedback loop based on the previous icons shift.

A third problem is changing menu labels on the fly as was done for the Undo and Redo entries.

Useful Links

  1. Migrating from Gtk3 to Gtk4
  2. Changes in gtkmm-4.0 and glibmm-2.68
  3. Toy program for testing UI, supports both GTK3 and GTK4