Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port 'Progress Bar' demo to Vala #168

Merged
merged 5 commits into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/Progress Bar/main.vala
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);
}
Loading