Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
activity.hpp
Go to the documentation of this file.
1/*
2 Copyright 2020 natinusala
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
20#include <aurore/core/view.hpp>
21
22#include <unordered_map>
23
24namespace aurore
25{
26
29#define CONTENT_FROM_XML_RES(x) \
30 aurore::View* createContentView() override { return aurore::View::createFromXMLResource(x); }
32#define CONTENT_FROM_XML_FILE(x) \
33 aurore::View* createContentView() override { return aurore::View::createFromXMLFile(x); }
35#define CONTENT_FROM_XML_STR(x) \
36 aurore::View* createContentView() override { return aurore::View::createFromXMLString(x); }
37
45{
46 public:
50 Activity(View* view);
52 virtual ~Activity();
53
63 void setContentView(View* view);
64
69
86
91 virtual void onContentAvailable() {};
92
95
100 unsigned getContentGeneration() const { return this->contentGeneration; }
101
106 View* getView(std::string id);
107
114 void registerModel(const std::string& name, DataModel* model);
115 void unregisterModel(const std::string& name);
116 DataModel* getModel(const std::string& name);
117
123
128
133 virtual bool isTranslucent();
134
136 virtual void willAppear(bool resetState = false);
138 virtual void willDisappear(bool resetState = false);
140 virtual void onPause() { }
142 virtual void onResume() { }
143
147 void
148 setInFadeAnimation(bool translucent);
149
153 void show(std::function<void(void)> cb, bool animate, float animationDuration);
154
158 void hide(std::function<void(void)> cb, bool animate, float animationDuration);
159
161 bool isHidden();
162
177 ActionIdentifier registerAction(const std::string& hintText, enum ControllerButton button, const ActionListener& actionListener, bool hidden = false, bool allowRepeating = false, enum Sound sound = SOUND_NONE);
178
180 ActionIdentifier registerAction(AuroreKeyCombination key, const ActionListener& actionListener, bool allowRepeating = false);
181
188
198
201
204
206 void setAlpha(float alpha);
207
208 private:
209 std::unordered_map<std::string, DataModel*> models;
210 View* constructorView = nullptr;
211 View* contentView = nullptr;
212 unsigned contentGeneration = 0;
213};
214
215} // namespace aurore
Definition activity.hpp:45
void unregisterAction(ActionIdentifier identifier)
Activity(View *view)
An activity showing view (it then owns it).
ActionIdentifier registerAction(const std::string &hintText, enum ControllerButton button, const ActionListener &actionListener, bool hidden=false, bool allowRepeating=false, enum Sound sound=SOUND_NONE)
virtual View * createContentView()
virtual bool isTranslucent()
virtual void willDisappear(bool resetState=false)
Passed on to the content view when the activity is hidden or popped.
virtual void willAppear(bool resetState=false)
Passed on to the content view when the activity is shown.
View * swapContentView(View *view)
void setContentView(View *view)
DataModel * getModel(const std::string &name)
View * getContentView()
The root of the activity's views, nullptr before it is set.
Activity()
An activity whose content comes from createContentView() when it is pushed.
virtual void onContentAvailable()
Definition activity.hpp:91
virtual ~Activity()
Frees the content view (at the end of the frame).
void registerModel(const std::string &name, DataModel *model)
unsigned getContentGeneration() const
Definition activity.hpp:100
ActionIdentifier registerExitAction(enum ControllerButton button=aurore::BUTTON_START)
void show(std::function< void(void)> cb, bool animate, float animationDuration)
void setAlpha(float alpha)
The content view's opacity.
ActionIdentifier registerAction(AuroreKeyCombination key, const ActionListener &actionListener, bool allowRepeating=false)
The same on a keyboard key, on the content view.
virtual void onPause()
Another activity was pushed over this one.
Definition activity.hpp:140
void onWindowSizeChanged()
Resizes the activity to the window (resizeToFitWindow()).
View * getView(std::string id)
void resizeToFitWindow()
void setInFadeAnimation(bool translucent)
void hide(std::function< void(void)> cb, bool animate, float animationDuration)
virtual float getShowAnimationDuration(TransitionAnimation animation)
View * getDefaultFocus()
The view the focus goes to when the activity is shown: the content view's default.
void unregisterModel(const std::string &name)
virtual void onResume()
The activity over this one was popped: it is on top again.
Definition activity.hpp:142
bool isHidden()
Whether hide() hid the content view.
Definition observable.hpp:222
Definition view.hpp:232
Definition actions.hpp:25
TransitionAnimation
Definition view.hpp:153
int ActionIdentifier
Definition actions.hpp:31
ControllerButton
Definition input.hpp:179
@ BUTTON_START
Definition input.hpp:192
Sound
Definition audio.hpp:23
@ SOUND_NONE
Definition audio.hpp:24
std::function< bool(View *)> ActionListener
Definition actions.hpp:29
Definition actions.hpp:36