Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
sidebar.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019-2021 natinusala
3 Copyright 2019 p-sam
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#pragma once
19
20#include <aurore/core/bind.hpp>
21#include <aurore/core/box.hpp>
25
26namespace aurore
27{
28
29class SidebarItem;
30
31class SidebarSeparator : public View
32{
33 public:
35
36 void draw(NVGcontext* vg, float x, float y, float width, float height, Style style, FrameContext* ctx) override;
37};
38
40{
41 public:
42 void add(SidebarItem* item);
44 void clear();
45
46 private:
47 std::vector<SidebarItem*> items;
48};
49
50class SidebarItem : public Box
51{
52 public:
54
55 void onFocusGained() override;
56 void onFocusLost() override;
57
59
60 void setLabel(std::string label);
61
62 void setActive(bool active);
63 bool isActive() const { return this->active; }
64
66
67 protected:
69 std::string getDefaultAccessibilityLabel() override { return this->label->getFullText(); }
70 bool getDefaultAccessibilitySelected() override { return this->active; }
71
72 private:
73 AURORE_BIND(Rectangle, accent, "aurore/sidebar/item_accent");
74 AURORE_BIND(Label, label, "aurore/sidebar/item_label");
75
76 GenericEvent activeEvent;
77
78 SidebarItemGroup* group;
79
80 bool active = false;
81};
82
83class Sidebar : public ScrollingFrame
84{
85 public:
87
92 void addItem(std::string label, GenericEvent::Callback focusCallback);
93
94 SidebarItem* getItem(int position);
95
100
105
106 static View* create();
107
108 private:
109 SidebarItemGroup group;
110
111 Box* contentBox;
112};
113
114} // namespace aurore
#define AURORE_BIND(type, name, id)
Definition bind.hpp:39
Generic FlexBox layout.
Definition box.hpp:74
std::function< void(Ts...)> Callback
Definition event.hpp:43
Definition frame_context.hpp:30
Definition label.hpp:65
std::string getFullText()
The whole text, as set (not cut to fit).
Definition rectangle.hpp:28
Definition scrolling_frame.hpp:45
Definition sidebar.hpp:40
void add(SidebarItem *item)
void setActive(SidebarItem *item)
Definition sidebar.hpp:51
void setActive(bool active)
void setGroup(SidebarItemGroup *group)
bool isActive() const
Definition sidebar.hpp:63
GenericEvent * getActiveEvent()
std::string getDefaultAccessibilityLabel() override
A focusable box says the texts shown in it (getAccessibilityText).
Definition sidebar.hpp:69
bool getDefaultAccessibilitySelected() override
Definition sidebar.hpp:70
void setLabel(std::string label)
AccessibilityRole getDefaultAccessibilityRole() override
Definition sidebar.hpp:68
void onFocusLost() override
void onFocusGained() override
Definition sidebar.hpp:32
void draw(NVGcontext *vg, float x, float y, float width, float height, Style style, FrameContext *ctx) override
Definition sidebar.hpp:84
void addItem(std::string label, GenericEvent::Callback focusCallback)
static View * create()
SidebarItem * getItem(int position)
Simple wrapper around StyleValues for the array operator.
Definition style.hpp:115
Definition view.hpp:232
Definition actions.hpp:25
AccessibilityRole
Definition view_style.hpp:78