Rose
Popup.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include "Callbacks.h"
11 #include "StructuredTypes.h"
12 #include "Types.h"
13 #include "Visual.h"
14 #include "GraphicsModel.h"
15 #include "Theme.h"
16 #include "Frame.h"
17 
18 namespace rose {
19 
20  class PopupWindow : public Window {
21  protected:
22  std::shared_ptr<Frame> mContentFrame{};
23  bool mRemovePopup{false};
24 
25  public:
26  PopupWindow() {
27  mModalWindow = true;
28  }
29 
30  ~PopupWindow() override = default;
31 
32  PopupWindow(const PopupWindow&) = delete;
33 
34  PopupWindow(PopupWindow&&) = delete;
35 
36  PopupWindow& operator=(const PopupWindow&) = delete;
37 
38  PopupWindow& operator=(PopupWindow&&) = delete;
39 
40  static constexpr std::string_view id = "PopupWindow";
41  std::string_view nodeId() const noexcept override {
42  return id;
43  }
44 
45  Rectangle layout(gm::Context &context, const Rectangle &screenRect) override {
46  auto rect = screenRect;
47  for (auto &content : (*this)) {
48  if (auto manager = std::dynamic_pointer_cast<Manager>(content); manager) {
49  rect = manager->layout(context, screenRect);
50  manager->setScreenRectangle(rect);
51  }
52  }
53  rect = mPreferredPos;
54  return rect;
55  }
56 
57  constexpr bool removePopup() const noexcept {
58  return mRemovePopup;
59  }
60  };
61 
62  class Dialog : public PopupWindow {
63  protected:
64 
65  public:
66  Dialog() = default;
67 
68  ~Dialog() override = default;
69 
70  Dialog(const PopupWindow&) = delete;
71 
72  Dialog(PopupWindow&&) = delete;
73 
74  explicit Dialog(const Position<int> &position) : PopupWindow() {
75  setPosition(position);
76  }
77 
78  static constexpr std::string_view id = "Dialog";
79  std::string_view nodeId() const noexcept override {
80  return id;
81  }
82 
83  void addedToContainer() override;
84 
85  template<class WidgetClass>
86  void addWidget(std::shared_ptr<WidgetClass> widget) {
87  mContentFrame << widget;
88  }
89  };
90 }
91 
92 template<class WidgetClass>
93 inline std::shared_ptr<WidgetClass> operator<<(std::shared_ptr<rose::Dialog> dialog, std::shared_ptr<WidgetClass> widget) {
94  dialog->addWidget(widget);
95  return widget;
96 }
97 
98 inline std::shared_ptr<rose::Dialog>
99 operator<<(std::shared_ptr<rose::Dialog> dialog, const rose::Position<int> &position) {
100  dialog->setPosition(position);
101  return dialog;
102 }
103 
111 inline std::shared_ptr<rose::PopupWindow>
112 operator<<(std::shared_ptr<rose::PopupWindow> widget, const rose::Position<int> &position) {
113  widget->setPosition(position);
114  return widget;
115 }
A Window is a visual abstraction of a number of related user interface objects.
Definition: Visual.h:315
virtual void addedToContainer()
Called when a Node is added to a Container.
Definition: StructuredTypes.h:206
A Dialog is a way for the application to have a brief conversation with the user. ...
Definition: Popup.h:62
Definitions to support callbacks.
A decorated transient Window.
Definition: Popup.h:20
Context
Definition: GraphicsModel.h:76
Classes and functions used to implement structured data collections.
Abstraction of the graphics model.
A composite of a Position and a Size.
Definition: Types.h:307
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
void setPosition(const Position< int > &position)
Set preferred Position.
Definition: Visual.h:188
User Interface Visual types.
Rectangle layout(gm::Context &context, const Rectangle &screenRect) override
Layout the visual.
Definition: Popup.h:45
Position< int > mPreferredPos
The preferred position.
Definition: Visual.h:136