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

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
42 changes: 38 additions & 4 deletions lib/Widgets/Toast.vala
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,19 @@ namespace Granite.Widgets {
closed ();
});

notification_label = new Gtk.Label (title);
var close_revealer = new Gtk.Revealer () {
valign = Gtk.Align.START,
halign = Gtk.Align.START,
transition_type = Gtk.RevealerTransitionType.CROSSFADE
};
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 +119,37 @@ 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 () {
above_child = false
};
notification_eventbox.add_events (Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK);
notification_eventbox.add (notification_overlay);

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