[lightsoff/arnaudb/rework-ui: 6/9] Add first-level hint.




commit b785a2c9d5c418f70200919ec084f44e08280d96
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Nov 18 13:52:17 2020 +0100

    Add first-level hint.
    
    This was removed in 269ccfc90f.
    
    Set also a default window size.

 data/lightsoff.css                   | 12 ++++++
 data/lightsoff.ui                    | 74 ++++++++++++++++++--------------
 data/notifications-revealer.ui       | 70 +++++++++++++++++++++++++++++++
 data/org.gnome.LightsOff.gschema.xml |  4 +-
 src/lightsoff-window.vala            | 21 ++++++----
 src/lightsoff.gresource.xml          |  1 +
 src/meson.build                      |  1 +
 src/notifications-revealer.vala      | 81 ++++++++++++++++++++++++++++++++++++
 8 files changed, 223 insertions(+), 41 deletions(-)
---
diff --git a/data/lightsoff.css b/data/lightsoff.css
index 1fe5615..d948e58 100644
--- a/data/lightsoff.css
+++ b/data/lightsoff.css
@@ -64,3 +64,15 @@ label.score-label:dir(rtl) {
 label.score-label:dir(ltr) {
   margin-right: 6px;
 }
+
+/*\
+* * app notification
+\*/
+
+.thin-window .app-notification {
+  border-radius:0;
+}
+
+/*\
+* * the end
+\*/
diff --git a/data/lightsoff.ui b/data/lightsoff.ui
index 894903d..5a22f71 100644
--- a/data/lightsoff.ui
+++ b/data/lightsoff.ui
@@ -79,51 +79,61 @@
       </object>
     </child>
     <child>
-      <object class="GtkGrid">
+      <object class="GtkOverlay">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <child>
-          <object class="GtkAspectFrame" id="aspect_frame">
+          <object class="GtkGrid">
             <property name="visible">True</property>
-            <property name="obey_child">False</property>
-            <property name="shadow_type">none</property>
-            <style>
-              <class name="aspect"/>
-            </style>
-          </object>
-        </child>
-        <child>
-          <object class="GtkRevealer" id="revealer">
-            <property name="visible">True</property>
-            <property name="reveal-child">False</property>
+            <property name="orientation">vertical</property>
             <child>
-              <object class="GtkActionBar">
+              <object class="GtkAspectFrame" id="aspect_frame">
                 <property name="visible">True</property>
+                <property name="obey_child">False</property>
+                <property name="shadow_type">none</property>
+                <style>
+                  <class name="aspect"/>
+                </style>
+              </object>
+            </child>
+            <child>
+              <object class="GtkRevealer" id="revealer">
+                <property name="visible">True</property>
+                <property name="reveal-child">False</property>
                 <child>
-                  <object class="GtkLabel" id="level_label">
-                    <property name="visible">True</property>
-                    <property name="label" translatable="no">Puzzle X</property>
-                    <style>
-                      <class name="level-label"/>
-                    </style>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkLabel" id="score_label_2">
+                  <object class="GtkActionBar">
                     <property name="visible">True</property>
-                    <property name="label" translatable="no">0</property>
-                    <style>
-                      <class name="score-label"/>
-                    </style>
+                    <child>
+                      <object class="GtkLabel" id="level_label">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="no">Puzzle X</property>
+                        <style>
+                          <class name="level-label"/>
+                        </style>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="score_label_2">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="no">0</property>
+                        <style>
+                          <class name="score-label"/>
+                        </style>
+                      </object>
+                      <packing>
+                        <property name="pack_type">end</property>
+                      </packing>
+                    </child>
                   </object>
-                  <packing>
-                    <property name="pack_type">end</property>
-                  </packing>
                 </child>
               </object>
             </child>
           </object>
         </child>
+        <child type="overlay">
+          <object class="NotificationsRevealer" id="notifications_revealer">
+            <property name="visible">True</property>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/data/notifications-revealer.ui b/data/notifications-revealer.ui
new file mode 100644
index 0000000..b4ad275
--- /dev/null
+++ b/data/notifications-revealer.ui
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  This file is part of LightsOff
+
+  LightsOff 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.
+
+  LightsOff 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 LightsOff.  If not, see <https://www.gnu.org/licenses/>.
+-->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <template class="NotificationsRevealer" parent="GtkRevealer">
+    <property name="halign">center</property>
+    <property name="valign">start</property>
+    <child>
+      <object class="GtkFrame">
+        <property name="visible">True</property>
+        <style>
+          <class name="app-notification"/>
+        </style>
+        <child>
+          <object class="GtkGrid">
+            <property name="visible">True</property>
+            <property name="column-spacing">6</property>
+            <child>
+              <object class="GtkLabel" id="notification_label">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="xalign">0</property>
+                <property name="wrap">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSeparator">
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkButton">
+                <property name="visible">True</property>
+                <property name="valign">center</property>
+                <property name="focus-on-click">False</property>
+                <property name="relief">none</property>
+                <property name="action-name">notification.hide</property>
+                <style>
+                  <class name="image-button"/>
+                </style>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="icon-name">window-close-symbolic</property>
+                    <property name="icon-size">1</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/data/org.gnome.LightsOff.gschema.xml b/data/org.gnome.LightsOff.gschema.xml
index 2f08fd5..16ab2c1 100644
--- a/data/org.gnome.LightsOff.gschema.xml
+++ b/data/org.gnome.LightsOff.gschema.xml
@@ -12,14 +12,14 @@
 
   <schema id="org.gnome.LightsOff.Lib" gettext-domain="lightsoff">
     <key name="window-width" type="i">
-      <default>1</default>
+      <default>800</default>
       <!-- Translators: summary of a settings key, see 'dconf-editor /org/gnome/LightsOff/window-width' -->
       <summary>The width of the window</summary>
       <!-- Translators: description of a settings key, see 'dconf-editor /org/gnome/LightsOff/window-width' 
-->
       <description>The width of the main window in pixels.</description>
     </key>
     <key name="window-height" type="i">
-      <default>1</default>
+      <default>600</default>
       <!-- Translators: summary of a settings key, see 'dconf-editor /org/gnome/LightsOff/window-height' -->
       <summary>The height of the window</summary>
       <!-- Translators: description of a settings key, see 'dconf-editor /org/gnome/LightsOff/window-height' 
-->
diff --git a/src/lightsoff-window.vala b/src/lightsoff-window.vala
index 5aa1e8c..0dc018c 100644
--- a/src/lightsoff-window.vala
+++ b/src/lightsoff-window.vala
@@ -15,13 +15,14 @@ using Gtk;
 [GtkTemplate (ui = "/org/gnome/LightsOff/ui/lightsoff.ui")]
 private class LightsoffWindow : ManagedWindow
 {
-    [GtkChild] private HeaderBar    headerbar;
-    [GtkChild] private MenuButton   menu_button;
-    [GtkChild] private Label        level_label;
-    [GtkChild] private Label        score_label_1;
-    [GtkChild] private Label        score_label_2;
-    [GtkChild] private AspectFrame  aspect_frame;
-    [GtkChild] private Revealer     revealer;
+    [GtkChild] private HeaderBar                headerbar;
+    [GtkChild] private MenuButton               menu_button;
+    [GtkChild] private Label                    level_label;
+    [GtkChild] private Label                    score_label_1;
+    [GtkChild] private Label                    score_label_2;
+    [GtkChild] private AspectFrame              aspect_frame;
+    [GtkChild] private Revealer                 revealer;
+    [GtkChild] private NotificationsRevealer    notifications_revealer;
 
     private GLib.Settings settings;
     private GameView game_view;
@@ -75,6 +76,9 @@ private class LightsoffWindow : ManagedWindow
         init_keyboard ();
         int level = settings.get_int ("level");
         level_changed_cb (level);
+        if (level == 1)
+            /* Translators: short game explanation, displayed as an in-app notification when game is 
launched on level 1 */
+            notifications_revealer.show_notification (_("Turn off all the lights!"));
 
         populate_game_container (level);
 
@@ -95,6 +99,7 @@ private class LightsoffWindow : ManagedWindow
             headerbar.set_title (custom_title);
         level_label.set_label (custom_title);
         update_subtitle (0);
+        notifications_revealer.hide_notification ();
     }
 
     private void previous_level_cb ()
@@ -156,12 +161,14 @@ private class LightsoffWindow : ManagedWindow
             score_label_1.show ();
             headerbar.set_title (custom_title);
             revealer.set_reveal_child (false);
+            notifications_revealer.set_window_size (/* thin */ false);
         }
         else
         {
             score_label_1.hide ();
             headerbar.set_title (null);
             revealer.set_reveal_child (true);
+            notifications_revealer.set_window_size (/* thin */ true);
         }
     }
 }
diff --git a/src/lightsoff.gresource.xml b/src/lightsoff.gresource.xml
index 8f254db..ad04bc1 100644
--- a/src/lightsoff.gresource.xml
+++ b/src/lightsoff.gresource.xml
@@ -3,6 +3,7 @@
   <gresource prefix="/org/gnome/LightsOff/ui">
     <file preprocess="xml-stripblanks" alias="lightsoff.ui">../data/lightsoff.ui</file>
     <file alias="lightsoff.css">../data/lightsoff.css</file>
+    <file preprocess="xml-stripblanks" 
alias="notifications-revealer.ui">../data/notifications-revealer.ui</file>
   </gresource>
   <gresource prefix="/org/gnome/LightsOff/gtk">
     <file preprocess="xml-stripblanks" alias="menus.ui">../data/lightsoff-menus.ui</file>
diff --git a/src/meson.build b/src/meson.build
index 7b2a454..803cbf5 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,6 +7,7 @@ lightsoff_vala_sources = [
   'game-view.vala',
   'game-view-gtk.vala',
   'managed-window.vala',
+  'notifications-revealer.vala',
 ]
 
 lightsoff_resources_file = files('lightsoff.gresource.xml')
diff --git a/src/notifications-revealer.vala b/src/notifications-revealer.vala
new file mode 100644
index 0000000..305eea0
--- /dev/null
+++ b/src/notifications-revealer.vala
@@ -0,0 +1,81 @@
+/*
+  This file is part of LightsOff
+
+  LightsOff 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.
+
+  LightsOff 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 LightsOff.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+using Gtk;
+
+[GtkTemplate (ui = "/org/gnome/LightsOff/ui/notifications-revealer.ui")]
+private class NotificationsRevealer : Revealer
+{
+    [GtkChild] private Label notification_label;
+
+    construct
+    {
+        install_action_entries ();
+    }
+
+    /*\
+    * * internal calls
+    \*/
+
+    internal void show_notification (string notification)
+    {
+        notification_label.set_text (notification);
+        set_reveal_child (true);
+    }
+
+    private bool thin_window_size = false;
+    internal void set_window_size (bool thin)
+    {
+        if (thin_window_size == thin)
+            return;
+        thin_window_size = thin;
+
+        if (thin)
+        {
+            hexpand = true;
+            halign = Align.FILL;
+            get_style_context ().add_class ("thin-window");
+        }
+        else
+        {
+            hexpand = false;
+            halign = Align.CENTER;
+            get_style_context ().remove_class ("thin-window");
+        }
+    }
+
+    /*\
+    * * action entries
+    \*/
+
+    private void install_action_entries ()
+    {
+        SimpleActionGroup action_group = new SimpleActionGroup ();
+        action_group.add_action_entries (action_entries, this);
+        insert_action_group ("notification", action_group);
+    }
+
+    private const GLib.ActionEntry [] action_entries =
+    {
+        { "hide", hide_notification }
+    };
+
+    internal void hide_notification (/* SimpleAction action, Variant? variant */)
+    {
+        set_reveal_child (false);
+    }
+}


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