File tree Expand file tree Collapse file tree
src/Library/demos/Progress Bar Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using Gtk 4.0;
2+ using Adw 1;
3+
4+ Adw.StatusPage {
5+ title: "Progress Bar";
6+ description: _("Display the progress of a long running operation");
7+
8+ Box {
9+ orientation: vertical;
10+ halign: center;
11+
12+ ProgressBar first {
13+ fraction: 0.2;
14+ show-text: true;
15+ margin-bottom: 24;
16+ }
17+
18+ ProgressBar second {
19+ inverted: true;
20+ pulse-step: 0.25;
21+ show-text: true;
22+ text: "";
23+ margin-bottom: 24;
24+ }
25+
26+ Label progress_tracker {
27+ label: "";
28+ margin-bottom: 12;
29+ }
30+
31+ Button play {
32+ halign: center;
33+ margin-bottom: 24;
34+ icon-name: "media-playback-start-symbolic";
35+ }
36+
37+ LinkButton {
38+ label: "API Reference";
39+ uri: "https://docs.gtk.org/gtk4/class.ProgressBar.html";
40+ }
41+
42+ LinkButton{
43+ label: "Human Interface Guidelines";
44+ uri: "https://developer.gnome.org/hig/patterns/feedback/progress-bars.html";
45+ }
46+ }
47+ }
48+
Original file line number Diff line number Diff line change 1+ const first_bar = workbench . builder . get_object ( "first" ) ;
2+ const second_bar = workbench . builder . get_object ( "second" ) ;
3+ const play = workbench . builder . get_object ( "play" ) ;
4+ const progress_tracker = workbench . builder . get_object ( "progress_tracker" ) ;
5+
6+ function handleProgress ( ) {
7+ //Counters for respective progress bars and for progress tracker label
8+ let counter = 0.3 ;
9+ let counter_two = 0.25 ;
10+ let timeLeft = 12 ;
11+
12+ //Display a Countdown
13+ const countdownInterval = setInterval ( ( ) => {
14+ timeLeft -- ;
15+ if ( timeLeft === 0 ) {
16+ clearInterval ( countdownInterval ) ;
17+ progress_tracker . label = "" ;
18+ console . log ( "Operation Complete!" ) ;
19+ } else {
20+ progress_tracker . label = `${ timeLeft } seconds remaining ...` ;
21+ }
22+ } , 1000 ) ;
23+
24+ //Advance the first progress bar by 0.1 value every 1.5 seconds
25+ const intervalId_one = setInterval ( ( ) => {
26+ first_bar . set_fraction ( counter ) ;
27+ counter += 0.1 ;
28+ if ( counter > 1.0 ) {
29+ clearInterval ( intervalId_one ) ;
30+ first_bar . set_fraction ( ( counter = 0.2 ) ) ;
31+ }
32+ } , 1500 ) ;
33+
34+ //Advance the second progress bar by 0.25 value every 3 seconds
35+ const intervalId_second = setInterval ( ( ) => {
36+ second_bar . pulse ( ) ;
37+ second_bar . set_fraction ( counter_two ) ;
38+ counter_two += 0.25 ;
39+ if ( counter_two > 1.0 ) {
40+ clearInterval ( intervalId_second ) ;
41+ second_bar . set_fraction ( ( counter_two = 0 ) ) ;
42+ }
43+ } , 3000 ) ;
44+ }
45+
46+ play . connect ( "clicked" , handleProgress ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " Progress Bar" ,
3+ "category" : " user_interface" ,
4+ "description" : " Display the progress of a long running operation" ,
5+ "panels" : [
6+ " ui" ,
7+ " preview"
8+ ],
9+ "autorun" : true
10+ }
You can’t perform that action at this time.
0 commit comments