I’m going to be spending a great deal of time contributing to the hxWidgets library by @IanHarrigan1982 but I’m currently having trouble with implementing menus.
In my latest commit, I have been attempting to come up with some way to use the WxMenuItemRef
signature the extern requires without coming across a stupid cannot convert from 'Dynamic' to 'wxMenuItem *'
error.
https://github.com/tienery/hxWidgets-1/commit/05b49280334229585f65dbd1fddb05a445ed96cd
I personally think that the way the extern works is not going in this favour without otherwise writing some C++ in order to get this functionality to work properly.
The way the library is structured is that you create an extern for the object itself, and then another extern for the same object, but as a reference instead. So you have two classes like this:
@:include("wx/frame.h")
@:unreflective
@:native("wxFrame*")
extern class WxFrameRef extends WxFrame {
@:native("new wxFrame") public static function createInstance():WxFrameRef;
}
@:include("wx/frame.h")
@:unreflective
@:native("wxFrame")
extern class WxFrame extends WxWindow {
@:native("Create") public function create(parent:WxWindowRef, id:Int, title:ConstCharStar):Bool;
@:native("CreateStatusBar") public function createStatusBar():Void;
@:native("SetStatusText") public function setStatusText(text:ConstCharStar):Void;
@:native("SetMenuBar") public function setMenuBar(menuBar:WxMenuBarRef):Void;
}
This is of course a very simple implementation of a wrapper which could definitely do with a bit of work, because as I continue working on the menus, I cannot seem to implement a way in which to get the return signature and store it without a compilation error.
extern class WxMenu extends WxEvent {
@:native("Append") public function append(id:Int, item:ConstCharStar, helpString:ConstCharStar):WxMenuItemRef;
@:native("AppendCheckItem") public function appendCheckItem(id:Int, item:ConstCharStar, help:ConstCharStar):WxMenuItemRef;
@:native("AppendRadioItem") public function appendRadioItem(id:Int, item:ConstCharStar, help:ConstCharStar):WxMenuItemRef;
@:native("AppendSeparator") public function appendSeparator():WxMenuItemRef;
@:native("AppendSubMenu") public function appendSubMenu(submenu:WxMenuRef, title:ConstCharStar, help:ConstCharStar):WxMenuItemRef;
I’m at the conundrum where the extern requires the return to be a reference to a MenuItem
, but the way that Haxe works is that any extern use in a generated Haxe class is considered Dynamic until resolved at I believe runtime?