Skip to content

Instantly share code, notes, and snippets.

@jonathanballs
Created February 14, 2019 11:55
Show Gist options
  • Save jonathanballs/7697041eedc295b5ebc4af3fc441d146 to your computer and use it in GitHub Desktop.
Save jonathanballs/7697041eedc295b5ebc4af3fc441d146 to your computer and use it in GitHub Desktop.
GtkD tick callbacks
/*
* This file is part of gtkD.
*
* gtkD is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* gtkD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with gtkD; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/
module gtk.HelloWorld;
import std.stdio;
import gio.Application : GioApplication = Application;
import gtk.Application;
import gtk.ApplicationWindow;
import gtk.Label;
import gtk.Widget;
import gdk.FrameClock;
class HelloWorld : ApplicationWindow
{
this(Application application)
{
super(application);
setTitle("GtkD");
setBorderWidth(10);
auto label = new Label("Hello World");
add(label);
// First callback
this.addTickCallback(delegate bool(Widget w, FrameClock f) {
writeln("Callback 1");
return true;
});
// Second callback
this.addTickCallback(delegate bool(Widget w, FrameClock f) {
writeln("Callback 2");
return true;
});
// Callback from a different widget
label.addTickCallback(delegate bool(Widget w, FrameClock f) {
writeln("Callback 3");
return true;
});
// Callback that should only get called once
label.addTickCallback(delegate bool(Widget w, FrameClock f) {
writeln("Callback 4");
return false;
});
showAll();
}
}
int main(string[] args)
{
auto application = new Application("org.gtkd.demo.helloworld", GApplicationFlags.FLAGS_NONE);
application.addOnActivate(delegate void(GioApplication app) { new HelloWorld(application); });
return application.run(args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment