Skip to content

Commit

Permalink
refactor: MainWindow: Use more specified variable name and lessen sco…
Browse files Browse the repository at this point in the history
…pe (#76)
  • Loading branch information
ryonakano authored Jun 15, 2024
1 parent 3810674 commit eeb1695
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class MainWindow : Gtk.ApplicationWindow {
private const string CSS_DATA = """
.result-text {
.magnified-text {
font-size: 128px;
font-weight: bold;
}
Expand All @@ -16,7 +16,6 @@ public class MainWindow : Gtk.ApplicationWindow {
private Gdk.Surface surface;

private bool is_label_updated = false;
private Gtk.Label result_label;

construct {
// Get the area where we can draw the app window
Expand All @@ -41,7 +40,7 @@ public class MainWindow : Gtk.ApplicationWindow {
title_bar.add_css_class (Granite.STYLE_CLASS_FLAT);
titlebar = title_bar;

result_label = new Gtk.Label (null) {
var magnified_label = new Gtk.Label (null) {
selectable = true,
margin_top = 24,
margin_bottom = 24,
Expand All @@ -50,10 +49,10 @@ public class MainWindow : Gtk.ApplicationWindow {
wrap = true,
wrap_mode = Pango.WrapMode.WORD_CHAR
};
result_label.add_css_class ("result-text");
magnified_label.add_css_class ("magnified-text");

var main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
main_box.append (result_label);
main_box.append (magnified_label);

child = main_box;

Expand All @@ -77,7 +76,7 @@ public class MainWindow : Gtk.ApplicationWindow {
// NOTE: The reason to update the label after the window get focused is that
// getting clipboard content is not allowed until that happens on Wayland.
// See https://gitlab.gnome.org/GNOME/gtk/-/issues/1874#note_509304
update_result_label.begin ();
update_label_text.begin (magnified_label);
});

// Follow elementary OS-wide dark preference
Expand All @@ -91,13 +90,13 @@ public class MainWindow : Gtk.ApplicationWindow {
});
}

private async void update_result_label () {
private async void update_label_text (Gtk.Label label_widget) {
if (Application.text != null) {
// Set the text passed by the command line option if specified
result_label.label = Application.text;
label_widget.label = Application.text;
} else {
// Otherwise set the text loaded from clipboard
result_label.label = yield load_clipboard ();
label_widget.label = yield load_clipboard ();
}
}

Expand Down

0 comments on commit eeb1695

Please sign in to comment.