[gnome-calculator] math-buttons: Add the "view more" button



commit 3c316ff1011dac4e095264540e8ed719cd838819
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed Mar 10 16:18:01 2021 +0100

    math-buttons: Add the "view more" button
    
    This adds a button at the end of the converter-like bars to switch
    between the two button sets when the current leaflet is folded.

 src/math-buttons.vala         | 89 +++++++++++++++++++++++++++++++++++++++++++
 src/math-converter.vala       |  3 ++
 src/ui/buttons-programming.ui | 20 +++++++++-
 src/ui/math-converter.ui      | 21 ++++++++++
 4 files changed, 132 insertions(+), 1 deletion(-)
---
diff --git a/src/math-buttons.vala b/src/math-buttons.vala
index 7f8e85f6..bb912240 100644
--- a/src/math-buttons.vala
+++ b/src/math-buttons.vala
@@ -49,6 +49,17 @@ public class MathButtons : Gtk.Box
                 converter.set_category ("currency");
                 converter.set_conversion (equation.source_currency, equation.target_currency);
             }
+
+            update_view_more_visible ();
+            converter.view_more_active = false;
+            if (prog_view_more_button != null)
+                prog_view_more_button.active = false;
+            if (adv_panel != null)
+                (adv_panel as Hdy.Leaflet).visible_child_name = "basic";
+            if (fin_panel != null)
+                (fin_panel as Hdy.Leaflet).visible_child_name = "basic";
+            if (prog_leaflet != null)
+                prog_leaflet.visible_child_name = "basic";
         }
     }
     private int _programming_base = 10;
@@ -66,6 +77,9 @@ public class MathButtons : Gtk.Box
     private Gtk.Widget prog_panel;
     private Gtk.Widget? active_panel = null;
 
+    private Hdy.Leaflet prog_leaflet;
+    private Gtk.ToggleButton prog_view_more_button;
+
     private Gtk.ComboBox base_combo;
     private Gtk.Label base_label;
     private Gtk.Label word_size_label;
@@ -288,6 +302,54 @@ public class MathButtons : Gtk.Box
         
     }
 
+    private void update_view_more_visible ()
+    {
+        bool visible;
+
+        switch (mode)
+        {
+        default:
+        case ButtonMode.BASIC:
+            visible = false;
+            break;
+        case ButtonMode.ADVANCED:
+            visible = adv_panel != null && (adv_panel as Hdy.Leaflet).folded;
+            break;
+        case ButtonMode.FINANCIAL:
+            visible = fin_panel != null && (fin_panel as Hdy.Leaflet).folded;
+            break;
+        case ButtonMode.PROGRAMMING:
+            visible = prog_leaflet != null && prog_leaflet.folded;
+            break;
+        }
+
+        converter.view_more_visible = visible;
+        if (prog_view_more_button != null)
+            prog_view_more_button.visible = visible;
+    }
+
+    private void update_view_more_active ()
+    {
+        switch (mode)
+        {
+        default:
+        case ButtonMode.BASIC:
+            break;
+        case ButtonMode.ADVANCED:
+            if (adv_panel != null)
+                converter.view_more_active = prog_view_more_button.active = (adv_panel as 
Hdy.Leaflet).visible_child_name == "advanced";
+            break;
+        case ButtonMode.FINANCIAL:
+            if (fin_panel != null)
+                converter.view_more_active = prog_view_more_button.active = (fin_panel as 
Hdy.Leaflet).visible_child_name == "advanced";
+            break;
+        case ButtonMode.PROGRAMMING:
+            if (prog_panel != null)
+                converter.view_more_active = prog_view_more_button.active = prog_leaflet.visible_child_name 
== "advanced";
+            break;
+        }
+    }
+
     private Gtk.Widget load_mode (ButtonMode mode)
     {
         Gtk.Builder builder;
@@ -341,12 +403,32 @@ public class MathButtons : Gtk.Box
             break;
         case ButtonMode.ADVANCED:
             adv_panel = panel;
+
+            converter.bind_property ("view-more-active", panel, "visible-child-name",
+                                     BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL,
+                                     (binding, from, ref to) => { to.set_string (from.get_boolean () ? 
"advanced" : "basic"); return true; },
+                                     (binding, from, ref to) => { to.set_boolean (from.get_string () == 
"advanced"); return true; });
+            adv_panel.notify["folded"].connect (update_view_more_visible);
             break;
         case ButtonMode.FINANCIAL:
             fin_panel = panel;
+
+            converter.bind_property ("view-more-active", panel, "visible-child-name",
+                                     BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL,
+                                     (binding, from, ref to) => { to.set_string (from.get_boolean () ? 
"advanced" : "basic"); return true; },
+                                     (binding, from, ref to) => { to.set_boolean (from.get_string () == 
"advanced"); return true; });
+            fin_panel.notify["folded"].connect (update_view_more_visible);
             break;
         case ButtonMode.PROGRAMMING:
             prog_panel = panel;
+            prog_leaflet = builder.get_object ("leaflet") as Hdy.Leaflet;
+
+            prog_view_more_button = builder.get_object ("view_more_button") as Gtk.ToggleButton;
+            prog_view_more_button.bind_property ("active", prog_leaflet, "visible-child-name",
+                                                 BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL,
+                                                 (binding, from, ref to) => { to.set_string 
(from.get_boolean () ? "advanced" : "basic"); return true; },
+                                                 (binding, from, ref to) => { to.set_boolean 
(from.get_string () == "advanced"); return true; });
+            prog_leaflet.notify["folded"].connect (update_view_more_visible);
             break;
         }
 
@@ -408,6 +490,7 @@ public class MathButtons : Gtk.Box
         builder.connect_signals (this);
 
         update_bit_panel ();
+        update_view_more_visible ();
 
         return panel;
     }
@@ -438,6 +521,12 @@ public class MathButtons : Gtk.Box
             converter = new MathConverter (equation);
             converter.changed.connect (converter_changed_cb);
             pack_start (converter, false, true, 0);
+            converter.notify["view-more-active"].connect (() => {
+                if (adv_panel != null)
+                    (adv_panel as Hdy.Leaflet).visible_child_name = converter.view_more_active ? "advanced" 
: "basic";
+                if (fin_panel != null)
+                    (fin_panel as Hdy.Leaflet).visible_child_name = converter.view_more_active ? "advanced" 
: "basic";
+            });
         }
 
         var panel = load_mode (mode);
diff --git a/src/math-converter.vala b/src/math-converter.vala
index d0ae583d..128ba149 100644
--- a/src/math-converter.vala
+++ b/src/math-converter.vala
@@ -27,6 +27,9 @@ public class MathConverter : Gtk.Grid
     [GtkChild]
     private unowned Gtk.Label to_label;
 
+    public bool view_more_visible { set; get; default = false; }
+    public bool view_more_active { set; get; default = false; }
+
     public signal void changed ();
 
     static construct {
diff --git a/src/ui/buttons-programming.ui b/src/ui/buttons-programming.ui
index cd5d8ea6..f4b390cd 100644
--- a/src/ui/buttons-programming.ui
+++ b/src/ui/buttons-programming.ui
@@ -47,6 +47,24 @@
             <property name="expand">True</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkToggleButton" id="view_more_button">
+            <property name="can_focus">False</property>
+            <property name="receives_default">False</property>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">view-more-horizontal-symbolic</property>
+                <property name="icon_size">1</property>
+              </object>
+            </child>
+            <style>
+              <class name="image-button"/>
+              <class name="view-more-button"/>
+            </style>
+          </object>
+        </child>
       </object>
       <packing>
         <property name="expand">False</property>
@@ -1353,7 +1371,7 @@
       </packing>
     </child>
     <child>
-      <object class="HdyLeaflet">
+      <object class="HdyLeaflet" id="leaflet">
         <property name="visible">True</property>
         <property name="can-swipe-back">True</property>
         <property name="can-swipe-forward">True</property>
diff --git a/src/ui/math-converter.ui b/src/ui/math-converter.ui
index d0dc9d33..7e97c9da 100644
--- a/src/ui/math-converter.ui
+++ b/src/ui/math-converter.ui
@@ -72,6 +72,7 @@
         <property name="valign">center</property>
         <property name="hexpand">True</property>
         <property name="vexpand">False</property>
+        <property name="visible" bind-source="MathConverter" bind-property="view-more-visible" 
bind-flags="sync-create|bidirectional|invert-boolean"/>
         <child>
           <object class="GtkLabel" id="from_label">
             <property name="visible">True</property>
@@ -189,6 +190,26 @@
             <property name="fill">true</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkToggleButton" id="view_more_button">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="receives_default">False</property>
+            <property name="active" bind-source="MathConverter" bind-property="view-more-active" 
bind-flags="sync-create|bidirectional"/>
+            <child>
+              <object class="GtkImage">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="icon_name">view-more-horizontal-symbolic</property>
+                <property name="icon_size">1</property>
+              </object>
+            </child>
+            <style>
+              <class name="image-button"/>
+              <class name="view-more-button"/>
+            </style>
+          </object>
+        </child>
       </object>
       <packing>
         <property name="left-attach">0</property>


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