Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
dropdown.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019-2021 natinusala
3 Copyright 2019 p-sam
4 Copyright 2021 XITRIX
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17*/
18
19#pragma once
20
21#include <string>
22#include <aurore/core/box.hpp>
23#include <aurore/core/event.hpp>
25#include <aurore/views/hint.hpp>
27
28namespace aurore
29{
30
31// Fired when the user has selected a value
32//
33// Parameter is either the selected value index
34// or -1 if the user cancelled
35//
36// Assume that the Dropdown is deleted
37// as soon as this function is called
39
40// Allows the user to select between multiple
41// values
42class Dropdown : public Box, private RecyclerDataSource
43{
44 private:
45 AURORE_BIND(RecyclerFrame, recycler, "aurore/dropdown/recycler");
46 AURORE_BIND(Box, header, "aurore/dropdown/header");
47 AURORE_BIND(Label, title, "aurore/dropdown/title_label");
48 AURORE_BIND(Box, content, "aurore/dropdown/content");
49 AURORE_BIND(AppletFrame, applet, "aurore/dropdown/applet");
52 std::vector<std::string> values;
53 int selected;
54 Animatable showOffset = 0;
55 Event<RecyclerCell*> cellFocusDidChangeEvent;
56
57 int numberOfRows(RecyclerFrame* recycler, int section) override;
58 RecyclerCell* cellForRow(RecyclerFrame* recycler, IndexPath index) override;
59 void didSelectRowAt(RecyclerFrame* recycler, IndexPath index) override;
60
61 void offsetTick();
62
63 protected:
65
66 // Said with its title when it opens, before its row.
68 std::string getDefaultAccessibilityLabel() override { return this->title->getFullText(); }
69
70 public:
71 Dropdown(std::string title, std::vector<std::string> values, ValueSelectedEvent::Callback cb, int selected = 0, ValueSelectedEvent::Callback dismissCb = [](int) {});
72
73 void show(std::function<void(void)> cb, bool animate, float animationDuration) override;
74 void hide(std::function<void(void)> cb, bool animated, float animationDuration) override;
75
76 virtual AppletFrame* getAppletFrame() override;
77 virtual View* getParentNavigationDecision(View* from, View* newFocus, FocusDirection direction) override;
78
80 {
81 return &cellFocusDidChangeEvent;
82 }
83
84 bool isTranslucent() override
85 {
86 return true || View::isTranslucent();
87 }
88};
89
90} // namespace aurore
#define AURORE_BIND(type, name, id)
Definition bind.hpp:39
Definition animation.hpp:42
Definition applet_frame.hpp:39
Generic FlexBox layout.
Definition box.hpp:74
Definition dropdown.hpp:43
float getShowAnimationDuration(TransitionAnimation animation) override
Event< RecyclerCell * > * getCellFocusDidChangeEvent()
Definition dropdown.hpp:79
void hide(std::function< void(void)> cb, bool animated, float animationDuration) override
std::string getDefaultAccessibilityLabel() override
A focusable box says the texts shown in it (getAccessibilityText).
Definition dropdown.hpp:68
Dropdown(std::string title, std::vector< std::string > values, ValueSelectedEvent::Callback cb, int selected=0, ValueSelectedEvent::Callback dismissCb=[](int) {})
void show(std::function< void(void)> cb, bool animate, float animationDuration) override
AccessibilityRole getDefaultAccessibilityRole() override
Definition dropdown.hpp:67
bool isTranslucent() override
Definition dropdown.hpp:84
virtual View * getParentNavigationDecision(View *from, View *newFocus, FocusDirection direction) override
virtual AppletFrame * getAppletFrame() override
The AppletFrame the view is in, or nullptr.
Definition event.hpp:41
std::function< void(Ts...)> Callback
Definition event.hpp:43
Definition label.hpp:65
Definition recycler.hpp:66
Definition recycler.hpp:136
Definition recycler.hpp:199
Definition view.hpp:232
virtual bool isTranslucent()
Definition actions.hpp:25
TransitionAnimation
Definition view.hpp:153
AccessibilityRole
Definition view_style.hpp:78
FocusDirection
Focus direction when navigating.
Definition view.hpp:96
Event< int > ValueSelectedEvent
Definition dropdown.hpp:38
Definition recycler.hpp:35