From 668ca65117d84ec0b149e33bfc16825de25e0371 Mon Sep 17 00:00:00 2001 From: Bharat Date: Sat, 8 Jun 2024 17:18:30 +0530 Subject: [PATCH 1/5] demos: Port 'Progress Bar' demo to Vala Add Vala code for Progress Bar --- src/Progress Bar/main.vala | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Progress Bar/main.vala diff --git a/src/Progress Bar/main.vala b/src/Progress Bar/main.vala new file mode 100644 index 00000000..4702f625 --- /dev/null +++ b/src/Progress Bar/main.vala @@ -0,0 +1,67 @@ +#! /usr/bin/env -S vala workbench.vala --pkg libadwaita-1 + +public void main () { + + var first_bar = (Gtk.ProgressBar) workbench.builder.get_object ("first"); + var second_bar = (Gtk.ProgressBar) workbench.builder.get_object ("second"); + var play = (Gtk.Button) workbench.builder.get_object ("play"); + var progress_tracker = (Gtk.Label) workbench.builder.get_object ("progress_tracker"); + + var target = new Adw.PropertyAnimationTarget (first_bar, "fraction"); + + var animation = new Adw.TimedAnimation ( + first_bar, + 0.2, + 1, + 11000, + target + ) { + easing = LINEAR + }; + + animation.done.connect (() => { + animation.reset (); + }); + + play.clicked.connect (() => { + animation.play (); + update_tracker (second_bar); + pulse_progress (progress_tracker); + }); +} + +void update_tracker (Gtk.ProgressBar second_bar) { + double counter = 0.0; + const int pulse_period = 500; + const int duration = 10000; + double increment = (double) pulse_period / duration; + + Timeout.add (pulse_period, () => { + if (counter >= 1.0) { + counter = 0.0; + second_bar.fraction = 0.0; + return false; + } + + second_bar.pulse (); + counter += increment; + return true; + }, Priority.DEFAULT); +} + +void pulse_progress (Gtk.Label progress_tracker) { + + int time = 10; + + Timeout.add (1000, () => { + if (time == 0) { + progress_tracker.set_text (""); + message (@"Operation complete!"); + return false; + } + + progress_tracker.set_text (@"$time seconds remaining…"); + time -= 1; + return true; + }, Priority.DEFAULT); +} From c0e42af0e815e45d415831cc0581e5ba176c277a Mon Sep 17 00:00:00 2001 From: Bharat Date: Sat, 8 Jun 2024 17:20:50 +0530 Subject: [PATCH 2/5] minor spacing changes --- src/Progress Bar/main.vala | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Progress Bar/main.vala b/src/Progress Bar/main.vala index 4702f625..0df093f8 100644 --- a/src/Progress Bar/main.vala +++ b/src/Progress Bar/main.vala @@ -1,7 +1,6 @@ #! /usr/bin/env -S vala workbench.vala --pkg libadwaita-1 public void main () { - var first_bar = (Gtk.ProgressBar) workbench.builder.get_object ("first"); var second_bar = (Gtk.ProgressBar) workbench.builder.get_object ("second"); var play = (Gtk.Button) workbench.builder.get_object ("play"); @@ -50,7 +49,6 @@ void update_tracker (Gtk.ProgressBar second_bar) { } void pulse_progress (Gtk.Label progress_tracker) { - int time = 10; Timeout.add (1000, () => { From 94d349c034ee285227144c71f90983d950328c6a Mon Sep 17 00:00:00 2001 From: Bharat Date: Sun, 9 Jun 2024 12:15:59 +0530 Subject: [PATCH 3/5] Minor Changes Add comments for TimedAnimation parameters Use label property instead of set_text --- src/Progress Bar/main.vala | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Progress Bar/main.vala b/src/Progress Bar/main.vala index 0df093f8..f2d94064 100644 --- a/src/Progress Bar/main.vala +++ b/src/Progress Bar/main.vala @@ -1,6 +1,7 @@ #! /usr/bin/env -S vala workbench.vala --pkg libadwaita-1 public void main () { + var first_bar = (Gtk.ProgressBar) workbench.builder.get_object ("first"); var second_bar = (Gtk.ProgressBar) workbench.builder.get_object ("second"); var play = (Gtk.Button) workbench.builder.get_object ("play"); @@ -8,12 +9,21 @@ public void main () { var target = new Adw.PropertyAnimationTarget (first_bar, "fraction"); - var animation = new Adw.TimedAnimation ( - first_bar, - 0.2, - 1, - 11000, - target + var animation = new Adw.TimedAnimation + /* + * widget + * value_from + * value_to + * duration + * target + */ + ( + first_bar, + 0.2, + 1, + 11000, + target + ) { easing = LINEAR }; @@ -49,16 +59,17 @@ void update_tracker (Gtk.ProgressBar second_bar) { } void pulse_progress (Gtk.Label progress_tracker) { + int time = 10; Timeout.add (1000, () => { if (time == 0) { - progress_tracker.set_text (""); + progress_tracker.label = (""); message (@"Operation complete!"); return false; } - progress_tracker.set_text (@"$time seconds remaining…"); + progress_tracker.label = (@"$time seconds remaining…"); time -= 1; return true; }, Priority.DEFAULT); From d8dff9db4a48273215ec6a5a0c666d5843fe3cf7 Mon Sep 17 00:00:00 2001 From: Bharat Date: Sun, 9 Jun 2024 12:20:59 +0530 Subject: [PATCH 4/5] Change comment style to match others --- src/Progress Bar/main.vala | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Progress Bar/main.vala b/src/Progress Bar/main.vala index f2d94064..c217356a 100644 --- a/src/Progress Bar/main.vala +++ b/src/Progress Bar/main.vala @@ -9,20 +9,12 @@ public void main () { var target = new Adw.PropertyAnimationTarget (first_bar, "fraction"); - var animation = new Adw.TimedAnimation - /* - * widget - * value_from - * value_to - * duration - * target - */ - ( - first_bar, - 0.2, - 1, - 11000, - target + var animation = new Adw.TimedAnimation ( + first_bar, // widget + 0.2, // value_from + 1, // value_to + 11000, // duration + target // target ) { easing = LINEAR From 5d941dddbe634a63710c845c929a68538f58c2dc Mon Sep 17 00:00:00 2001 From: Bharat Date: Sun, 9 Jun 2024 12:25:33 +0530 Subject: [PATCH 5/5] remove extra line --- src/Progress Bar/main.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Progress Bar/main.vala b/src/Progress Bar/main.vala index c217356a..a2245894 100644 --- a/src/Progress Bar/main.vala +++ b/src/Progress Bar/main.vala @@ -15,7 +15,6 @@ public void main () { 1, // value_to 11000, // duration target // target - ) { easing = LINEAR };