[gnome-boxes/list-max-content-width: 8/8] list-view: Allow ListView to shrink
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/list-max-content-width: 8/8] list-view: Allow ListView to shrink
- Date: Thu, 13 Dec 2018 12:44:44 +0000 (UTC)
commit e04c71a6d43f232a19dc952b4291c8d6b7660ee6
Author: Felipe Borges <felipeborges gnome org>
Date: Tue Dec 11 13:24:58 2018 +0100
list-view: Allow ListView to shrink
We were forcing a constant width for ListView rows in order to limit
the maximium width of the content. This prevented the main Boxes
window from being resized to values smaller than that.
Now we store a max-content-width value in the ListView and whenever
the allocated width for the main window is smaller than that, we
just let the listbox fill the available space.
This is somewhat a responsive behavior for width allocation that
should cover small screen devices or tiling displays.
Hopefully Gtk4 will introduce a max-width CSS property that would
ease the implementation of these use cases. Alternatively, Gtk4
might have a constraint layout machinery that would obsolete this
issue.
Fixes #76
data/ui/list-view-row.ui | 1 -
data/ui/list-view.ui | 3 ++-
src/list-view.vala | 15 +++++++++++++++
3 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/list-view-row.ui b/data/ui/list-view-row.ui
index b49d9090..7affca93 100644
--- a/data/ui/list-view-row.ui
+++ b/data/ui/list-view-row.ui
@@ -3,7 +3,6 @@
<!-- interface-requires gtk+ 3.9 -->
<template class="BoxesListViewRow" parent="GtkBox">
<property name="visible">True</property>
- <property name="width-request">848</property>
<property name="margin-start">24</property>
<property name="margin-end">24</property>
<property name="margin-top">8</property>
diff --git a/data/ui/list-view.ui b/data/ui/list-view.ui
index 131ef247..08c065a4 100644
--- a/data/ui/list-view.ui
+++ b/data/ui/list-view.ui
@@ -5,6 +5,8 @@
<property name="visible">True</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">automatic</property>
+ <property name="max-content-width">948</property>
+ <signal name="size-allocate" handler="on_size_allocate"/>
<child>
<object class="GtkBox">
@@ -21,7 +23,6 @@
<property name="margin-end">24</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
- <property name="halign">center</property>
<property name="valign">start</property>
<signal name="button-release-event" handler="on_button_press_event"/>
<signal name="key-press-event" handler="on_key_press_event"/>
diff --git a/src/list-view.vala b/src/list-view.vala
index 723ab8ed..3537c16d 100644
--- a/src/list-view.vala
+++ b/src/list-view.vala
@@ -342,4 +342,19 @@ public void unselect_all () {
App.app.notify_property ("selected-items");
}
+
+ [GtkCallback]
+ private void on_size_allocate (Gtk.Allocation allocation) {
+ // Work around for https://gitlab.gnome.org/GNOME/gnome-boxes/issues/76
+ bool small_screen = (allocation.width < max_content_width);
+
+ if (small_screen) {
+ list_box.halign = Gtk.Align.FILL;
+ list_box.set_size_request (-1, -1);
+ } else {
+ list_box.halign = Gtk.Align.CENTER;
+ // 100 here should cover margins, padding, and theme specifics.
+ list_box.set_size_request (max_content_width - 100, -1);
+ }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]