Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toasts: Overlay close button on corner #480

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
40 changes: 36 additions & 4 deletions lib/Widgets/Toast.vala
Expand Up @@ -90,11 +90,18 @@ namespace Granite.Widgets {
closed ();
});

notification_label = new Gtk.Label (title);
var close_revealer = new Gtk.Revealer ();
close_revealer.valign = Gtk.Align.START;
close_revealer.halign = Gtk.Align.START;
close_revealer.transition_type = Gtk.RevealerTransitionType.CROSSFADE;
alainm23 marked this conversation as resolved.
Show resolved Hide resolved
close_revealer.add (close_button);

notification_label = new Gtk.Label (title) {
margin_start = 3
};

var notification_box = new Gtk.Grid ();
notification_box.column_spacing = 12;
notification_box.add (close_button);
notification_box.add (notification_label);
notification_box.add (default_action_button);

Expand All @@ -111,11 +118,36 @@ namespace Granite.Widgets {
start_timeout ();
});

var notification_frame = new Gtk.Frame (null);
var notification_frame = new Gtk.Frame (null) {
margin = 6
};
notification_frame.get_style_context ().add_class ("app-notification");
notification_frame.add (event_box);

add (notification_frame);
var notification_overlay = new Gtk.Overlay ();
notification_overlay.add_overlay (close_revealer);
notification_overlay.add (notification_frame);

var notification_eventbox = new Gtk.EventBox ();
notification_eventbox.add_events (Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK);
notification_eventbox.above_child = false;
notification_eventbox.add (notification_overlay);
alainm23 marked this conversation as resolved.
Show resolved Hide resolved

notification_eventbox.enter_notify_event.connect ((event) => {
close_revealer.reveal_child = true;
return true;
});

notification_eventbox.leave_notify_event.connect ((event) => {
if (event.detail == Gdk.NotifyType.INFERIOR) {
return false;
}

close_revealer.reveal_child = false;
return true;
});

add (notification_eventbox);
}

private void start_timeout () {
Expand Down