Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RevealerBox : Gtk.Box {
- public class RevealerBox (Gtk.DirectionType direction) {
- Object (direction: direction);
- }
- Gtk.Revealer revealer;
- Gtk.Image image;
- construct {
- orientation = (direction == Gtk.DirectionType.UP || direction == Gtk.DirectionType.DOWN) ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL;
- image = new Gtk.Image.from_icon_name ("go-next", Gtk.IconSize.BUTTON);
- if (direction == Gtk.DirectionType.UP)
- image.icon_name = "go-up";
- if (direction == Gtk.DirectionType.DOWN)
- image.icon_name = "go-down";
- if (direction == Gtk.DirectionType.LEFT)
- image.icon_name = "go-previous";
- var button = new Gtk.Button();
- button.clicked.connect (() => {
- reveal_child = !reveal_child;
- });
- button.child = image;
- revealer = new Gtk.Revealer();
- if (direction == Gtk.DirectionType.RIGHT || direction == Gtk.DirectionType.DOWN) {
- pack_start (button, false);
- pack_start (revealer);
- } else {
- pack_start (revealer);
- pack_start (button, false);
- }
- }
- void resize_window (bool shown) {
- if (!resize_toplevel)
- return;
- var top = get_toplevel();
- if (!top.get_realized() || !revealer.get_realized())
- return;
- Gtk.Allocation top_allocation;
- Gtk.Allocation child_allocation;
- top.get_allocation (out top_allocation);
- revealer.get_child().get_allocation (out child_allocation);
- if (direction == Gtk.DirectionType.UP || direction == Gtk.DirectionType.DOWN) {
- if (shown) {
- int i;
- revealer.get_child().get_preferred_height_for_width (child_allocation.width, out i, null);
- top_allocation.height += i;
- }
- else
- top_allocation.height -= child_allocation.height;
- }
- else {
- if (shown) {
- int i;
- revealer.get_child().get_preferred_width_for_height (child_allocation.height, out i, null);
- top_allocation.width += i;
- }
- else
- top_allocation.width -= child_allocation.width;
- }
- (top as Gtk.Window).resize (top_allocation.width, top_allocation.height);
- }
- public new Gtk.Widget child {
- owned get {
- return revealer.get_child();
- }
- set {
- revealer.child = value;
- }
- }
- public bool child_revealed {
- get {
- return revealer.child_revealed;
- }
- }
- public Gtk.DirectionType direction { get; construct; }
- public bool resize_toplevel { get; set; }
- public bool reveal_child {
- get {
- return revealer.reveal_child;
- }
- set {
- if (value && direction == Gtk.DirectionType.RIGHT) {
- revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT;
- image.icon_name = "go-previous";
- }
- if (value && direction == Gtk.DirectionType.LEFT) {
- revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT;
- image.icon_name = "go-next";
- }
- if (value && direction == Gtk.DirectionType.UP) {
- revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_UP;
- image.icon_name = "go-down";
- }
- if (value && direction == Gtk.DirectionType.DOWN) {
- revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
- image.icon_name = "go-up";
- }
- if (!value && direction == Gtk.DirectionType.RIGHT) {
- revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT;
- image.icon_name = "go-next";
- }
- if (!value && direction == Gtk.DirectionType.LEFT) {
- revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT;
- image.icon_name = "go-previous";
- }
- if (!value && direction == Gtk.DirectionType.UP) {
- revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN;
- image.icon_name = "go-up";
- }
- if (!value && direction == Gtk.DirectionType.DOWN) {
- revealer.transition_type = Gtk.RevealerTransitionType.SLIDE_UP;
- image.icon_name = "go-down";
- }
- revealer.reveal_child = value;
- revealer.set_child_visible (value);
- queue_resize();
- resize_window (value);
- }
- }
- public uint transition_duration {
- get {
- return revealer.transition_duration;
- }
- set {
- revealer.transition_duration = value;
- }
- }
- }
- public static void main (string[] args) {
- Gtk.init (ref args);
- var win = new Gtk.Window();
- var revealer = new RevealerBox (Gtk.DirectionType.DOWN);
- revealer.resize_toplevel = true;
- revealer.transition_duration = 800;
- revealer.child = new Gtk.Label ("toto");
- revealer.reveal_child = true;
- win.add (revealer);
- win.show_all();
- Gtk.main();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement