1 /**
2 Dplug's wren bridge.
3 4 Copyright: Guillaume Piolat 2021.
5 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6 */7 moduledplug.wren;
8 9 importdplug.core.nogc;
10 importdplug.gui.context;
11 importdplug.gui.element;
12 13 nothrow:
14 15 16 publicimportdplug.wren.wrensupport;
17 18 /// Create wren support for this UI tree, puts it in UIContext under pimpl idiom.19 /// Returns the Wren support object.20 /// Call this in your gui.d this.21 voidenableWrenSupport(IUIContextcontext) @nogc22 {
23 WrenSupportw = mallocNew!WrenSupport(context);
24 context.setUserPointer(UICONTEXT_POINTERID_WREN_SUPPORT, cast(void*)w);
25 }
26 27 /// Disable wren support, meaning it will release the Wren VM and integration.28 /// Call this in your gui.d ~this.29 voiddisableWrenSupport(IUIContextcontext) @nogc30 {
31 WrenSupportw = wrenSupport(context);
32 context.setUserPointer(UICONTEXT_POINTERID_WREN_SUPPORT, null);
33 destroyFree(w);
34 }
35 36 /// Get the `WrenSupport` object that holds all wren state and integration with the plugin.37 /// The rest of the public API follows in dplug.wren.wrensupport38 WrenSupportwrenSupport(IUIContextcontext) @nogc39 {
40 returncast(WrenSupport) context.getUserPointer(UICONTEXT_POINTERID_WREN_SUPPORT);
41 }
42 43 /// All widgets (derivatives of UIElement) have a string ID.44 /// mixin this code to automatically set widgets ID. 45 /// It generates 46 /// _member.id = "_member";47 /// for every field that is @ScriptExport, in order to find them from Wren.48 ///49 /// Example:50 /// ---51 /// mixin(fieldIdentifiersAreIDs!MyPluginGUI);52 /// ---53 stringfieldIdentifiersAreIDs(T)()
54 {
55 importstd.traits: getSymbolsByUDA;
56 strings;
57 staticforeach(m; getSymbolsByUDA!(T, ScriptExport))
58 {{
59 stringfieldName = m.stringof;
60 s ~= "if(" ~ fieldName ~ ")" ~ fieldName ~ ".id = \"" ~ fieldName ~ "\";\n";
61 }}
62 returns;
63 }