[gnome-taquin/arnaudb/wip/gtk4: 69/108] Adapt NewGameScreen.




commit 0475187c2f7174f14892d8d5cf9a4a607256f430
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Feb 19 20:49:42 2020 +0100

    Adapt NewGameScreen.

 data/ui/new-game-screen.ui | 36 ++++-------------------------
 src/new-game-screen.vala   | 57 ++++++++++++++++++++++++++++++----------------
 2 files changed, 42 insertions(+), 51 deletions(-)
---
diff --git a/data/ui/new-game-screen.ui b/data/ui/new-game-screen.ui
index abe1dd6..9f10cf8 100644
--- a/data/ui/new-game-screen.ui
+++ b/data/ui/new-game-screen.ui
@@ -16,10 +16,9 @@
   with this application.  If not, see <https://www.gnu.org/licenses/>.
 -->
 <interface>
-  <requires lib="gtk+" version="3.12"/>
+  <requires lib="gtk+" version="3.96"/>
   <template class="NewGameScreen" parent="GtkBox">
     <property name="orientation">vertical</property>
-    <property name="visible">True</property>
     <property name="spacing">6</property>
     <style>
       <class name="new-game-screen"/>
@@ -39,40 +38,29 @@
     <child>
       <object class="GtkBox" id="games_box">
         <property name="orientation">horizontal</property>
-        <property name="visible">True</property>
         <property name="homogeneous">True</property>
         <property name="spacing">6</property>
         <child>
-          <object class="GtkModelButton" id="modelbutton_one">
-            <property name="visible">True</property>
+          <object class="GtkToggleButton" id="gamebutton_one">
             <property name="name">radio-one</property>
             <style>
               <class name="radio-like-toggle"/>
               <class name="flat"/>
             </style>
             <property name="focus-on-click">False</property>
-            <property name="iconic">True</property>
-            <property name="centered">True</property>
           </object>
         </child>
         <child>
-          <object class="GtkModelButton" id="modelbutton_two">
-            <property name="visible">True</property>
+          <object class="GtkToggleButton" id="gamebutton_two">
             <property name="name">radio-two</property>
             <style>
               <class name="radio-like-toggle"/>
               <class name="flat"/>
             </style>
             <property name="focus-on-click">False</property>
-            <property name="iconic">True</property>
-            <property name="centered">True</property>
           </object>
         </child>
       </object>
-      <packing>
-        <property name="expand">True</property>
-        <property name="fill">True</property>
-      </packing>
     </child>
     <child>
       <object class="GtkSeparator" id="options_separator">
@@ -95,41 +83,27 @@
     <child>
       <object class="GtkBox" id="options_box">
         <property name="orientation">horizontal</property>
-        <property name="visible">True</property>
         <property name="homogeneous">True</property>
         <property name="spacing">6</property>
         <child>
           <object class="GtkMenuButton" id="menubutton_one">
-            <property name="visible">True</property>
-            <property name="use-underline">True</property>
+<!--            <property name="use-underline">True</property>-->
             <style>
               <class name="menubutton-like-combo"/>
               <class name="flat"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-          </packing>
         </child>
         <child>
           <object class="GtkMenuButton" id="menubutton_two">
-            <property name="visible">True</property>
-            <property name="use-underline">True</property>
+<!--            <property name="use-underline">True</property>-->
             <style>
               <class name="menubutton-like-combo"/>
               <class name="flat"/>
             </style>
           </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-          </packing>
         </child>
       </object>
-      <packing>
-        <property name="fill">True</property>
-      </packing>
     </child>
   </template>
 </interface>
diff --git a/src/new-game-screen.vala b/src/new-game-screen.vala
index 9b362ac..b56a97d 100644
--- a/src/new-game-screen.vala
+++ b/src/new-game-screen.vala
@@ -23,8 +23,8 @@ using Gtk;
 [GtkTemplate (ui = "/org/gnome/Taquin/ui/new-game-screen.ui")]
 private class NewGameScreen : Box, AdaptativeWidget
 {
-    [GtkChild] private ModelButton modelbutton_one;
-    [GtkChild] private ModelButton modelbutton_two;
+    [GtkChild] private ToggleButton gamebutton_one;
+    [GtkChild] private ToggleButton gamebutton_two;
 
     [GtkChild] private Gtk.MenuButton menubutton_one;
     [GtkChild] private Gtk.MenuButton menubutton_two;
@@ -37,19 +37,24 @@ private class NewGameScreen : Box, AdaptativeWidget
         if (gdk_display != null) // else..?
             StyleContext.add_provider_for_display ((!) gdk_display, css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
 
-        fix_race ();
+        Widget? widget = menubutton_one.get_first_child ();
+        if (widget != null && (!) widget is ToggleButton)
+            ((!) widget).get_style_context ().add_class ("flat");
+        widget = menubutton_two.get_first_child ();
+        if (widget != null && (!) widget is ToggleButton)
+            ((!) widget).get_style_context ().add_class ("flat");
     }
 
-    internal NewGameScreen (string modelbutton_one_label,
-                            string modelbutton_one_action,
-                            string modelbutton_two_label,
-                            string modelbutton_two_action)
+    internal NewGameScreen (string gamebutton_one_label,
+                            string gamebutton_one_action,
+                            string gamebutton_two_label,
+                            string gamebutton_two_action)
     {
-        modelbutton_one.text = modelbutton_one_label;
-        modelbutton_two.text = modelbutton_two_label;
+        gamebutton_one.label = gamebutton_one_label;
+        gamebutton_two.label = gamebutton_two_label;
 
-        modelbutton_one.set_detailed_action_name (modelbutton_one_action);
-        modelbutton_two.set_detailed_action_name (modelbutton_two_action);
+        gamebutton_one.set_detailed_action_name (gamebutton_one_action);
+        gamebutton_two.set_detailed_action_name (gamebutton_two_action);
     }
 
     /*\
@@ -63,10 +68,29 @@ private class NewGameScreen : Box, AdaptativeWidget
 
     internal inline void update_menubutton_label (MenuButton button, string label)
     {
+        Widget? widget;
         switch (button)
         {
-            case MenuButton.ONE: menubutton_one.set_label (label); return;
-            case MenuButton.TWO: menubutton_two.set_label (label); return;
+            case MenuButton.ONE:
+                menubutton_one.set_label (label);
+                widget = menubutton_one.get_first_child ();
+                if (widget != null && (!) widget is ToggleButton)
+                {
+                    widget = ((!) widget).get_first_child ();
+                    if (widget != null && (!) widget is Box)
+                        ((!) widget).halign = Align.CENTER;
+                }
+                return;
+
+            case MenuButton.TWO: menubutton_two.set_label (label);
+                widget = menubutton_two.get_first_child ();
+                if (widget != null && (!) widget is ToggleButton)
+                {
+                    widget = ((!) widget).get_first_child ();
+                    if (widget != null && (!) widget is Box)
+                        ((!) widget).halign = Align.CENTER;
+                }
+                return;
         }
     }
 
@@ -100,12 +124,6 @@ private class NewGameScreen : Box, AdaptativeWidget
     * * adaptative stuff
     \*/
 
-    private void fix_race ()   // FIXME things are a bit racy between the CSS and the box orientation 
changes, so delay games_box redraw
-    {
-        size_allocate.connect_after (() => games_box.show ());
-        map.connect (() => games_box.show ());
-    }
-
     [GtkChild] private Box          games_box;
     [GtkChild] private Box          options_box;
 
@@ -151,7 +169,6 @@ private class NewGameScreen : Box, AdaptativeWidget
                 this.set_orientation (Orientation.VERTICAL);
                 games_box.set_orientation (Orientation.HORIZONTAL);
                 options_box.set_orientation (Orientation.HORIZONTAL);
-                games_box.hide ();
             }
         }
         else if (_phone_size)


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