Adding webui_get_float

This commit is contained in:
Hassan DRAGA 2024-05-29 17:23:19 -04:00
parent 8d94cdcae8
commit 9c9b3dc00a
2 changed files with 58 additions and 0 deletions

View File

@ -647,6 +647,29 @@ WEBUI_EXPORT long long int webui_get_int_at(webui_event_t* e, size_t index);
*/
WEBUI_EXPORT long long int webui_get_int(webui_event_t* e);
/**
* @brief Get an argument as float at a specific index
*
* @param e The event struct
* @param index The argument position starting from 0
*
* @return Returns argument as float
*
* @example double myNum = webui_get_float_at(e, 0);
*/
WEBUI_EXPORT double webui_get_float_at(webui_event_t* e, size_t index);
/**
* @brief Get the first argument as float
*
* @param e The event struct
*
* @return Returns argument as float
*
* @example double myNum = webui_get_float(e);
*/
WEBUI_EXPORT double webui_get_float(webui_event_t* e);
/**
* @brief Get an argument as string at a specific index
*

View File

@ -1462,6 +1462,32 @@ long long int webui_get_int_at(webui_event_t* e, size_t index) {
return 0;
}
double webui_get_float_at(webui_event_t* e, size_t index) {
#ifdef WEBUI_LOG
printf("[User] webui_get_float_at([%zu])\n", index);
#endif
// Initialization & Dereference
// are done by webui_get_string()
if (index > WEBUI_MAX_ARG)
return 0.0;
const char* str = webui_get_string_at(e, index);
if (str == NULL)
return 0.0;
size_t len = _webui_strlen(str);
if (len > 0 && len <= 20) {
// 64-bit max is -9,223,372,036,854,775,808 (20 character)
char* endptr;
return strtod(str, &endptr);
}
return 0.0;
}
bool webui_get_bool_at(webui_event_t* e, size_t index) {
#ifdef WEBUI_LOG
@ -1527,6 +1553,15 @@ long long int webui_get_int(webui_event_t* e) {
return webui_get_int_at(e, 0);
}
double webui_get_float(webui_event_t* e) {
#ifdef WEBUI_LOG
printf("[User] webui_get_float()\n");
#endif
return webui_get_float_at(e, 0);
}
bool webui_get_bool(webui_event_t* e) {
#ifdef WEBUI_LOG