introduce early props
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good

This commit is contained in:
Nishi 2026-04-20 09:00:28 +09:00
commit 5d0c84d748
Signed by: nishi
GPG key ID: 27EF69B208EB9343
6 changed files with 62 additions and 45 deletions

View file

@ -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);

View file

@ -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"

View file

@ -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.
*/

View file

@ -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
-->
<properties>
<integer name="x" common="yes" />
@ -104,6 +107,10 @@
<string name="foreground" common="yes" />
<string name="subForeground" common="yes" />
<!-- Early string properties -->
<string name="vulkanExtension" early="yes" />
<string name="vulkanLayer" early="yes" />
<pixmap name="pixmap" />
<pixmap name="iconPixmap" />
<struct defname="MwSizeHints" pointer="yes" name="sizeHints" />

View file

@ -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);
}

View file

@ -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;
}