Skip to content

Instantly share code, notes, and snippets.

@gavr123456789
Last active July 25, 2024 01:23
Show Gist options
  • Save gavr123456789/04883b80cc942d2957c517231575b10e to your computer and use it in GitHub Desktop.
Save gavr123456789/04883b80cc942d2957c517231575b10e to your computer and use it in GitHub Desktop.
async GTK 3 4 gui example vala nim
using Gtk;
Button button;
void main (string[] args) {
Gtk.init (ref args);
var window = new Window ();
button = new Button.with_label ("Start counting");
button.clicked.connect (() => {
count.begin();
});
with (window){
title = "Count without blocking the UI";
border_width = 10;
window_position = WindowPosition.CENTER;
set_default_size (350, 70);
destroy.connect (Gtk.main_quit);
child = button;
show_all ();
}
Gtk.main ();
}
async void count(){
for(int i = 0; i < 10000; i++){
button.label = i.to_string();
Idle.add (count.callback);
yield;
}
}
@Miqueas
Copy link

Miqueas commented Oct 12, 2021

Love this ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment