DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit e6be1c3e7d61405643f05601806ef15ca2fdc91d
parent 923c4fbca043b5a0a69226b738dbf9fac1c087f2
Author: falkTX <falktx@falktx.com>
Date:   Sat, 13 Aug 2022 23:42:57 +0100

Add a few widget methods to make inspectors possible

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdgl/Widget.hpp | 26+++++++++++++++++++++++++-
Mdgl/src/Widget.cpp | 18+++++++++++++++++-
Mdgl/src/WidgetPrivateData.cpp | 5++++-
Mdgl/src/WidgetPrivateData.hpp | 3++-
4 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/dgl/Widget.hpp b/dgl/Widget.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> + * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -19,6 +19,8 @@ #include "Geometry.hpp" +#include <list> + START_NAMESPACE_DGL // -------------------------------------------------------------------------------------------------------------------- @@ -331,17 +333,34 @@ public: /** Get the Id associated with this widget. + Returns 0 by default. @see setId */ uint getId() const noexcept; /** + Get the name associated with this widget. + This is complately optional, mostly useful for debugging purposes. + Returns an empty string by default. + @see setName + */ + const char* getName() const noexcept; + + /** Set an Id to be associated with this widget. @see getId */ void setId(uint id) noexcept; /** + Set a name to be associated with this widget. + This is complately optional, only useful for debugging purposes. + @note name must not be null + @see getName + */ + void setName(const char* name) noexcept; + + /** Get the application associated with this widget's window. This is the same as calling `getTopLevelWidget()->getApp()`. */ @@ -368,6 +387,11 @@ public: TopLevelWidget* getTopLevelWidget() const noexcept; /** + Get list of children (a subwidgets) that belong to this widget. + */ + std::list<SubWidget*> getChildren() const noexcept; + + /** Request repaint of this widget's area to the window this widget belongs to. On the raw Widget class this function does nothing. */ diff --git a/dgl/src/Widget.cpp b/dgl/src/Widget.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> + * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -148,6 +148,11 @@ TopLevelWidget* Widget::getTopLevelWidget() const noexcept return pData->topLevelWidget; } +std::list<SubWidget*> Widget::getChildren() const noexcept +{ + return pData->subWidgets; +} + void Widget::repaint() noexcept { } @@ -157,11 +162,22 @@ uint Widget::getId() const noexcept return pData->id; } +const char* Widget::getName() const noexcept +{ + return pData->name != nullptr ? pData->name : ""; +} + void Widget::setId(uint id) noexcept { pData->id = id; } +void Widget::setName(const char* const name) noexcept +{ + std::free(pData->name); + pData->name = strdup(name); +} + bool Widget::onKeyboard(const KeyboardEvent& ev) { return pData->giveKeyboardEventForSubWidgets(ev); diff --git a/dgl/src/WidgetPrivateData.cpp b/dgl/src/WidgetPrivateData.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> + * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -33,6 +33,7 @@ Widget::PrivateData::PrivateData(Widget* const s, TopLevelWidget* const tlw) topLevelWidget(tlw), parentWidget(nullptr), id(0), + name(nullptr), needsScaling(false), visible(true), size(0, 0), @@ -43,6 +44,7 @@ Widget::PrivateData::PrivateData(Widget* const s, Widget* const pw) topLevelWidget(findTopLevelWidget(pw)), parentWidget(pw), id(0), + name(nullptr), needsScaling(false), visible(true), size(0, 0), @@ -51,6 +53,7 @@ Widget::PrivateData::PrivateData(Widget* const s, Widget* const pw) Widget::PrivateData::~PrivateData() { subWidgets.clear(); + std::free(name); } void Widget::PrivateData::displaySubWidgets(const uint width, const uint height, const double autoScaleFactor) diff --git a/dgl/src/WidgetPrivateData.hpp b/dgl/src/WidgetPrivateData.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> + * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -30,6 +30,7 @@ struct Widget::PrivateData { TopLevelWidget* const topLevelWidget; Widget* const parentWidget; uint id; + char* name; bool needsScaling; bool visible; Size<uint> size;