On Sun, 6 Jan 2019 19:16:17 +0100, Mike Wey wrote:
addOnButtonRelease(delegate bool(Event e, Widget w){ buttonAction(args); return false; } );
I don't think the type inference works when both overloads have the same
amount of arguments.The bool the function returns determines whether Gtk+ continues running
the other registered handlers or not.true
if you handled the event
and Gtk should stop orfalse
to let Gtk continue.
Thanks, Mike. That did the trick. The final code:
import std.stdio;
import gtk.MainWindow;
import gtk.Main;
import gtk.Widget;
import gtk.Button;
import gdk.Event;
void main(string[] args)
{
// initialization & creation
Main.init(args);
TestRigWindow myTestRig = new TestRigWindow("Test Rig OOP - Pass Args", args);
// Show the window and its contents...
myTestRig.showAll();
// give control over to gtkD
Main.run();
} // main()
class TestRigWindow : MainWindow
{
this(string title, string[] args)
{
// window
super(title);
addOnDestroy(delegate void(Widget w) { quitApp(); } );
// pass command line args to the button constructor
MyArgsButton myButton = new MyArgsButton("Show Args", args);
add(myButton);
// Show the window and its contents...
showAll();
} // this()
void quitApp()
{
// This exists in case we want to do anything
// before exiting such as warn the user to
// save work.
writeln("Bye.");
Main.quit();
} // quitApp()
} // class TestRigWindow
class MyArgsButton : Button
{
// string[] buttonArgs;
this(string labelText, string[] args)
{
super(labelText);
// addOnButtonRelease(&onButtonRelease);
addOnButtonRelease(delegate bool(Event e, Widget w){ buttonAction(args); return false; } );
// buttonArgs = args;
} // this()
// public bool buttonAction(Event event, Widget widget, string[] buttonArgs)
public bool buttonAction(string[] buttonArgs)
{
writeln("got this bar.");
foreach(arg; buttonArgs)
{
writeln("arg: ", arg);
}
return(true);
} // buttonAction()
} // class MyArgsButton
Something I noticed...
Running this from the bash shell (the version included with git 2.20 from git-scm.com) nothing gets written to the shell window until I exit, but with the standard Windows command prompt, it's written out as soon as I release the button.
I didn't expect that.