mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-19 20:32:15 +02:00
libobs: Add button support to properties
This adds button support to properties, which will allow a properties pane to let the user click a button to activate something with a particular obs context. When pressed, the button will execute the callback given, with the context's private data as a parameter.
This commit is contained in:
parent
5be241b17a
commit
85dcfcaa34
@ -17,6 +17,7 @@
|
||||
|
||||
#include "util/bmem.h"
|
||||
#include "util/darray.h"
|
||||
#include "obs-internal.h"
|
||||
#include "obs-properties.h"
|
||||
|
||||
static inline void *get_property_data(struct obs_property *prop);
|
||||
@ -51,6 +52,10 @@ struct list_data {
|
||||
enum obs_combo_format format;
|
||||
};
|
||||
|
||||
struct button_data {
|
||||
obs_property_clicked_t callback;
|
||||
};
|
||||
|
||||
static inline void list_item_free(struct list_data *data,
|
||||
struct list_item *item)
|
||||
{
|
||||
@ -214,6 +219,7 @@ static inline size_t get_property_size(enum obs_property_type type)
|
||||
case OBS_PROPERTY_PATH: return 0;
|
||||
case OBS_PROPERTY_LIST: return sizeof(struct list_data);
|
||||
case OBS_PROPERTY_COLOR: return 0;
|
||||
case OBS_PROPERTY_BUTTON: return sizeof(struct button_data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -350,6 +356,18 @@ obs_property_t obs_properties_add_color(obs_properties_t props,
|
||||
return new_prop(props, name, desc, OBS_PROPERTY_COLOR);
|
||||
}
|
||||
|
||||
obs_property_t obs_properties_add_button(obs_properties_t props,
|
||||
const char *name, const char *text,
|
||||
obs_property_clicked_t callback)
|
||||
{
|
||||
if (!props || has_prop(props, name)) return NULL;
|
||||
|
||||
struct obs_property *p = new_prop(props, name, text,
|
||||
OBS_PROPERTY_BUTTON);
|
||||
struct button_data *data = get_property_data(p);
|
||||
data->callback = callback;
|
||||
return p;
|
||||
}
|
||||
|
||||
static inline bool is_combo(struct obs_property *p)
|
||||
{
|
||||
@ -395,6 +413,19 @@ bool obs_property_modified(obs_property_t p, obs_data_t settings)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool obs_property_button_clicked(obs_property_t p, void *obj)
|
||||
{
|
||||
struct obs_context_data *context = obj;
|
||||
if (p) {
|
||||
struct button_data *data = get_type_data(p,
|
||||
OBS_PROPERTY_BUTTON);
|
||||
if (data && data->callback)
|
||||
return data->callback(p->parent, p, context->data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void obs_property_set_visible(obs_property_t p, bool visible)
|
||||
{
|
||||
if (p) p->visible = visible;
|
||||
|
@ -33,6 +33,7 @@ enum obs_property_type {
|
||||
OBS_PROPERTY_PATH,
|
||||
OBS_PROPERTY_LIST,
|
||||
OBS_PROPERTY_COLOR,
|
||||
OBS_PROPERTY_BUTTON,
|
||||
};
|
||||
|
||||
enum obs_combo_format {
|
||||
@ -82,6 +83,14 @@ extern void obs_properties_apply_settings(obs_properties_t props,
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Callback for when a button property is clicked. If the properties
|
||||
* need to be refreshed due to changes to the property layout, return true,
|
||||
* otherwise return false.
|
||||
*/
|
||||
typedef bool (*obs_property_clicked_t)(obs_properties_t props,
|
||||
obs_property_t property, void *data);
|
||||
|
||||
EXPORT obs_property_t obs_properties_add_bool(obs_properties_t props,
|
||||
const char *name, const char *description);
|
||||
|
||||
@ -107,6 +116,10 @@ EXPORT obs_property_t obs_properties_add_list(obs_properties_t props,
|
||||
EXPORT obs_property_t obs_properties_add_color(obs_properties_t props,
|
||||
const char *name, const char *description);
|
||||
|
||||
EXPORT obs_property_t obs_properties_add_button(obs_properties_t props,
|
||||
const char *name, const char *text,
|
||||
obs_property_clicked_t callback);
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
@ -121,6 +134,7 @@ EXPORT void obs_property_set_modified_callback(obs_property_t p,
|
||||
obs_property_modified_t modified);
|
||||
|
||||
EXPORT bool obs_property_modified(obs_property_t p, obs_data_t settings);
|
||||
EXPORT bool obs_property_button_clicked(obs_property_t p, void *obj);
|
||||
|
||||
EXPORT void obs_property_set_visible(obs_property_t p, bool visible);
|
||||
EXPORT void obs_property_set_enabled(obs_property_t p, bool enabled);
|
||||
|
Loading…
Reference in New Issue
Block a user