libobs: Add obs_property_list_insert_* functions
These functions allow you to insert items at a specific index in a list instead of being forced to always append to the end.
This commit is contained in:
parent
e88632ed73
commit
a69524a271
@ -581,6 +581,22 @@ static size_t add_item(struct list_data *data, const char *name,
|
||||
return da_push_back(data->items, &item);
|
||||
}
|
||||
|
||||
static void insert_item(struct list_data *data, size_t idx, const char *name,
|
||||
const void *val)
|
||||
{
|
||||
struct list_item item = { NULL };
|
||||
item.name = bstrdup(name);
|
||||
|
||||
if (data->format == OBS_COMBO_FORMAT_INT)
|
||||
item.ll = *(const long long*)val;
|
||||
else if (data->format == OBS_COMBO_FORMAT_FLOAT)
|
||||
item.d = *(const double*)val;
|
||||
else
|
||||
item.str = bstrdup(val);
|
||||
|
||||
da_insert(data->items, idx, &item);
|
||||
}
|
||||
|
||||
size_t obs_property_list_add_string(obs_property_t *p,
|
||||
const char *name, const char *val)
|
||||
{
|
||||
@ -608,6 +624,30 @@ size_t obs_property_list_add_float(obs_property_t *p,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void obs_property_list_insert_string(obs_property_t *p, size_t idx,
|
||||
const char *name, const char *val)
|
||||
{
|
||||
struct list_data *data = get_list_data(p);
|
||||
if (data && data->format == OBS_COMBO_FORMAT_STRING)
|
||||
insert_item(data, idx, name, val);
|
||||
}
|
||||
|
||||
void obs_property_list_insert_int(obs_property_t *p, size_t idx,
|
||||
const char *name, long long val)
|
||||
{
|
||||
struct list_data *data = get_list_data(p);
|
||||
if (data && data->format == OBS_COMBO_FORMAT_INT)
|
||||
insert_item(data, idx, name, &val);
|
||||
}
|
||||
|
||||
void obs_property_list_insert_float(obs_property_t *p, size_t idx,
|
||||
const char *name, double val)
|
||||
{
|
||||
struct list_data *data = get_list_data(p);
|
||||
if (data && data->format == OBS_COMBO_FORMAT_FLOAT)
|
||||
insert_item(data, idx, name, &val);
|
||||
}
|
||||
|
||||
void obs_property_list_item_remove(obs_property_t *p, size_t idx)
|
||||
{
|
||||
struct list_data *data = get_list_data(p);
|
||||
|
@ -223,6 +223,13 @@ EXPORT size_t obs_property_list_add_int(obs_property_t *p,
|
||||
EXPORT size_t obs_property_list_add_float(obs_property_t *p,
|
||||
const char *name, double val);
|
||||
|
||||
EXPORT void obs_property_list_insert_string(obs_property_t *p, size_t idx,
|
||||
const char *name, const char *val);
|
||||
EXPORT void obs_property_list_insert_int(obs_property_t *p, size_t idx,
|
||||
const char *name, long long val);
|
||||
EXPORT void obs_property_list_insert_float(obs_property_t *p, size_t idx,
|
||||
const char *name, double val);
|
||||
|
||||
EXPORT void obs_property_list_item_disable(obs_property_t *p, size_t idx,
|
||||
bool disabled);
|
||||
EXPORT bool obs_property_list_item_disabled(obs_property_t *p, size_t idx);
|
||||
|
Loading…
x
Reference in New Issue
Block a user