Skip to content

Commit

Permalink
Component Tags in JuceGui (#145)
Browse files Browse the repository at this point in the history
Add compoennt tags api. Add ones for clap param, traversal id,
and full traversal id. Use these in KeyboardAccesibilityThingy
  • Loading branch information
baconpaul authored Jan 8, 2025
1 parent 7ecc2c2 commit 8211137
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ add_library(${PROJECT_NAME} STATIC
src/sst/jucegui/components/ToolTip.cpp
src/sst/jucegui/components/VSlider.cpp

src/sst/jucegui/component-adapters/ComponentTags.cpp

src/sst/jucegui/data/TreeTable.cpp

src/sst/jucegui/style/StyleAndSettingsConsumer.cpp
Expand Down
39 changes: 12 additions & 27 deletions include/sst/jucegui/accessibility/KeyboardTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <iostream>
#include <limits>
#include "sst/jucegui/component-adapters/ComponentTags.h"

namespace sst::jucegui::accessibility
{
Expand All @@ -44,18 +45,6 @@ struct KeyboardTraverser : juce::KeyboardFocusTraverser
return juce::KeyboardFocusTraverser::getDefaultComponent(parentComponent);
}

static const juce::Identifier &idIndex()
{
static juce::Identifier idIndex{"sstjucegui-idIndex"};
return idIndex;
}

static const juce::Identifier &fullIdIndex()
{
static juce::Identifier idIndex{"sstjucegui-fullIdIndex"};
return idIndex;
}

static std::string nm(juce::Component *c)
{
if (!c)
Expand Down Expand Up @@ -170,20 +159,21 @@ struct KeyboardTraverser : juce::KeyboardFocusTraverser
{
if (k == c)
continue;
auto hasidx = k->getProperties().getVarPointer(idIndex());
if (hasidx)
auto hasidx = component_adapters::getTraversalId(k);
if (hasidx.has_value())
newID = std::max(newID, (int)*hasidx + 1);
}
c->getProperties().set(idIndex(), newID);
component_adapters::setTraversalId(c, newID);
KLG("Issued " << nm(c) << " " << newID);
}
static int traversalId(juce::Component *c)
{
if (!c->isAccessible())
return 0;

auto hasidx = c->getProperties().getVarPointer(idIndex());
if (!hasidx)
auto hasidx = component_adapters::getTraversalId(c);

if (!hasidx.has_value())
{
if (dynamic_cast<IssueIDIfMissingMarker *>(c))
{
Expand All @@ -195,22 +185,22 @@ struct KeyboardTraverser : juce::KeyboardFocusTraverser
}
}

auto fullidx = c->getProperties().getVarPointer(fullIdIndex());
if (fullidx)
auto fullidx = component_adapters::getFullTraversalId(c);
if (fullidx.has_value())
return *fullidx;

auto res = 0;
auto curr = c;
while (curr)
{
auto idx = curr->getProperties().getVarPointer(idIndex());
if (idx)
auto idx = component_adapters::getTraversalId(curr);
if (idx.has_value())
res += (int)*idx;
curr = curr->getParentComponent();
}
if (res != 0)
{
c->getProperties().set(fullIdIndex(), res);
component_adapters::setFullTraversalId(c, res);
}
return res;
}
Expand Down Expand Up @@ -253,11 +243,6 @@ struct KeyboardTraverser : juce::KeyboardFocusTraverser
{
return juce::KeyboardFocusTraverser::getAllComponents(parentComponent);
}

static void assignTraversalIndex(juce::Component *c, int idx)
{
c->getProperties().set(idIndex(), idx);
}
};
#undef KLG
} // namespace sst::jucegui::accessibility
Expand Down
37 changes: 37 additions & 0 deletions include/sst/jucegui/component-adapters/ComponentTags.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* sst-jucegui - an open source library of juce widgets
* built by Surge Synth Team.
*
* Copyright 2023-2024, various authors, as described in the GitHub
* transaction log.
*
* sst-jucegui is released under the MIT license, as described
* by "LICENSE.md" in this repository. This means you may use this
* in commercial software if you are a JUCE Licensee. If you use JUCE
* in the open source / GPL3 context, your combined work must be
* released under GPL3.
*
* All source in sst-jucegui available at
* https://github.com/surge-synthesizer/sst-jucegui
*/

#ifndef INCLUDE_SST_JUCEGUI_COMPONENT_ADAPTERS_COMPONENTTAGS_H
#define INCLUDE_SST_JUCEGUI_COMPONENT_ADAPTERS_COMPONENTTAGS_H

#include <juce_gui_basics/juce_gui_basics.h>
#include <optional>

namespace sst::jucegui::component_adapters
{
void setTraversalId(juce::Component *, int64_t);
std::optional<int64_t> getTraversalId(juce::Component *);

void setFullTraversalId(juce::Component *, int64_t);
std::optional<int64_t> getFullTraversalId(juce::Component *);

void setClapParamId(juce::Component *, uint32_t);
std::optional<uint32_t> getClapParamId(juce::Component *);

} // namespace sst::jucegui::component_adapters

#endif // COMPONENTTAGS_H
49 changes: 49 additions & 0 deletions src/sst/jucegui/component-adapters/ComponentTags.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* sst-jucegui - an open source library of juce widgets
* built by Surge Synth Team.
*
* Copyright 2023-2024, various authors, as described in the GitHub
* transaction log.
*
* sst-jucegui is released under the MIT license, as described
* by "LICENSE.md" in this repository. This means you may use this
* in commercial software if you are a JUCE Licensee. If you use JUCE
* in the open source / GPL3 context, your combined work must be
* released under GPL3.
*
* All source in sst-jucegui available at
* https://github.com/surge-synthesizer/sst-jucegui
*/

#include <sst/jucegui/component-adapters/ComponentTags.h>

namespace sst::jucegui::component_adapters
{

template <typename CT, typename JT>
std::optional<CT> unpack(juce::Component *c, const juce::Identifier &id)
{
auto prop = c->getProperties().getVarPointer(id);
if (prop)
{
return static_cast<CT>(static_cast<JT>(*prop));
}
return std::nullopt;
}

#define GETSET(name, type, jucetype) \
static juce::Identifier id_##name{"sstjg-" #name}; \
void set##name(juce::Component *c, type id) \
{ \
c->getProperties().set(id_##name, (jucetype)id); \
} \
std::optional<type> get##name(juce::Component *c) \
{ \
return unpack<type, jucetype>(c, id_##name); \
}

GETSET(TraversalId, int64_t, juce::int64);
GETSET(FullTraversalId, int64_t, juce::int64);
GETSET(ClapParamId, uint32_t, juce::int64);

} // namespace sst::jucegui::component_adapters

0 comments on commit 8211137

Please sign in to comment.