Skip to content

Commit

Permalink
Use Granite.Overlaybar (#773)
Browse files Browse the repository at this point in the history
* Use overlaybar style, cleanup

* ZoomOverlay: use overlaybar

* Remove extra styles
  • Loading branch information
danirabbit authored Aug 18, 2024
1 parent 8fabe6c commit 2166ef3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 62 deletions.
10 changes: 6 additions & 4 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
93 changes: 35 additions & 58 deletions src/Widgets/ZoomOverlay.vala
Original file line number Diff line number Diff line change
@@ -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 = "<span face='monospaced' size='24pt' alpha='20000'><b>%.0f%%</b></span>".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);
}

}

}

0 comments on commit 2166ef3

Please sign in to comment.