ConfigItems: Add configId to all item structs

This commit is contained in:
Maschell 2022-09-24 17:41:20 +02:00
parent 51f627dc6e
commit e649e4c93d
4 changed files with 29 additions and 11 deletions

View File

@ -5,6 +5,7 @@ extern "C" {
#endif #endif
typedef struct ConfigItemBoolean { typedef struct ConfigItemBoolean {
char *configId;
WUPSConfigItemHandle handle; WUPSConfigItemHandle handle;
bool defaultValue; bool defaultValue;
bool value; bool value;
@ -15,13 +16,13 @@ typedef struct ConfigItemBoolean {
typedef void (*BooleanValueChangedCallback)(ConfigItemBoolean *, bool); typedef void (*BooleanValueChangedCallback)(ConfigItemBoolean *, bool);
bool WUPSConfigItemBoolean_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback); bool WUPSConfigItemBoolean_AddToCategory(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback);
bool WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback, const char *trueValue, bool WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback, const char *trueValue,
const char *falseValue); const char *falseValue);
#define WUPSConfigItemBoolean_AddToCategoryHandled(__config__, __cat__, __configID__, __displayName__, __defaultValue__, __callback__) \ #define WUPSConfigItemBoolean_AddToCategoryHandled(__config__, __cat__, __configIs__, __displayName__, __defaultValue__, __callback__) \
do { \ do { \
if (!WUPSConfigItemBoolean_AddToCategory(__cat__, __configID__, __displayName__, __defaultValue__, __callback__)) { \ if (!WUPSConfigItemBoolean_AddToCategory(__cat__, __configIs__, __displayName__, __defaultValue__, __callback__)) { \
WUPSConfig_Destroy(__config__); \ WUPSConfig_Destroy(__config__); \
return 0; \ return 0; \
} \ } \

View File

@ -5,6 +5,7 @@ extern "C" {
#endif #endif
typedef struct ConfigItemIntegerRange { typedef struct ConfigItemIntegerRange {
char *configId;
WUPSConfigItemHandle handle; WUPSConfigItemHandle handle;
int defaultValue; int defaultValue;
int value; int value;
@ -15,13 +16,13 @@ typedef struct ConfigItemIntegerRange {
typedef void (*IntegerRangeValueChangedCallback)(ConfigItemIntegerRange *, int32_t); typedef void (*IntegerRangeValueChangedCallback)(ConfigItemIntegerRange *, int32_t);
bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName,
int32_t defaultValue, int32_t minValue, int32_t maxValue, int32_t defaultValue, int32_t minValue, int32_t maxValue,
IntegerRangeValueChangedCallback callback); IntegerRangeValueChangedCallback callback);
#define WUPSConfigItemIntegerRange_AddToCategoryHandled(__config__, __cat__, __configID__, __displayName__, __defaultValue__, __minValue__, __maxValue__, __callback__) \ #define WUPSConfigItemIntegerRange_AddToCategoryHandled(__config__, __cat__, __configId__, __displayName__, __defaultValue__, __minValue__, __maxValue__, __callback__) \
do { \ do { \
if (!WUPSConfigItemIntegerRange_AddToCategory(__cat__, __configID__, __displayName__, __defaultValue__, __minValue__, __maxValue__, __callback__)) { \ if (!WUPSConfigItemIntegerRange_AddToCategory(__cat__, __configId__, __displayName__, __defaultValue__, __minValue__, __maxValue__, __callback__)) { \
WUPSConfig_Destroy(__config__); \ WUPSConfig_Destroy(__config__); \
return 0; \ return 0; \
} \ } \

View File

@ -1,6 +1,7 @@
#include "wups/config/WUPSConfigItemBoolean.h" #include "wups/config/WUPSConfigItemBoolean.h"
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring>
#include <wups.h> #include <wups.h>
void WUPSConfigItemBoolean_onDelete(void *context); void WUPSConfigItemBoolean_onDelete(void *context);
@ -58,7 +59,7 @@ void WUPSConfigItemBoolean_onSelected(void *context, bool isSelected) {
} }
extern "C" bool extern "C" bool
WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback, const char *trueValue, WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, bool defaultValue, BooleanValueChangedCallback callback, const char *trueValue,
const char *falseValue) { const char *falseValue) {
if (cat == 0) { if (cat == 0) {
return false; return false;
@ -68,6 +69,12 @@ WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *
return false; return false;
} }
if (configId != nullptr) {
item->configId = strdup(configId);
} else {
item->configId = nullptr;
}
item->defaultValue = defaultValue; item->defaultValue = defaultValue;
item->value = defaultValue; item->value = defaultValue;
item->callback = (void *) callback; item->callback = (void *) callback;
@ -84,7 +91,7 @@ WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *
.onButtonPressed = &WUPSConfigItemBoolean_onButtonPressed, .onButtonPressed = &WUPSConfigItemBoolean_onButtonPressed,
.onDelete = &WUPSConfigItemBoolean_onDelete}; .onDelete = &WUPSConfigItemBoolean_onDelete};
if (WUPSConfigItem_Create(&item->handle, configID, displayName, callbacks, item) < 0) { if (WUPSConfigItem_Create(&item->handle, configId, displayName, callbacks, item) < 0) {
free(item); free(item);
return false; return false;
} }
@ -98,6 +105,7 @@ WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *
void WUPSConfigItemBoolean_onDelete(void *context) { void WUPSConfigItemBoolean_onDelete(void *context) {
auto *item = (ConfigItemBoolean *) context; auto *item = (ConfigItemBoolean *) context;
free(item->configId);
free(item); free(item);
} }

View File

@ -1,6 +1,7 @@
#include "wups/config/WUPSConfigItemIntegerRange.h" #include "wups/config/WUPSConfigItemIntegerRange.h"
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring>
#include <wups.h> #include <wups.h>
int32_t WUPSConfigItemIntegerRange_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) { int32_t WUPSConfigItemIntegerRange_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
@ -60,13 +61,14 @@ void WUPSConfigItemIntegerRange_restoreDefault(void *context) {
void WUPSConfigItemIntegerRange_onDelete(void *context) { void WUPSConfigItemIntegerRange_onDelete(void *context) {
auto *item = (ConfigItemIntegerRange *) context; auto *item = (ConfigItemIntegerRange *) context;
free(item->configId);
free(item); free(item);
} }
void WUPSConfigItemIntegerRange_onSelected(void *context, bool isSelected) { void WUPSConfigItemIntegerRange_onSelected(void *context, bool isSelected) {
} }
extern "C" bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, int32_t defaultValue, int32_t minValue, int32_t maxValue, extern "C" bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandle cat, const char *configId, const char *displayName, int32_t defaultValue, int32_t minValue, int32_t maxValue,
IntegerRangeValueChangedCallback callback) { IntegerRangeValueChangedCallback callback) {
if (cat == 0) { if (cat == 0) {
return false; return false;
@ -76,6 +78,12 @@ extern "C" bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandl
return false; return false;
} }
if (configId != nullptr) {
item->configId = strdup(configId);
} else {
item->configId = nullptr;
}
item->defaultValue = defaultValue; item->defaultValue = defaultValue;
item->value = defaultValue; item->value = defaultValue;
item->minValue = minValue; item->minValue = minValue;
@ -92,7 +100,7 @@ extern "C" bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandl
.onButtonPressed = &WUPSConfigItemIntegerRange_onButtonPressed, .onButtonPressed = &WUPSConfigItemIntegerRange_onButtonPressed,
.onDelete = &WUPSConfigItemIntegerRange_onDelete}; .onDelete = &WUPSConfigItemIntegerRange_onDelete};
if (WUPSConfigItem_Create(&(item->handle), configID, displayName, callbacks, item) < 0) { if (WUPSConfigItem_Create(&(item->handle), configId, displayName, callbacks, item) < 0) {
free(item); free(item);
return false; return false;
}; };