From 2166ef3b09317004661349e3092eb2df760e6729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 18 Aug 2024 03:21:44 -0700 Subject: [PATCH] Use Granite.Overlaybar (#773) * Use overlaybar style, cleanup * ZoomOverlay: use overlaybar * Remove extra styles --- src/MainWindow.vala | 10 ++-- src/Widgets/ZoomOverlay.vala | 93 ++++++++++++++---------------------- 2 files changed, 41 insertions(+), 62 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 3d022bac68..25edf93d64 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -383,13 +383,15 @@ namespace Terminal { term.grab_focus (); }); - zoom_overlay = new Widgets.ZoomOverlay (); - zoom_overlay.add_overlay_child (notebook); + var overlay = new Gtk.Overlay () { + child = notebook + }; + + zoom_overlay = new Widgets.ZoomOverlay (overlay); var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); box.add (header); - box.add (zoom_overlay); - // box.add (notebook); + box.add (overlay); add (box); get_style_context ().add_class ("terminal-window"); diff --git a/src/Widgets/ZoomOverlay.vala b/src/Widgets/ZoomOverlay.vala index 952e0ee8d0..b4ea2d6d79 100644 --- a/src/Widgets/ZoomOverlay.vala +++ b/src/Widgets/ZoomOverlay.vala @@ -1,67 +1,44 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io) + */ + +public class Terminal.Widgets.ZoomOverlay : Granite.Widgets.OverlayBar { + private int visible_duration; + private uint timer_id; + private bool will_hide; + + public ZoomOverlay (Gtk.Overlay overlay) { + base (overlay); + } -namespace Terminal.Widgets { - - public class ZoomOverlay : Gtk.Bin { - private Gtk.Overlay overlay; - private Gtk.Revealer revealer; - private Gtk.Label zoom_label; - private int visible_duration; - private uint timer_id; - private bool will_hide; - - construct { - overlay = new Gtk.Overlay (); - - revealer = new Gtk.Revealer () { - hexpand = false, - vexpand = false, - halign = Gtk.Align.CENTER, - valign = Gtk.Align.CENTER, - transition_type = Gtk.RevealerTransitionType.CROSSFADE - }; - - zoom_label = new Gtk.Label ("") { - use_markup = true - }; - - revealer.add (zoom_label); - overlay.add_overlay (revealer); - overlay.set_overlay_pass_through (revealer, true); - - visible_duration = 1500; - will_hide = false; + construct { + visible_duration = 1500; + will_hide = false; + } - add (overlay); - show_all (); - } + public void show_zoom_level (double zoom_level) { + label = _("Zoom: %.0f%%").printf (zoom_level * 100); + show (); - public void add_overlay_child (Gtk.Widget child) { - overlay.add (child); + if (will_hide) { + GLib.Source.remove (timer_id); } - public void show_zoom_level (double zoom_level) { - revealer.reveal_child = true; - zoom_label.label = "%.0f%%".printf (zoom_level * 100); - - if (will_hide) { - GLib.Source.remove (timer_id); - } - - will_hide = true; - timer_id = GLib.Timeout.add (visible_duration, () => { - revealer.reveal_child = false; - will_hide = false; - return false; - }); - } + will_hide = true; + timer_id = GLib.Timeout.add (visible_duration, () => { + hide (); + will_hide = false; + return false; + }); + } - public void hide_zoom_level () { - revealer.reveal_child = false; - if (will_hide) { - will_hide = false; - GLib.Source.remove (timer_id); - } + public void hide_zoom_level () { + hide (); + if (will_hide) { + will_hide = false; + GLib.Source.remove (timer_id); } - } + }