Rose
PopupWindow.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include "Button.h"
10 #include "Container.h"
11 #include "Frame.h"
12 #include "Label.h"
13 #include "Signals.h"
14 
15 namespace rose {
16 
22  ActionButtonType mActionButton{};
23  SignalToken mSignalToken{};
24  };
25 
30  class Popup : public Window {
31  protected:
33  std::shared_ptr<Frame> mFrame;
34  std::shared_ptr<Column> mColumn;
35 
36  std::shared_ptr<Slot<Button::SignalType>> mActionButtonRx{};
37  std::shared_ptr<Slot<Button::SignalType>> mDismissButtonRx{};
38 
39  public:
40  Popup() = delete;
41  ~Popup() override = default;
42  Popup(Popup &&) = delete;
43  Popup(const Popup &) = delete;
44  Popup& operator=(Popup &&) = delete;
45  Popup& operator=(const Popup &) = delete;
46 
51  explicit Popup(const shared_ptr <Rose>& parent);
52 
59  Popup(const shared_ptr <Rose>& parent, const Position &position);
60 
67  Popup(const shared_ptr <Rose>& parent, const Position &pos, const Size &minimumSize);
68 
72  void initializeComposite() override;
73 
77  Rectangle widgetLayout(sdl::Renderer &renderer, Rectangle available, uint layoutStage) override;
78 
82  void draw(sdl::Renderer &renderer, Rectangle parentRect) override;
83 
88  void addChild(const std::shared_ptr<Widget>& widget) override {
89  mColumn->addChild(widget);
90  }
91 
98  template<class C>
99  void setActionButtons(C actionButtonList) {
100  std::for_each(actionButtonList.begin(), actionButtonList.end(),
101  [this](const DialogActionButton &dialogActionButton){
102  createActionButton(dialogActionButton);
103  });
104  }
105 
111  virtual void createActionButton(const DialogActionButton &dialogActionButton) {}
112 
119  virtual void setButtonSlot(shared_ptr <Slot<Button::SignalType>> &buttonSlot, bool dismissAll) {
120  mActionButtonRx = buttonSlot;
121  }
122  };
123 
128  class PopupWindow : public Popup {
129  protected:
130  std::string mWindowTitle{};
131  std::shared_ptr<Label> mTitle;
132 
133  public:
134  PopupWindow() = delete;
135  ~PopupWindow() override = default;
136  PopupWindow(PopupWindow &&) = delete;
137  PopupWindow(const PopupWindow &) = delete;
138  PopupWindow& operator=(PopupWindow &&) = delete;
139  PopupWindow& operator=(const PopupWindow &) = delete;
140 
145  explicit PopupWindow(shared_ptr <Rose> parent);
146 
153  PopupWindow(shared_ptr <Rose> parent, const Position &position);
154 
161  PopupWindow(shared_ptr <Rose> parent, const Position &pos, const Size &size);
162 
166  void initializeComposite() override;
167 
168  Rectangle widgetLayout(sdl::Renderer &renderer, Rectangle available, uint layoutStage) override;
169 
174  void setTitle(const std::string &text) override {
175  mTitle->setText(text);
176  setNeedsDrawing();
177  }
178 
180  bool mouseDragEvent(const Position &mousePos, const Position &rel, int button, int modifiers) override;
181  };
182 
188  class Dialog : public PopupWindow {
189  protected:
190  ImageId mBadgeId{};
191  std::shared_ptr<Row> mMessageRow;
192  std::shared_ptr<Row> mButtonRow;
193 
194  public:
195  Dialog() = delete;
196  ~Dialog() override = default;
197  Dialog(Dialog &&) = delete;
198  Dialog(const Dialog &) = delete;
199  Dialog& operator=(Dialog &&) = delete;
200  Dialog& operator=(const Dialog &) = delete;
201 
206  explicit Dialog(shared_ptr <Rose> parent);
207 
214  Dialog(shared_ptr <Rose> parent, const Position &position);
215 
222  Dialog(shared_ptr <Rose> parent, const Position &pos, const Size &size);
223 
227  void initializeComposite() override;
228 
233  void createActionButton(const DialogActionButton &dialogActionButton) override;
234 
241  void setButtonSlot(shared_ptr <Slot<Button::SignalType>> &buttonSlot, bool dismissAll) override;
242  };
243 
248  class ExitDialog : public Dialog {
249  protected:
250  static constexpr std::string_view mExitTitle = "Exit?";
251  static constexpr std::string_view mExitMessage = "Exit the program?";
252  static constexpr std::array<DialogActionButton,2> mActionButtons = {
255  };
256 
257  public:
258  ExitDialog() = delete;
259  ~ExitDialog() override = default;
260  ExitDialog(ExitDialog &&) = delete;
261  ExitDialog(const ExitDialog &) = delete;
262  ExitDialog& operator=(ExitDialog &&) = delete;
263  ExitDialog& operator=(const ExitDialog &) = delete;
264 
269  explicit ExitDialog(shared_ptr <Rose> parent);
270 
277  ExitDialog(shared_ptr <Rose> parent, const Position &position);
278 
285  ExitDialog(shared_ptr <Rose> parent, const Position &pos, const Size &size);
286 
290  void initializeComposite() override;
291 
292  };
293 
298  class UnsavedDialog : public Dialog {
299  protected:
300  static constexpr std::string_view mTitle = "Discard Changes?";
301  static constexpr std::string_view mMessage = "You have unsaved changes, discard them?";
302  static constexpr std::array<DialogActionButton,2> mActionButtons = {
305  };
306 
307  public:
308  UnsavedDialog() = delete;
309  ~UnsavedDialog() override = default;
310  UnsavedDialog(UnsavedDialog &&) = delete;
311  UnsavedDialog(const UnsavedDialog &) = delete;
312  UnsavedDialog& operator=(UnsavedDialog &&) = delete;
313  UnsavedDialog& operator=(const UnsavedDialog &) = delete;
314 
319  explicit UnsavedDialog(shared_ptr <Rose> parent);
320 
327  UnsavedDialog(shared_ptr <Rose> parent, const Position &position);
328 
335  UnsavedDialog(shared_ptr <Rose> parent, const Position &pos, const Size &size);
336 
340  void initializeComposite() override;
341 
342  };
343 }
344 
358 template<class WidgetType, size_t N>
359 inline std::shared_ptr<WidgetType> operator << (std::shared_ptr<WidgetType> &widget,
360  std::array<rose::DialogActionButton,N> &container) {
361  static_assert(std::is_base_of_v<rose::Popup, WidgetType>,
362  "Dialog action buttons are only created on classes derived from rose::Popup." );
363  widget->setActionbuttons(container);
364  return widget;
365 }
366 
375 template<class WidgetType>
376 inline std::shared_ptr<WidgetType> operator << (std::shared_ptr<WidgetType> &widget,
377  std::vector<rose::DialogActionButton> &container) {
378  static_assert(std::is_base_of_v<rose::Popup, WidgetType>,
379  "Dialog action buttons are only created on classes derived from rose::Popup." );
380  widget->setActionbuttons(container);
381  return widget;
382 }
383 
384 template<class WidgetType>
385 inline std::shared_ptr<WidgetType> operator << (std::shared_ptr<WidgetType> &widget,
386  std::shared_ptr<rose::Slot<rose::Button::SignalType>> &rxSlot) {
387  static_assert(std::is_base_of_v<rose::Popup, WidgetType>,
388  "Button Slot can only be set on objects derived from rose::Popup." );
389  widget->setButtonSlot(rxSlot, true);
390  return widget;
391 }
392 
A Dialog specialized to guard the exit path.
Definition: PopupWindow.h:248
void addChild(const std::shared_ptr< Widget > &widget) override
Add a child Widget to the container that will be managing children.
Definition: PopupWindow.h:88
uint32_t SignalToken
A type definition for SignalToken used to identify the source of a Signal.
Definition: Types.h:53
A Window is a visual abstraction of a number of related user interface objects.
Definition: Visual.h:315
ExitDialog Ok ActionButton.
Definition: Constants.h:58
ActionButtonType
Types of Dialog action buttons.
Definition: Constants.h:69
virtual void setButtonSlot(shared_ptr< Slot< Button::SignalType >> &buttonSlot, bool dismissAll)
See Widget::setButtonSlot()
Definition: PopupWindow.h:119
std::shared_ptr< Row > mButtonRow
The area where the Dialog ActionButtons are held.
Definition: PopupWindow.h:192
void setTitle(const std::string &text) override
Set the value of the Window Title.
Definition: PopupWindow.h:174
A Dialog is a way for the application to have a brief conversation with the user. ...
Definition: Popup.h:62
std::shared_ptr< Label > mTitle
The Window Title Label.
Definition: PopupWindow.h:131
A position in integer (x, y) co-ordinates.
Definition: Types.h:95
The data required to creat a DialogActionButton.
Definition: PopupWindow.h:21
A decorated transient Window.
Definition: Popup.h:20
A Dialog specialized to guard the exit path.
Definition: PopupWindow.h:298
std::shared_ptr< Frame > mFrame
The Window Frame.
Definition: PopupWindow.h:33
std::shared_ptr< Column > mColumn
A container for the Window Title gadget and the window Container.
Definition: PopupWindow.h:34
An undecorated window that is transient by nature.
Definition: PopupWindow.h:30
virtual void createActionButton(const DialogActionButton &dialogActionButton)
Create a DialogActionButton on derivatives of Popup that support them.
Definition: PopupWindow.h:111
A composite of a Position and a Size.
Definition: Types.h:307
General Dialog Ok Action Button.
Definition: Constants.h:54
std::shared_ptr< Row > mMessageRow
The area where the Dialog badge and message are held.
Definition: PopupWindow.h:191
Cancel the action described in the dialog.
Definition: Constants.h:71
Written as a workaround for an issue in the SDL2 Library.
Definition: Renderer.h:64
ExitDialog Cancel ActionButton.
Definition: Constants.h:59
A size in integer dimensions.
Definition: Types.h:230
Acknowledge the message or authorize the action described in the dialog.
Definition: Constants.h:70
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
The receiver portion of a Signal-Slot transmitter receiver pair.
Definition: Signals.h:25
Size mMinimumSize
The minimum size requests for the popup if supported by derived types.
Definition: PopupWindow.h:32
Establish an intra-application signaling protocol.
General Dialog Cancel Action Button.
Definition: Constants.h:56
void setActionButtons(C actionButtonList)
Create the DialogActionButton objects.
Definition: PopupWindow.h:99