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
typedef struct ConfigItemBoolean {
char *configId;
WUPSConfigItemHandle handle;
bool defaultValue;
bool value;
@ -15,13 +16,13 @@ typedef struct ConfigItemBoolean {
typedef void (*BooleanValueChangedCallback)(ConfigItemBoolean *, bool);
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_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,
const char *falseValue);
#define WUPSConfigItemBoolean_AddToCategoryHandled(__config__, __cat__, __configID__, __displayName__, __defaultValue__, __callback__) \
#define WUPSConfigItemBoolean_AddToCategoryHandled(__config__, __cat__, __configIs__, __displayName__, __defaultValue__, __callback__) \
do { \
if (!WUPSConfigItemBoolean_AddToCategory(__cat__, __configID__, __displayName__, __defaultValue__, __callback__)) { \
if (!WUPSConfigItemBoolean_AddToCategory(__cat__, __configIs__, __displayName__, __defaultValue__, __callback__)) { \
WUPSConfig_Destroy(__config__); \
return 0; \
} \

View File

@ -5,6 +5,7 @@ extern "C" {
#endif
typedef struct ConfigItemIntegerRange {
char *configId;
WUPSConfigItemHandle handle;
int defaultValue;
int value;
@ -15,13 +16,13 @@ typedef struct ConfigItemIntegerRange {
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,
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 { \
if (!WUPSConfigItemIntegerRange_AddToCategory(__cat__, __configID__, __displayName__, __defaultValue__, __minValue__, __maxValue__, __callback__)) { \
if (!WUPSConfigItemIntegerRange_AddToCategory(__cat__, __configId__, __displayName__, __defaultValue__, __minValue__, __maxValue__, __callback__)) { \
WUPSConfig_Destroy(__config__); \
return 0; \
} \

View File

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

View File

@ -1,6 +1,7 @@
#include "wups/config/WUPSConfigItemIntegerRange.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <wups.h>
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) {
auto *item = (ConfigItemIntegerRange *) context;
free(item->configId);
free(item);
}
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) {
if (cat == 0) {
return false;
@ -76,6 +78,12 @@ extern "C" bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandl
return false;
}
if (configId != nullptr) {
item->configId = strdup(configId);
} else {
item->configId = nullptr;
}
item->defaultValue = defaultValue;
item->value = defaultValue;
item->minValue = minValue;
@ -92,7 +100,7 @@ extern "C" bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandl
.onButtonPressed = &WUPSConfigItemIntegerRange_onButtonPressed,
.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);
return false;
};