Skip to content

Commit

Permalink
EntryPopover/Generic: Gtk4 Prep
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Jun 6, 2024
1 parent d5b10b4 commit dd2faec
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/Widgets/EntryPopover/Generic.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public abstract class Tasks.Widgets.EntryPopover.Generic<T> : Gtk.EventBox {
private Gtk.MenuButton popover_button;
private T value_on_popover_show;

private Gtk.EventControllerMotion motion_controller;

protected Generic (string placeholder, string? icon_name = null) {
Object (
icon_name: icon_name,
Expand All @@ -27,31 +29,37 @@ public abstract class Tasks.Widgets.EntryPopover.Generic<T> : Gtk.EventBox {
}

construct {
events |= Gdk.EventMask.ENTER_NOTIFY_MASK
| Gdk.EventMask.LEAVE_NOTIFY_MASK;

popover = new Gtk.Popover (popover_button);

var label = new Gtk.Label (placeholder);

var popover_button_box = new Gtk.Box (HORIZONTAL, 0);
if (icon_name != null) {
popover_button_box.add (new Gtk.Image.from_icon_name (icon_name, BUTTON));
}
popover_button_box.add (label);

popover_button = new Gtk.MenuButton () {
label = placeholder,
child = popover_button_box,
popover = popover,
image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.BUTTON),
always_show_image = icon_name != null
};
popover_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

var delete_button = new Gtk.Button.from_icon_name ("process-stop-symbolic", Gtk.IconSize.BUTTON) {
label.mnemonic_widget = popover_button;

var delete_button = new Gtk.Button.from_icon_name ("process-stop-symbolic", BUTTON) {
tooltip_text = _("Remove")
};
delete_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);

var delete_button_revealer = new Gtk.Revealer () {
transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT,
child = delete_button,
transition_type = SLIDE_LEFT,
reveal_child = false
};
delete_button_revealer.add (delete_button);

var button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
var button_box = new Gtk.Box (HORIZONTAL, 0);
button_box.add (popover_button);
button_box.add (delete_button_revealer);

Expand All @@ -74,24 +82,28 @@ public abstract class Tasks.Widgets.EntryPopover.Generic<T> : Gtk.EventBox {
notify["value"].connect (() => {
var value_formatted = value_format (value);
if (value_formatted == null) {
popover_button.label = placeholder;
label.label = placeholder;

if (delete_button_revealer.reveal_child) {
delete_button_revealer.reveal_child = false;
}

} else {
popover_button.label = value_formatted;
label.label = value_formatted;
}
});

enter_notify_event.connect (() => {
motion_controller = new Gtk.EventControllerMotion (this) {
propagation_phase = CAPTURE
};

motion_controller.enter.connect (() => {
if (value_format (value) != null) {
delete_button_revealer.reveal_child = true;
}
});

leave_notify_event.connect (() => {
motion_controller.leave.connect (() => {
if (delete_button_revealer.reveal_child) {
delete_button_revealer.reveal_child = false;
}
Expand Down

0 comments on commit dd2faec

Please sign in to comment.