Menu animation (#230)
This commit is contained in:
@@ -314,6 +314,17 @@ config file to be able to detect config errors
|
|||||||
default: "right" ++
|
default: "right" ++
|
||||||
description: Horizontal position of the button in the bar ++
|
description: Horizontal position of the button in the bar ++
|
||||||
enum: ["right", "left"] ++
|
enum: ["right", "left"] ++
|
||||||
|
animation_type: ++
|
||||||
|
type: string ++
|
||||||
|
optional: true ++
|
||||||
|
default: "slide_down" ++
|
||||||
|
description: Animation type for menu++
|
||||||
|
enum: ["slide_down", "slide_up", "none"] ++
|
||||||
|
animation_duration: ++
|
||||||
|
type: integer ++
|
||||||
|
optional: true ++
|
||||||
|
default: 250 ++
|
||||||
|
description: Duration of animation in milliseconds ++
|
||||||
actions: ++
|
actions: ++
|
||||||
type: array ++
|
type: array ++
|
||||||
Default values: [] ++
|
Default values: [] ++
|
||||||
|
@@ -423,6 +423,17 @@
|
|||||||
"default": "right",
|
"default": "right",
|
||||||
"enum": ["right", "left"]
|
"enum": ["right", "left"]
|
||||||
},
|
},
|
||||||
|
"animation_type": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "slide_down",
|
||||||
|
"description": "Animation type for menu",
|
||||||
|
"enum": ["slide_down", "slide_up", "none"]
|
||||||
|
},
|
||||||
|
"animation_duration":{
|
||||||
|
"type": "integer",
|
||||||
|
"default": 250,
|
||||||
|
"description": "Duration of animation in milliseconds"
|
||||||
|
},
|
||||||
"actions": {
|
"actions": {
|
||||||
"$ref" : "#/widgets/buttons-grid/properties/actions"
|
"$ref" : "#/widgets/buttons-grid/properties/actions"
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,9 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
string ? label;
|
string ? label;
|
||||||
Position ? position;
|
Position ? position;
|
||||||
Action[] actions;
|
Action[] actions;
|
||||||
Gtk.Box ? menu;
|
Gtk.Revealer ? revealer;
|
||||||
|
int animation_duration;
|
||||||
|
Gtk.RevealerTransitionType animation_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct Action {
|
public struct Action {
|
||||||
@@ -61,7 +63,7 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
show_all ();
|
show_all ();
|
||||||
|
|
||||||
foreach (var obj in menu_objects) {
|
foreach (var obj in menu_objects) {
|
||||||
obj.menu ?.hide ();
|
obj.revealer ?.set_reveal_child (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +71,7 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
switch (obj.type) {
|
switch (obj.type) {
|
||||||
case MenuType.BUTTONS:
|
case MenuType.BUTTONS:
|
||||||
Gtk.Box container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
|
Gtk.Box container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
|
||||||
container.get_style_context ().add_class (obj.name);
|
if (obj.name != null) container.get_style_context ().add_class (obj.name);
|
||||||
|
|
||||||
foreach (Action a in obj.actions) {
|
foreach (Action a in obj.actions) {
|
||||||
Gtk.Button b = new Gtk.Button.with_label (a.label);
|
Gtk.Button b = new Gtk.Button.with_label (a.label);
|
||||||
@@ -91,16 +93,21 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
Gtk.Button show_button = new Gtk.Button.with_label (obj.label);
|
Gtk.Button show_button = new Gtk.Button.with_label (obj.label);
|
||||||
|
|
||||||
Gtk.Box menu = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
|
Gtk.Box menu = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
|
||||||
menu.get_style_context ().add_class (obj.name);
|
if (obj.name != null) menu.get_style_context ().add_class (obj.name);
|
||||||
obj.menu = menu;
|
|
||||||
|
Gtk.Revealer r = new Gtk.Revealer ();
|
||||||
|
r.add (menu);
|
||||||
|
r.set_transition_duration (obj.animation_duration);
|
||||||
|
r.set_transition_type (obj.animation_type);
|
||||||
|
obj.revealer = r;
|
||||||
|
|
||||||
show_button.clicked.connect (() => {
|
show_button.clicked.connect (() => {
|
||||||
bool visible = !menu.visible;
|
bool visible = !r.get_reveal_child ();
|
||||||
foreach (var o in menu_objects) {
|
foreach (var o in menu_objects) {
|
||||||
o.menu ?.set_visible (false);
|
o.revealer ?.set_reveal_child (false);
|
||||||
}
|
}
|
||||||
menu.set_visible (visible);
|
r.set_reveal_child (visible);
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (var a in obj.actions) {
|
foreach (var a in obj.actions) {
|
||||||
Gtk.Button b = new Gtk.Button.with_label (a.label);
|
Gtk.Button b = new Gtk.Button.with_label (a.label);
|
||||||
@@ -117,7 +124,7 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
menus_container.add (menu);
|
menus_container.add (r);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,6 +167,30 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
info ("No label for menu-object given using default");
|
info ("No label for menu-object given using default");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int duration = int.max (0, get_prop<int> (obj, "animation_duration"));
|
||||||
|
if (duration == 0) duration = 250;
|
||||||
|
|
||||||
|
string ? animation_type = get_prop<string> (obj, "animation_type");
|
||||||
|
if (animation_type == null) {
|
||||||
|
animation_type = "slide_down";
|
||||||
|
info ("No animation-type for menu-object given using default");
|
||||||
|
}
|
||||||
|
|
||||||
|
Gtk.RevealerTransitionType revealer_type;
|
||||||
|
|
||||||
|
switch (animation_type) {
|
||||||
|
default:
|
||||||
|
case "none":
|
||||||
|
revealer_type = Gtk.RevealerTransitionType.NONE;
|
||||||
|
break;
|
||||||
|
case "slide_up":
|
||||||
|
revealer_type = Gtk.RevealerTransitionType.SLIDE_UP;
|
||||||
|
break;
|
||||||
|
case "slide_down":
|
||||||
|
revealer_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Action[] actions_list = parse_actions (actions);
|
Action[] actions_list = parse_actions (actions);
|
||||||
menu_objects.append (ConfigObject () {
|
menu_objects.append (ConfigObject () {
|
||||||
name = name,
|
name = name,
|
||||||
@@ -167,7 +198,9 @@ namespace SwayNotificationCenter.Widgets {
|
|||||||
label = label,
|
label = label,
|
||||||
position = pos,
|
position = pos,
|
||||||
actions = actions_list,
|
actions = actions_list,
|
||||||
menu = null,
|
revealer = null,
|
||||||
|
animation_duration = duration,
|
||||||
|
animation_type = revealer_type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user