add return code for some stuff

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@156 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-04 13:57:28 +00:00
parent 121b75ac69
commit 68510eff6b
12 changed files with 82 additions and 17 deletions

View File

@@ -20,6 +20,9 @@
<dd>
<a href="#Mw_Core_h__MwDispatch">MwDispatch</a>
</dd>
<dd>
<a href="#Mw_Core_h__MwDispatch2">MwDispatch2</a>
</dd>
<dd>
<a href="#Mw_Core_h__MwCreateWidget">MwCreateWidget</a>
</dd>
@@ -317,6 +320,37 @@
</dd>
</dl>
<hr>
<pre id="Mw_Core_h__MwDispatch2"><code>#define MwDispatch2(x, y)</code></pre>
<dl>
<dd>
Dispatches the handler of widget class.
</dd>
<dt>
<img src="warning.gif" alt="warning">
</dt>
<dd>
Used internally.
</dd>
<dt>
Parameter <code>x</code>
</dt>
<dd>
Widget.
</dd>
<dt>
Parameter <code>y</code>
</dt>
<dd>
Handler name.
</dd>
<dt>
Returns
</dt>
<dd>
<code>0</code> for success, otherwise failed.
</dd>
</dl>
<hr>
<pre id="Mw_Core_h__MwCreateWidget"><code>MWDECL MwWidget MwCreateWidget (
MwClass widget_class,
const char* name,

View File

@@ -18,6 +18,16 @@
#define MwDispatch(x, y) \
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x)
/*!
* %warning Used internally
* %brief Dispatches the handler of widget class
* %param x Widget
* %param y Handler name
* %return `0` for success, otherwise failed
*/
#define MwDispatch2(x, y) \
((x->widget_class != NULL && x->widget_class->y != NULL) ? x->widget_class->y(x) : 0)
#define MwWaitMS 5
#ifdef __cplusplus

View File

@@ -24,6 +24,7 @@ typedef void* MwWidget;
typedef void* MwMenu;
#endif
typedef void (*MwHandler)(MwWidget handle);
typedef int (*MwHandler2)(MwWidget handle);
typedef void (*MwUserHandler)(MwWidget handle, void* user_data, void* call_data);
typedef void (*MwErrorHandler)(int code, const char* message, void* user_data);
@@ -96,11 +97,11 @@ struct _MwMenu {
#endif
struct _MwClass {
MwHandler create;
MwHandler destroy;
MwHandler draw;
MwHandler click;
MwHandler parent_resize;
MwHandler2 create;
MwHandler destroy;
MwHandler draw;
MwHandler click;
MwHandler parent_resize;
};
struct _MwFont {

View File

@@ -96,7 +96,11 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
shdefault(h->handler, NULL);
shdefault(h->data, NULL);
MwDispatch(h, create);
if(MwDispatch2(h, create)) {
h->widget_class = NULL;
MwDestroyWidget(h);
return NULL;
}
return h;
}

View File

@@ -1,8 +1,10 @@
/* $Id$ */
#include <Mw/Milsko.h>
static void create(MwWidget handle) {
static int create(MwWidget handle) {
MwSetDefault(handle);
return 0;
}
static void draw(MwWidget handle) {

View File

@@ -1,8 +1,10 @@
/* $Id$ */
#include <Mw/Milsko.h>
static void create(MwWidget handle) {
static int create(MwWidget handle) {
MwSetDefault(handle);
return 0;
}
static void draw(MwWidget handle) {

View File

@@ -1,8 +1,10 @@
/* $Id$ */
#include <Mw/Milsko.h>
static void create(MwWidget handle) {
static int create(MwWidget handle) {
MwSetDefault(handle);
return 0;
}
static void draw(MwWidget handle) {

View File

@@ -25,7 +25,7 @@ static void set_xywh(MwWidget handle) {
NULL);
}
static void create(MwWidget handle) {
static int create(MwWidget handle) {
MwMenu m = malloc(sizeof(*m));
m->name = NULL;
@@ -37,6 +37,8 @@ static void create(MwWidget handle) {
MwSetDefault(handle);
set_xywh(handle);
return 0;
}
static void recursive_free(MwMenu m) {

View File

@@ -49,7 +49,7 @@ typedef struct opengl {
} opengl_t;
#endif
static void create(MwWidget handle) {
static int create(MwWidget handle) {
opengl_t* o = malloc(sizeof(*o));
#ifdef _WIN32
PIXELFORMATDESCRIPTOR pfd;
@@ -107,6 +107,8 @@ static void create(MwWidget handle) {
handle->lowlevel->copy_buffer = 0;
MwSetDefault(handle);
return 0;
}
static void destroy(MwWidget handle) {

View File

@@ -3,13 +3,15 @@
#include "../external/stb_ds.h"
static void create(MwWidget handle) {
static int create(MwWidget handle) {
#ifdef _WIN32
#else
XUnmapWindow(handle->lowlevel->display, handle->lowlevel->window);
#endif
MwSetDefault(handle);
return 0;
}
static void null_all(MwMenu menu) {

View File

@@ -117,30 +117,32 @@ static MwErrorEnum vulkan_instance_setup(MwWidget handle, vulkan_t* o);
static MwErrorEnum vulkan_surface_setup(MwWidget handle, vulkan_t* o);
static MwErrorEnum vulkan_devices_setup(MwWidget handle, vulkan_t* o);
static void create(MwWidget handle) {
static int create(MwWidget handle) {
vulkan_t* o = malloc(sizeof(*o));
MwErrorEnum err;
err = vulkan_instance_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
return;
return 1;
}
err = vulkan_surface_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
return;
return 1;
}
err = vulkan_devices_setup(handle, o);
if(err != MwEsuccess) {
printf("%s", MwGetLastError());
return;
return 1;
}
handle->lowlevel->copy_buffer = 0;
handle->internal = o;
MwSetDefault(handle);
return 0;
}
static MwErrorEnum _destroy(MwWidget handle) {

View File

@@ -1,8 +1,10 @@
/* $Id$ */
#include <Mw/Milsko.h>
static void create(MwWidget handle) {
static int create(MwWidget handle) {
MwSetDefault(handle);
return 0;
}
static void draw(MwWidget handle) {