Skip to content

Commit

Permalink
EntryPopover/Generic: Gtk4 Prep (#386)
Browse files Browse the repository at this point in the history
* EntryPopover/Generic: Gtk4 Prep

* Don't cache menubutton

* Remove always show image

* Don't use eventbox
  • Loading branch information
danirabbit authored Jun 10, 2024
1 parent d5b10b4 commit 58cfb39
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/Widgets/EntryPopover/Generic.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

public abstract class Tasks.Widgets.EntryPopover.Generic<T> : Gtk.EventBox {
public abstract class Tasks.Widgets.EntryPopover.Generic<T> : Gtk.Box {
public signal string? value_format (T value);
public signal void value_changed (T value);

Expand All @@ -12,9 +12,10 @@ public abstract class Tasks.Widgets.EntryPopover.Generic<T> : Gtk.EventBox {
public string placeholder { get; construct; }
public T value { get; set; }

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 +28,36 @@ 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 (null);

var label = new Gtk.Label (placeholder);

popover = new Gtk.Popover (popover_button);
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,
popover = popover,
image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.BUTTON),
always_show_image = icon_name != null
var popover_button = new Gtk.MenuButton () {
child = popover_button_box,
popover = popover
};
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 +80,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 58cfb39

Please sign in to comment.