-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port 'Progress Bar' demo to Vala (#168)
- Loading branch information
1 parent
747fa4e
commit 51e5765
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, // widget | ||
0.2, // value_from | ||
1, // value_to | ||
11000, // duration | ||
target // 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.label = (""); | ||
message (@"Operation complete!"); | ||
return false; | ||
} | ||
|
||
progress_tracker.label = (@"$time seconds remaining…"); | ||
time -= 1; | ||
return true; | ||
}, Priority.DEFAULT); | ||
} |