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> <dd>
<a href="#Mw_Core_h__MwDispatch">MwDispatch</a> <a href="#Mw_Core_h__MwDispatch">MwDispatch</a>
</dd> </dd>
<dd>
<a href="#Mw_Core_h__MwDispatch2">MwDispatch2</a>
</dd>
<dd> <dd>
<a href="#Mw_Core_h__MwCreateWidget">MwCreateWidget</a> <a href="#Mw_Core_h__MwCreateWidget">MwCreateWidget</a>
</dd> </dd>
@@ -317,6 +320,37 @@
</dd> </dd>
</dl> </dl>
<hr> <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 ( <pre id="Mw_Core_h__MwCreateWidget"><code>MWDECL MwWidget MwCreateWidget (
MwClass widget_class, MwClass widget_class,
const char* name, const char* name,

View File

@@ -18,6 +18,16 @@
#define MwDispatch(x, y) \ #define MwDispatch(x, y) \
if(x->widget_class != NULL && x->widget_class->y != NULL) x->widget_class->y(x) 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 #define MwWaitMS 5
#ifdef __cplusplus #ifdef __cplusplus

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,13 +3,15 @@
#include "../external/stb_ds.h" #include "../external/stb_ds.h"
static void create(MwWidget handle) { static int create(MwWidget handle) {
#ifdef _WIN32 #ifdef _WIN32
#else #else
XUnmapWindow(handle->lowlevel->display, handle->lowlevel->window); XUnmapWindow(handle->lowlevel->display, handle->lowlevel->window);
#endif #endif
MwSetDefault(handle); MwSetDefault(handle);
return 0;
} }
static void null_all(MwMenu menu) { 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_surface_setup(MwWidget handle, vulkan_t* o);
static MwErrorEnum vulkan_devices_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)); vulkan_t* o = malloc(sizeof(*o));
MwErrorEnum err; MwErrorEnum err;
err = vulkan_instance_setup(handle, o); err = vulkan_instance_setup(handle, o);
if(err != MwEsuccess) { if(err != MwEsuccess) {
printf("%s", MwGetLastError()); printf("%s", MwGetLastError());
return; return 1;
} }
err = vulkan_surface_setup(handle, o); err = vulkan_surface_setup(handle, o);
if(err != MwEsuccess) { if(err != MwEsuccess) {
printf("%s", MwGetLastError()); printf("%s", MwGetLastError());
return; return 1;
} }
err = vulkan_devices_setup(handle, o); err = vulkan_devices_setup(handle, o);
if(err != MwEsuccess) { if(err != MwEsuccess) {
printf("%s", MwGetLastError()); printf("%s", MwGetLastError());
return; return 1;
} }
handle->lowlevel->copy_buffer = 0; handle->lowlevel->copy_buffer = 0;
handle->internal = o; handle->internal = o;
MwSetDefault(handle); MwSetDefault(handle);
return 0;
} }
static MwErrorEnum _destroy(MwWidget handle) { static MwErrorEnum _destroy(MwWidget handle) {

View File

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