[gnome-games/wip/exalm/issue98] collection-icon-view: Set children size via CSS
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/issue98] collection-icon-view: Set children size via CSS
- Date: Sun, 23 Sep 2018 09:59:11 +0000 (UTC)
commit 4177bf3eb38409c6dbc2c2af32a60920caa3f46d
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sun Sep 23 14:47:53 2018 +0500
collection-icon-view: Set children size via CSS
Avoid manually setting width-request within size_allocate() handler.
Use CSS 'min-width' property for sizing and just dynamically add/remove a
style class.
data/gtk-style.css | 8 ++++++++
src/ui/collection-icon-view.vala | 27 ++-------------------------
2 files changed, 10 insertions(+), 25 deletions(-)
---
diff --git a/data/gtk-style.css b/data/gtk-style.css
index bddbeb35..5b58ade7 100644
--- a/data/gtk-style.css
+++ b/data/gtk-style.css
@@ -26,6 +26,14 @@ gamesgamethumbnail {
color: @theme_fg_color;
}
+gamescollectioniconview flowboxchild {
+ min-width: 128px;
+}
+
+gamescollectioniconview.large flowboxchild {
+ min-width: 256px;
+}
+
/* Styles from libhandy example, this should be kept in sync with this:
* https://source.puri.sm/Librem5/libhandy/blob/master/examples/style.css
*/
diff --git a/src/ui/collection-icon-view.vala b/src/ui/collection-icon-view.vala
index 3290aee0..f5e7e0d4 100644
--- a/src/ui/collection-icon-view.vala
+++ b/src/ui/collection-icon-view.vala
@@ -78,9 +78,6 @@ private class Games.CollectionIconView : Gtk.Bin {
[GtkChild]
private GamepadBrowse gamepad_browse;
- // Current size used by the thumbnails.
- private int game_view_size;
-
static construct {
set_css_name ("gamescollectioniconview");
}
@@ -215,7 +212,6 @@ private class Games.CollectionIconView : Gtk.Bin {
var child = new Gtk.FlowBoxChild ();
game_view.visible = true;
- game_view.width_request = game_view_size;
child.visible = true;
child.add (game_view);
@@ -275,27 +271,8 @@ private class Games.CollectionIconView : Gtk.Bin {
// them rather than a few huge thumbnails, making Games more usable on
// small screens.
if (allocation.width < 960)
- set_size (128);
+ get_style_context ().remove_class ("large");
else
- set_size (256);
- }
-
- private void set_size (int size) {
- if (game_view_size == size)
- return;
-
- game_view_size = size;
-
- flow_box.forall ((child) => {
- var flow_box_child = child as Gtk.FlowBoxChild;
-
- assert (flow_box_child != null);
-
- var game_view = flow_box_child.get_child () as GameIconView;
-
- assert (game_view != null);
-
- game_view.width_request = size;
- });
+ get_style_context ().add_class ("large");
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]