digitalmars.D.learn - How do you draw in gtkD? Simple example overriding Widget.draw()
- Enjoys Math (22/22) Jan 26 2016 import gtk.MainWindow;
- Enjoys Math (3/25) Jan 26 2016 Oh i see, there are examples under the GDk directory under
- Gerald (4/4) Jan 26 2016 Generally don't override methods in GtkD, use event handlers like
import gtk.MainWindow;
import gtk.Main;
import gtk.DrawingArea;
import cairo.Context;
import std.stdio;
void main(string[] args) {
Main.init(args);
auto win = new MainWindow("Hello World");
win.setDefaultSize(200, 100);
win.add(new MyDrawingArea());
win.showAll();
Main.run();
}
class MyDrawingArea : DrawingArea {
override bool draw(Context cairo) {
writeln("Hello");
return true;
}
}
Error:
Error: function main.MyDrawingArea.draw does not override any
function, did you mean to override 'gtk.Widget.Widget.draw'?
Jan 26 2016
On Wednesday, 27 January 2016 at 01:54:53 UTC, Enjoys Math wrote:
import gtk.MainWindow;
import gtk.Main;
import gtk.DrawingArea;
import cairo.Context;
import std.stdio;
void main(string[] args) {
Main.init(args);
auto win = new MainWindow("Hello World");
win.setDefaultSize(200, 100);
win.add(new MyDrawingArea());
win.showAll();
Main.run();
}
class MyDrawingArea : DrawingArea {
override bool draw(Context cairo) {
writeln("Hello");
return true;
}
}
Error:
Error: function main.MyDrawingArea.draw does not override any
function, did you mean to override 'gtk.Widget.Widget.draw'?
Oh i see, there are examples under the GDk directory under
'demos'.
Jan 26 2016
Generally don't override methods in GtkD, use event handlers like addOnDraw. Because GtkD wraps GTK functions an overriden D method of GtkD will never get called by GTK since it is working with the underlying C functions directly.
Jan 26 2016








Gerald <gerald.b.nunn gmail.com>