Skip to content

Commit 9ddb8cd

Browse files
authored
Hide/show sliders depending on global switch (#93)
* Hide/show sliders depending on global switch - have a nice animation and window resize doing so * Linter
1 parent 85bc996 commit 9ddb8cd

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

src/MainGrid.vala

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
public class Badger.MainGrid : Gtk.Box {
2222
delegate void SetInterval (uint interval);
23+
public Gtk.Revealer revealer;
2324

2425
public MainGrid (Reminder[] reminders) {
2526
var settings = new GLib.Settings ("com.github.elfenware.badger.timers");
@@ -41,6 +42,7 @@ public class Badger.MainGrid : Gtk.Box {
4142
halign = Gtk.Align.END,
4243
hexpand = true,
4344
valign = Gtk.Align.CENTER,
45+
margin_bottom = 18
4446
};
4547
settings.bind ("all", global_switch, "active", SettingsBindFlags.DEFAULT);
4648
var heading = new Granite.HeaderLabel (_ ("Reminders")) {
@@ -52,23 +54,28 @@ public class Badger.MainGrid : Gtk.Box {
5254
global_box.append (global_switch);
5355
append (global_box);
5456

57+
// This is everything below the switch.
58+
var scale_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
59+
scale_box.vexpand = true;
60+
61+
5562

5663
/************************************************/
5764
/* Label to explain */
5865
/************************************************/
5966

6067
var subheading = new Gtk.Label (_ ("Decide how often Badger should remind you to relax these:")) {
6168
halign = Gtk.Align.START,
62-
margin_top = 18,
63-
margin_bottom = 6
69+
margin_top = 12,
70+
margin_bottom = 0
6471
};
6572
subheading.add_css_class (Granite.STYLE_CLASS_H4_LABEL);
6673
subheading.add_css_class ("title-4");
6774

68-
append (subheading);
75+
scale_box.append (subheading);
6976

7077
var marks = new Marks ();
71-
append (marks);
78+
scale_box.append (marks);
7279

7380
HashTable<string, Gtk.Scale> scales = new HashTable<string, Gtk.Scale> (str_hash, str_equal);
7481

@@ -97,9 +104,6 @@ public class Badger.MainGrid : Gtk.Box {
97104
/* All the scales */
98105
/************************************************/
99106

100-
var scale_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
101-
scale_box.vexpand = true;
102-
103107
for (int index = 0; index < reminders.length; index++) {
104108
Reminder reminder = reminders[index];
105109

@@ -161,9 +165,6 @@ public class Badger.MainGrid : Gtk.Box {
161165

162166
}
163167

164-
append (scale_box);
165-
166-
167168
/********************************************/
168169
/* DnD Label */
169170
/********************************************/
@@ -174,6 +175,19 @@ public class Badger.MainGrid : Gtk.Box {
174175
margin_bottom = 6
175176
};
176177
hey.add_css_class ("accent");
177-
append (hey);
178+
scale_box.append (hey);
179+
180+
/**************************************************/
181+
/* Scales revealer */
182+
/**************************************************/
183+
184+
// If the "all" flag is false, the switch is off, hide the scales
185+
Gtk.Revealer revealer = new Gtk.Revealer ();
186+
revealer.set_transition_type (Gtk.RevealerTransitionType.SLIDE_DOWN);
187+
settings.bind ("all", revealer, "reveal_child", SettingsBindFlags.DEFAULT);
188+
189+
revealer.set_child (scale_box);
190+
append (revealer);
191+
178192
}
179193
}

src/MainWindow.vala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class Badger.MainWindow : Gtk.Window {
3232
}
3333

3434
construct {
35-
Intl.setlocale ();
35+
Intl.setlocale ();
3636
settings = new GLib.Settings ("com.github.elfenware.badger.state");
3737

3838
set_default_size (
@@ -59,6 +59,17 @@ public class Badger.MainWindow : Gtk.Window {
5959

6060
set_child (handle);
6161

62+
var global_switch = new GLib.Settings ("com.github.elfenware.badger.timers");
63+
64+
// Resize window when content gets hidden
65+
global_switch.notify["all"].connect (() => {
66+
if (global_switch.get_boolean ("all") == false) {
67+
this.height_request = 0;
68+
this.default_height = 0;
69+
print ("eugh");
70+
}
71+
});
72+
6273
// save state
6374
close_request.connect (e => {
6475
return before_destroy ();

0 commit comments

Comments
 (0)