Unverified Commit cf7fcaee authored by Gabriele Musco's avatar Gabriele Musco Committed by GitHub

feat: new buttons-per-row property for buttons-grid widget (#576)

parent a831118a
...@@ -471,6 +471,8 @@ config file to be able to detect config errors ...@@ -471,6 +471,8 @@ config file to be able to detect config errors
type: object ++ type: object ++
css class: widget-buttons (access buttons with >flowbox>flowboxchild>button) ++ css class: widget-buttons (access buttons with >flowbox>flowboxchild>button) ++
properties: ++ properties: ++
buttons-per-row: ++
type: number ++
actions: ++ actions: ++
type: array ++ type: array ++
Default values: [] ++ Default values: [] ++
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
"loop-carousel": false "loop-carousel": false
}, },
"buttons-grid": { "buttons-grid": {
"buttons-per-row": 7,
"actions": [ "actions": [
{ {
"label": "直", "label": "直",
......
...@@ -434,6 +434,10 @@ ...@@ -434,6 +434,10 @@
"description": "A widget to add a grid of buttons that execute shell commands", "description": "A widget to add a grid of buttons that execute shell commands",
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"buttons-per-row": {
"type": "number",
"description": "How many buttons should be shown in a buttons-grid row"
},
"actions": { "actions": {
"type": "array", "type": "array",
"description": "A list of actions containing a label and a command", "description": "A list of actions containing a label and a command",
......
...@@ -10,6 +10,8 @@ namespace SwayNotificationCenter.Widgets { ...@@ -10,6 +10,8 @@ namespace SwayNotificationCenter.Widgets {
} }
Action[] actions; Action[] actions;
// 7 is the default Gtk.FlowBox.max_children_per_line
int buttons_per_row = 7;
List<ToggleButton> toggle_buttons; List<ToggleButton> toggle_buttons;
public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) { public ButtonsGrid (string suffix, SwayncDaemon swaync_daemon, NotiDaemon noti_daemon) {
...@@ -19,9 +21,14 @@ namespace SwayNotificationCenter.Widgets { ...@@ -19,9 +21,14 @@ namespace SwayNotificationCenter.Widgets {
if (config != null) { if (config != null) {
Json.Array a = get_prop_array (config, "actions"); Json.Array a = get_prop_array (config, "actions");
if (a != null) actions = parse_actions (a); if (a != null) actions = parse_actions (a);
bool bpr_found = false;
int bpr = get_prop<int> (config, "buttons-per-row", out bpr_found);
if (bpr_found) buttons_per_row = bpr;
} }
Gtk.FlowBox container = new Gtk.FlowBox (); Gtk.FlowBox container = new Gtk.FlowBox ();
container.set_max_children_per_line (buttons_per_row);
container.set_selection_mode (Gtk.SelectionMode.NONE); container.set_selection_mode (Gtk.SelectionMode.NONE);
container.set_hexpand (true); container.set_hexpand (true);
append (container); append (container);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment