Browse Source

Platform: make it possible to create & add a Screen in one step.

pull/364/head
Vladimír Vondruš 7 years ago
parent
commit
206122b405
  1. 5
      doc/changelog.dox
  2. 21
      src/Magnum/Platform/Screen.h
  3. 6
      src/Magnum/Platform/ScreenedApplication.h
  4. 12
      src/Magnum/Platform/ScreenedApplication.hpp

5
doc/changelog.dox

@ -359,6 +359,11 @@ See also:
application implementations that provide such events
- @ref Platform::BasicScreenedApplication is now available also for
@ref Platform::AndroidApplication
- New @ref Platform::BasicScreen::BasicScreen(BasicScreenedApplication<Application>&, PropagatedEvents&)
constructor that directly adds the newly-created screen to an application
in a RAII manner, without needing to explicitly call
@ref Platform::BasicScreenedApplication::addScreen() and
@ref Platform::BasicScreen::setPropagatedEvents() later
@subsubsection changelog-latest-changes-text Text library

21
src/Magnum/Platform/Screen.h

@ -212,8 +212,28 @@ template<class Application> class BasicScreen:
typedef typename BasicScreenedApplication<Application>::TextEditingEvent TextEditingEvent;
#endif
/**
* @brief Construct a detached screen
*
* The screen is not attached to any application, use
* @ref BasicScreenedApplication::addScreen() to add it. Alternatively,
* use @ref BasicScreen(BasicScreenedApplication<Application>&, PropagatedEvents) to
* attach the screen right during the construction.
*/
explicit BasicScreen();
/**
* @brief Construct a screen and attach it to an application
*
* Unlike with @ref BasicScreen(), the screen is added to the
* application already during the construction, removing the need to
* call @ref addScreen() later. This also means @ref focusEvent() is
* not called for the very first time, assuming the screen is put into
* desired state already during construction.
* @see @ref setPropagatedEvents()
*/
explicit BasicScreen(BasicScreenedApplication<Application>& application, PropagatedEvents events);
/* A common use case is a list of screen derivatives, so allow deleting
them through a base pointer */
virtual ~BasicScreen();
@ -227,6 +247,7 @@ template<class Application> class BasicScreen:
* For non-propagated events related event functions are not called.
* No events are propagated by default, call this function in
* @ref focusEvent() and @ref blurEvent() to reflect focus changes.
* @see @ref BasicScreen(BasicScreenedApplication<Application>&, PropagatedEvents)
*/
void setPropagatedEvents(PropagatedEvents events) { _propagatedEvents = events; }

6
src/Magnum/Platform/ScreenedApplication.h

@ -219,6 +219,12 @@ template<class Application> class BasicScreenedApplication:
* added, @ref BasicScreen::focusEvent() is called. If not, neither
* @ref BasicScreen::blurEvent() nor @ref BasicScreen::focusEvent() is
* called (i.e. the screen default state is used).
*
* Alternatively, a screen can be created using the
* @ref BasicScreen::BasicScreen(BasicScreenedApplication<Application>&, PropagatedEvents)
* constructor. In that case, the first @ref BasicScreen::focusEvent()
* is not called, assuming the screen is put into desired state already
* during construction.
*/
BasicScreenedApplication<Application>& addScreen(BasicScreen<Application>& screen);

12
src/Magnum/Platform/ScreenedApplication.hpp

@ -106,6 +106,15 @@ true>::textEditingEvent(TextEditingEvent&) {}
}
template<class Application> BasicScreen<Application>::BasicScreen() = default;
template<class Application> BasicScreen<Application>::BasicScreen(BasicScreenedApplication<Application>& application, PropagatedEvents events) {
/* A superset of this (together with focusEvent()) is done in
BasicScreenedApplication::addScreen() as well. Keep in sync. */
application.Containers::template LinkedList<BasicScreen<Application>>::insert(this);
redraw();
setPropagatedEvents(events);
}
template<class Application> BasicScreen<Application>::~BasicScreen() = default;
template<class Application> void BasicScreen<Application>::focusEvent() {}
@ -140,6 +149,9 @@ template<class Application> BasicScreenedApplication<Application>::BasicScreened
template<class Application> BasicScreenedApplication<Application>::~BasicScreenedApplication() = default;
template<class Application> BasicScreenedApplication<Application>& BasicScreenedApplication<Application>::addScreen(BasicScreen<Application>& screen) {
/* A subset of this (except focusEvent()) is done in
BasicScreen(BasicScreenedApplication&, PropagatedEvents) as well. Keep
in sync. */
Containers::LinkedList<BasicScreen<Application>>::insert(&screen);
if(screens().first() == &screen) screen.focusEvent();
Application::redraw();

Loading…
Cancel
Save