[gnome-usage] graph-stack-switcher: Change graphSwitcherButton to GtkRadioButton
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-usage] graph-stack-switcher: Change graphSwitcherButton to GtkRadioButton
- Date: Fri, 13 Apr 2018 15:04:09 +0000 (UTC)
commit f44dc4b1eed2a08457702e2ca5dc85e99e2c0c11
Author: Petr Štětka <pstetka redhat com>
Date: Mon Jan 15 15:49:06 2018 +0100
graph-stack-switcher: Change graphSwitcherButton to GtkRadioButton
With GtkRadioButton we can benefit from its "grouping" capabilities
to make sure that only one is active/toggled at the time.
https://bugzilla.gnome.org/show_bug.cgi?id=785801
data/interface/adwaita.css | 16 +------------
src/graph-stack-switcher.vala | 53 ++++++++++++++----------------------------
src/graph-switcher-button.vala | 17 +++++++++++---
3 files changed, 33 insertions(+), 53 deletions(-)
---
diff --git a/data/interface/adwaita.css b/data/interface/adwaita.css
index 2bd261c..7a75efa 100644
--- a/data/interface/adwaita.css
+++ b/data/interface/adwaita.css
@@ -46,25 +46,11 @@ subprocess-list row.max:hover {
border: 1px solid #faa5a2;
}
-graph-switcher-button {
- padding: 6px 10px;
+button.graph-switcher {
border-style: none;
border-radius: 0;
}
-graph-switcher-button:hover {
- background-color: @theme_base_color;
-}
-
-graph-switcher-button:checked {
- background-color: alpha(@theme_fg_color, 0.2);
-}
-
-graph-switcher-button:active {
- background-color: alpha(@theme_fg_color, 0.2);
- box-shadow: inset 0 2px 2px -2px rgba(0, 0, 0, 0.2);
-}
-
rg-graph.big {
background-color: #ffffff;
background-size: 57px 57px;
diff --git a/src/graph-stack-switcher.vala b/src/graph-stack-switcher.vala
index b3845c5..f13a02c 100644
--- a/src/graph-stack-switcher.vala
+++ b/src/graph-stack-switcher.vala
@@ -25,9 +25,7 @@ namespace Usage
Gtk.Stack stack;
View[] sub_views;
- Gtk.ToggleButton[] buttons;
-
- bool can_change = true;
+ GraphSwitcherButton[] buttons;
public GraphStackSwitcher(Gtk.Stack stack, View[] sub_views)
{
@@ -41,44 +39,29 @@ namespace Usage
new GraphSwitcherButton.memory(_("Memory"))
};
- foreach(Gtk.ToggleButton button in buttons)
+ foreach(GraphSwitcherButton button in buttons)
{
this.pack_start(button, false, true, 0);
- }
-
- buttons[0].set_active (true);
- foreach(Gtk.ToggleButton button in buttons)
- {
- button.toggled.connect (() => {
- if(can_change)
- {
- if (button.active)
- {
- can_change = false;
-
- int i = 0;
- int button_number = 0;
- foreach(Gtk.ToggleButton btn in buttons)
- {
- if(btn != button)
- btn.active = false;
- else
- button_number = i;
- i++;
- }
- this.stack.set_visible_child_name(this.sub_views[button_number].name);
+ button.button_release_event.connect(() => {
+ var button_number = get_button_number(button);
+ this.stack.set_visible_child_name(this.sub_views[button_number].name);
- can_change = true;
- } else
- {
- can_change = false;
- button.active = true;
- can_change = true;
- }
- }
+ return false;
});
}
}
+
+ private int get_button_number(Gtk.Button button)
+ {
+ for(int i = 0; i < buttons.length; i++)
+ {
+ if(buttons[i] == button)
+ return i;
+ }
+
+ return 0;
+ }
+
}
}
diff --git a/src/graph-switcher-button.vala b/src/graph-switcher-button.vala
index c42e1c0..452dc93 100644
--- a/src/graph-switcher-button.vala
+++ b/src/graph-switcher-button.vala
@@ -20,8 +20,10 @@
namespace Usage
{
- public class GraphSwitcherButton : Gtk.ToggleButton
+ public class GraphSwitcherButton : Gtk.RadioButton
{
+ private static Gtk.RadioButton? _group = null;
+
public GraphSwitcherButton.processor(string label)
{
Rg.Graph processor_graph = new CpuGraphMostUsed();
@@ -54,9 +56,18 @@ namespace Usage
return box;
}
- class construct
+ construct
{
- set_css_name("graph-switcher-button");
+ if(_group == null)
+ _group = this;
+ else
+ join_group(_group);
+
+ set_mode(false);
+
+ var context = get_style_context();
+ context.add_class("flat");
+ context.add_class("graph-switcher");
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]