obs-frontend-api,UI,docs: Add dock API that ask for unique object name

obs_frontend_add_dock() is deprecated in favor of
obs_frontend_add_dock_by_id()
This commit is contained in:
tytan652 2022-10-22 10:36:53 +02:00 committed by Lain
parent f2fa54120a
commit cde5545f8f
5 changed files with 82 additions and 0 deletions

View file

@ -398,6 +398,35 @@ struct OBSStudioAPI : obs_frontend_callbacks {
return (void *)main->AddDockWidget(d);
}
bool obs_frontend_add_dock_by_id(const char *id, const char *title,
void *widget) override
{
if (main->IsDockObjectNameUsed(QT_UTF8(id))) {
blog(LOG_WARNING,
"Dock id '%s' already used! "
"Duplicate library?",
id);
return false;
}
OBSDock *dock = new OBSDock(main);
dock->setWidget((QWidget *)widget);
dock->setWindowTitle(QT_UTF8(title));
dock->setObjectName(QT_UTF8(id));
main->AddDockWidget(dock, Qt::RightDockWidgetArea);
dock->setFloating(true);
dock->setVisible(false);
return true;
}
void obs_frontend_remove_dock(const char *id) override
{
main->RemoveDockWidget(QT_UTF8(id));
}
void obs_frontend_add_event_callback(obs_frontend_event_cb callback,
void *private_data) override
{

View file

@ -330,6 +330,20 @@ void *obs_frontend_add_dock(void *dock)
return !!callbacks_valid() ? c->obs_frontend_add_dock(dock) : nullptr;
}
bool obs_frontend_add_dock_by_id(const char *id, const char *title,
void *widget)
{
return !!callbacks_valid()
? c->obs_frontend_add_dock_by_id(id, title, widget)
: false;
}
void obs_frontend_remove_dock(const char *id)
{
if (callbacks_valid())
c->obs_frontend_remove_dock(id);
}
void obs_frontend_add_event_callback(obs_frontend_event_cb callback,
void *private_data)
{

View file

@ -138,8 +138,15 @@ EXPORT void obs_frontend_add_tools_menu_item(const char *name,
void *private_data);
/* takes QDockWidget and returns QAction */
OBS_DEPRECATED
EXPORT void *obs_frontend_add_dock(void *dock);
/* takes QWidget for widget */
EXPORT bool obs_frontend_add_dock_by_id(const char *id, const char *title,
void *widget);
EXPORT void obs_frontend_remove_dock(const char *id);
typedef void (*obs_frontend_event_cb)(enum obs_frontend_event event,
void *private_data);

View file

@ -66,6 +66,11 @@ struct obs_frontend_callbacks {
virtual void *obs_frontend_add_dock(void *dock) = 0;
virtual bool obs_frontend_add_dock_by_id(const char *id,
const char *title,
void *widget) = 0;
virtual void obs_frontend_remove_dock(const char *id) = 0;
virtual void
obs_frontend_add_event_callback(obs_frontend_event_cb callback,
void *private_data) = 0;

View file

@ -447,6 +447,33 @@ Functions
:param dock: QDockWidget to add/create
:return: A pointer to the added QAction
.. deprecated:: 29.1
Prefer :c:func:`obs_frontend_add_dock_by_id()` instead.
---------------------------------------
.. function:: bool obs_frontend_add_dock_by_id(const char *id, const char *title, void *widget)
Adds a dock with the widget to the UI with a toggle in the Docks
menu.
Note: Use :c:func:`obs_frontend_remove_dock` to remove the dock
and the id from the UI.
:param id: Unique identifier of the dock
:param title: Window title of the dock
:param widget: QWidget to insert in the dock
:return: *true* if the dock was added, *false* if the id was already
used
---------------------------------------
.. function:: void obs_frontend_remove_dock(const char *id)
Removes the dock with this id from the UI.
:param id: Unique identifier of the dock to remove.
---------------------------------------
.. function:: void obs_frontend_add_event_callback(obs_frontend_event_cb callback, void *private_data)