[four-in-a-row: 13/13] Introduce GameActionBarPlaceHolder.



commit a741c00c6aa7061537d0e4d188abed20de740fe3
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Dec 20 18:06:12 2019 +0100

    Introduce GameActionBarPlaceHolder.

 data/four-in-a-row.css                |  1 -
 data/ui/game-actionbar-placeholder.ui | 30 +++++++++++++++++++++++++++
 src/four-in-a-row.gresource.xml       |  1 +
 src/game-actionbar.vala               | 39 +++++++++++++++++++++++++++++++++++
 src/game-window.vala                  |  5 +++++
 5 files changed, 75 insertions(+), 1 deletion(-)
---
diff --git a/data/four-in-a-row.css b/data/four-in-a-row.css
index ddc4b56..56187ef 100644
--- a/data/four-in-a-row.css
+++ b/data/four-in-a-row.css
@@ -36,7 +36,6 @@ GtkButtonBox {
                   .thin-window .game-box                {                          padding:1.0rem; }
 .extra-thin-window.thin-window .game-box,
                   .flat-window .game-box                {                          padding:0.5rem; }
-.extra-thin-window.thin-window .game-box                {                          
padding-bottom:calc(0.5rem+47px); } /* FIXME hackish, height of the actionbar using MySettings(TM)... */
 .extra-flat-window.flat-window .game-box                {                          padding:0.4rem; }
 
 /*\
diff --git a/data/ui/game-actionbar-placeholder.ui b/data/ui/game-actionbar-placeholder.ui
new file mode 100644
index 0000000..2b69eee
--- /dev/null
+++ b/data/ui/game-actionbar-placeholder.ui
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   This file is part of a GNOME game
+
+   Copyright (C) 2019 – Arnaud Bonatti <arnaud bonatti gmail com>
+
+   This application is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This application is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this application.  If not, see <https://www.gnu.org/licenses/>.
+-->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <template class="GameActionBarPlaceHolder" parent="GtkRevealer">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkDrawingArea" id="placeholder_child">
+        <property name="visible">True</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/four-in-a-row.gresource.xml b/src/four-in-a-row.gresource.xml
index b0e11c9..eb7ef77 100644
--- a/src/four-in-a-row.gresource.xml
+++ b/src/four-in-a-row.gresource.xml
@@ -14,6 +14,7 @@
     <file preprocess="xml-stripblanks" compressed="true" 
alias="fiar-screens.ui">../data/ui/fiar-screens.ui</file>
     <file preprocess="xml-stripblanks" compressed="true" 
alias="game-window.ui">../data/ui/four-in-a-row.ui</file>
     <file preprocess="xml-stripblanks" compressed="true" 
alias="game-actionbar.ui">../data/ui/game-actionbar.ui</file>
+    <file preprocess="xml-stripblanks" compressed="true" 
alias="game-actionbar-placeholder.ui">../data/ui/game-actionbar-placeholder.ui</file>
     <file preprocess="xml-stripblanks" compressed="true" 
alias="history-button.ui">../data/ui/history-button.ui</file>
   </gresource>
 </gresources>
diff --git a/src/game-actionbar.vala b/src/game-actionbar.vala
index 297006c..7937db4 100644
--- a/src/game-actionbar.vala
+++ b/src/game-actionbar.vala
@@ -89,3 +89,42 @@ private class GameActionBar : Revealer, AdaptativeWidget
         update_visibility ();
     }
 }
+
+[GtkTemplate (ui = "/org/gnome/Four-in-a-row/ui/game-actionbar-placeholder.ui")]
+private class GameActionBarPlaceHolder : Revealer, AdaptativeWidget
+{
+    [GtkChild] private Widget placeholder_child;
+    private GameActionBar actionbar;
+
+    internal GameActionBarPlaceHolder (GameActionBar _actionbar)
+    {
+        actionbar = _actionbar;
+        actionbar.size_allocate.connect (set_height);
+        set_height ();
+        set_reveal_child (true);    // seems like setting it in the UI file does not work, while it is OK 
for GameActionBar...
+    }
+
+    private void set_height ()
+    {
+        Requisition natural_size;
+        Widget? widget = actionbar.get_child ();
+        if (widget == null)
+            return;
+        ((!) widget).get_preferred_size (/* minimum size */ null, out natural_size);
+        placeholder_child.height_request = natural_size.height;
+    }
+
+    /*\
+    * * adaptative stuff
+    \*/
+
+    private bool is_extra_thin = true;
+    protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
+    {
+        bool _is_extra_thin = AdaptativeWidget.WindowSize.is_extra_thin (new_size);
+        if (_is_extra_thin == is_extra_thin)
+            return;
+        is_extra_thin = _is_extra_thin;
+        set_reveal_child (is_extra_thin);
+    }
+}
diff --git a/src/game-window.vala b/src/game-window.vala
index 6ec0137..3510bee 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -105,9 +105,14 @@ private class GameWindow : AdaptativeWindow, AdaptativeWidget
         actionbar.valign = Align.END;
         overlay.add_overlay (actionbar);
 
+        GameActionBarPlaceHolder actionbar_placeholder = new GameActionBarPlaceHolder (actionbar);
+        actionbar_placeholder.show ();
+        game_box.pack_end (actionbar_placeholder, /* expand */ false, /* fill */ true, /* padding */ 0);
+
         new_game_box.pack_start (new_game_screen, true, true, 0);
         add_adaptative_child ((AdaptativeWidget) new_game_screen);
         add_adaptative_child ((AdaptativeWidget) actionbar);
+        add_adaptative_child ((AdaptativeWidget) actionbar_placeholder);
         add_adaptative_child ((AdaptativeWidget) this);
         if (GameWindowFlags.SHOW_START_BUTTON in flags)
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]