JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_FocusHelpers.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::detail
27{
28
30{
31 FocusHelpers() = delete;
32
33 static int getOrder (const Component* c)
34 {
35 auto order = c->getExplicitFocusOrder();
36 return order > 0 ? order : std::numeric_limits<int>::max();
37 }
38
39 template <typename FocusContainerFn>
40 static void findAllComponents (Component* parent,
41 std::vector<Component*>& components,
42 FocusContainerFn isFocusContainer)
43 {
44 if (parent == nullptr || parent->getNumChildComponents() == 0)
45 return;
46
48
49 for (auto* c : parent->getChildren())
50 if (c->isVisible() && c->isEnabled())
52
53 const auto compareComponents = [&] (const Component* a, const Component* b)
54 {
55 const auto getComponentOrderAttributes = [] (const Component* c)
56 {
57 return std::make_tuple (getOrder (c),
58 c->isAlwaysOnTop() ? 0 : 1,
59 c->getY(),
60 c->getX());
61 };
62
64 };
65
66 // This will sort so that they are ordered in terms of explicit focus,
67 // always on top, left-to-right, and then top-to-bottom.
69
70 for (auto* c : localComponents)
71 {
72 components.push_back (c);
73
74 if (! (c->*isFocusContainer)())
75 findAllComponents (c, components, isFocusContainer);
76 }
77 }
78
79 enum class NavigationDirection { forwards, backwards };
80
81 template <typename FocusContainerFn>
82 static Component* navigateFocus (Component* current,
83 Component* focusContainer,
84 NavigationDirection direction,
85 FocusContainerFn isFocusContainer)
86 {
87 if (focusContainer != nullptr)
88 {
89 std::vector<Component*> components;
90 findAllComponents (focusContainer, components, isFocusContainer);
91
92 const auto iter = std::find (components.cbegin(), components.cend(), current);
93
94 if (iter == components.cend())
95 return nullptr;
96
97 switch (direction)
98 {
99 case NavigationDirection::forwards:
100 if (iter != std::prev (components.cend()))
101 return *std::next (iter);
102
103 break;
104
105 case NavigationDirection::backwards:
106 if (iter != components.cbegin())
107 return *std::prev (iter);
108
109 break;
110 }
111 }
112
113 return nullptr;
114 }
115};
116
117} // namespace juce::detail
T cbegin(T... args)
The base class for all JUCE user-interface objects.
bool isVisible() const noexcept
Tests whether the component is visible or not.
int getNumChildComponents() const noexcept
Returns the number of child components that this component contains.
bool isAlwaysOnTop() const noexcept
Returns true if this component is set to always stay in front of its siblings.
int getX() const noexcept
Returns the x coordinate of the component's left edge.
int getExplicitFocusOrder() const
Returns the focus order of this component, if one has been specified.
int getY() const noexcept
Returns the y coordinate of the top of this component.
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
const Array< Component * > & getChildren() const noexcept
Provides access to the underlying array of child components.
T cend(T... args)
T find(T... args)
T make_tuple(T... args)
T max(T... args)
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
T next(T... args)
T prev(T... args)
T push_back(T... args)
T stable_sort(T... args)