From 5d0c84d7483ef94962d0332184a8333b4038430f Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Mon, 20 Apr 2026 09:00:28 +0900 Subject: [PATCH] introduce early props --- examples/vkdemos/vulkan.c | 6 ++--- include/Mw/StringDefs.h | 3 +++ include/Mw/Widget/Vulkan.h | 12 ---------- milsko.xml | 7 ++++++ src/core.c | 46 ++++++++++++++++++++++++++++---------- src/widget/vulkan.c | 33 +++++++++++++-------------- 6 files changed, 62 insertions(+), 45 deletions(-) diff --git a/examples/vkdemos/vulkan.c b/examples/vkdemos/vulkan.c index 7e20a5b..f5faa9b 100644 --- a/examples/vkdemos/vulkan.c +++ b/examples/vkdemos/vulkan.c @@ -624,9 +624,9 @@ int main() { MwNtitle, "hello world", NULL); - MwVulkanEnableExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME); - - vulkan = MwCreateWidget(MwVulkanClass, "vulkan", window, 50, 50, ow, oh); + vulkan = MwVaCreateWidget(MwVulkanClass, "vulkan", window, 50, 50, ow, oh, + MwNvulkanExtension, VK_KHR_SWAPCHAIN_EXTENSION_NAME, + NULL); MwAddUserHandler(window, MwNtickHandler, tick, NULL); diff --git a/include/Mw/StringDefs.h b/include/Mw/StringDefs.h index c657a63..394cb9e 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -51,6 +51,9 @@ #define MwNforeground "Sforeground" #define MwNsubForeground "SsubForeground" +#define MwNvulkanExtension "SEvulkanExtension" +#define MwNvulkanLayer "SEvulkanLayer" + #define MwNpixmap "Vpixmap" #define MwNiconPixmap "ViconPixmap" #define MwNsizeHints "VsizeHints" diff --git a/include/Mw/Widget/Vulkan.h b/include/Mw/Widget/Vulkan.h index 0b7db3a..255c8d3 100644 --- a/include/Mw/Widget/Vulkan.h +++ b/include/Mw/Widget/Vulkan.h @@ -33,18 +33,6 @@ extern "C" { */ MWDECL MwClass MwVulkanClass; -/*! - * @brief Add an extension to the list of extensions to enable prior to initialization. - * @warning This must be called before MwCreateWidget. - */ -MWDECL void MwVulkanEnableExtension(const char* ext_name); - -/*! - * @brief Add an layer to the list of layers to enable prior to initialization. - * @warning This must be called before MwCreateWidget. - */ -MWDECL void MwVulkanEnableLayer(const char* ext_name); - /*! * @brief Configuration options that can be passed to setup Vulkan before a widget is created. */ diff --git a/milsko.xml b/milsko.xml index 8783710..b69e8b7 100644 --- a/milsko.xml +++ b/milsko.xml @@ -55,6 +55,9 @@ String properties must be prefixed with S. Handler properties must be prefixed with C. Other properties must be prefixed with V. + + "Early" properties must have letter "E" as 2nd letter. + e.g. vulkanExtension would be SEvulkanExtension --> @@ -104,6 +107,10 @@ + + + + diff --git a/src/core.c b/src/core.c index 758e86a..dddf25b 100644 --- a/src/core.c +++ b/src/core.c @@ -18,6 +18,9 @@ MwLLEndDraw(handle->lowlevel); \ } +static void MwVaListApply_Internal(MwWidget handle, va_list va, int only_early); +static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, int do_prop, va_list prop); + static void lldrawhandler(MwLL handle, void* data) { MwWidget h = (MwWidget)handle->common.user; #ifdef PERIODIC @@ -177,7 +180,7 @@ static void lldarkthemehandler(MwLL handle, void* data) { } } -MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) { +static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, int do_prop, va_list prop) { MwWidget h = malloc(sizeof(*h)); h->name = MwStringDuplicate(name); @@ -194,17 +197,17 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, } else { h->lowlevel = NULL; } - h->widget_class = widget_class; - h->pressed = 0; - h->close = 0; - h->destroy_queue = NULL; - h->prop_event = 1; - h->draw_inject = NULL; + h->widget_class = widget_class; + h->pressed = 0; + h->close = 0; + h->destroy_queue = NULL; + h->prop_event = 1; + h->draw_inject = NULL; h->destroy_inject = NULL; - h->tick_list = NULL; - h->destroyed = 0; - h->bgcolor = NULL; - h->berserk = 0; + h->tick_list = NULL; + h->destroyed = 0; + h->bgcolor = NULL; + h->berserk = 0; h->top_step = 0; h->draw_queue = NULL; @@ -243,6 +246,8 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, shdefault(h->handler, NULL); shdefault(h->data, NULL); + if(do_prop) MwVaListApply_Internal(h, prop, 1); + h->prop_event = 0; if(MwDispatch2(h, create) != 0) { h->widget_class = NULL; @@ -276,6 +281,12 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, return h; } +MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height) { + va_list dummy; + + return MwCreateWidget_Internal(widget_class, name, parent, x, y, width, height, 0, dummy); +} + MwWidget MwVaCreateWidget(MwClass widget_class, const char* name, MwWidget parent, int x, int y, unsigned int width, unsigned int height, ...) { MwWidget h; va_list va; @@ -704,13 +715,15 @@ void MwVaApply(MwWidget handle, ...) { va_end(va); } -void MwVaListApply(MwWidget handle, va_list va) { +static void MwVaListApply_Internal(MwWidget handle, va_list va, int only_early) { char* key; int x = MwDEFAULT, y = MwDEFAULT, w = MwDEFAULT, h = MwDEFAULT; while((key = va_arg(va, char*)) != NULL) { if(key[0] == 'I') { int n = va_arg(va, int); + if(only_early && key[1] != 'E') continue; + if(strcmp(key, MwNx) == 0) { x = n; } else if(strcmp(key, MwNy) == 0) { @@ -724,12 +737,17 @@ void MwVaListApply(MwWidget handle, va_list va) { } } else if(key[0] == 'S') { char* t = va_arg(va, char*); + if(only_early && key[1] != 'E') continue; + MwSetText(handle, key, t); } else if(key[0] == 'C') { MwUserHandler h = va_arg(va, MwUserHandler); + if(only_early && key[1] != 'E') continue; + MwAddUserHandler(handle, key, h, NULL); } else if(key[0] == 'V') { void* v = va_arg(va, void*); + if(only_early && key[1] != 'E') continue; MwSetVoid(handle, key, v); } } @@ -761,6 +779,10 @@ void MwVaListApply(MwWidget handle, va_list va) { } } +void MwVaListApply(MwWidget handle, va_list va) { + MwVaListApply_Internal(handle, va, 0); +} + void MwSetDefault(MwWidget handle) { if(handle->lowlevel != NULL) MwLLSetCursor(handle->lowlevel, &MwCursorDefault, &MwCursorDefaultMask); } diff --git a/src/widget/vulkan.c b/src/widget/vulkan.c index bc0e1bb..32ae20a 100644 --- a/src/widget/vulkan.c +++ b/src/widget/vulkan.c @@ -493,14 +493,6 @@ void MwVulkanConfigure(MwVulkanConfig* cfg) { vulkan_config = *cfg; } -void MwVulkanEnableExtension(const char* name) { - arrput(enabledExtensions, name); -} - -void MwVulkanEnableLayer(const char* name) { - arrput(enabledLayers, name); -} - int MwVulkanSupported(void) { if(vulkan_supported == VULKAN_SUPPORTED_UNKNOWN) { void* lib = vulkan_lib_load(); @@ -552,7 +544,20 @@ static void* mwVulkanGetFieldImpl(MwWidget handle, int field, int* err) { if(err != NULL) { *err = 0; } -}; +} + +static void prop_change(MwWidget handle, const char* prop) { + /* TODO: make this local to widgets, not global */ + if(strcmp(prop, MwNvulkanExtension) == 0) { + char* str = MwStringDuplicate(MwGetText(handle, MwNvulkanExtension)); + + arrput(enabledExtensions, str); + } else if(strcmp(prop, MwNvulkanLayer) == 0) { + char* str = MwStringDuplicate(MwGetText(handle, MwNvulkanExtension)); + + arrput(enabledLayers, str); + } +} static void func_handler(MwWidget handle, const char* name, void* output, va_list va) { if(strcmp(name, "mwVulkanGetField") == 0) { @@ -568,7 +573,7 @@ MwClassRec MwVulkanClassRec = { NULL, /* draw */ NULL, /* click */ NULL, /* parent_resize */ - NULL, /* prop_change */ + prop_change, /* prop_change */ NULL, /* mouse_move */ NULL, /* mouse_up */ NULL, /* mouse_down */ @@ -587,14 +592,6 @@ MwClass MwVulkanClass = &MwVulkanClassRec; #else MwClass MwVulkanClass = NULL; -void MwVulkanEnableExtension(const char* ext_name) { - (void)ext_name; -} - -void MwVulkanEnableLayer(const char* ext_name) { - (void)ext_name; -} - void MwVulkanConfigure(MwVulkanConfig* cfg) { (void)cfg; }