Gorgon Game Engine
ComponentStackWidget.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Widget.h"
4 #include "ComponentStack.h"
5 #include "WidgetContainer.h"
6 
7 namespace Gorgon { namespace UI {
8 
9 
14  class ComponentStackWidget : public Widget {
15  public:
16  ComponentStackWidget(const Template &temp, std::map<ComponentTemplate::Tag, std::function<Widget *(const Template &)>> generators = {}) : stack(*new ComponentStack(temp, temp.GetSize(), generators)) { }
17 
19 
21  delete &stack;
22  }
23 
24  using Widget::Move;
25 
26  virtual void Move(const Geometry::Point &location) override {
27  stack.Move(location);
28 
29  if(IsVisible() && HasParent())
30  boundschanged();
31  }
32 
33  using Widget::Resize;
34 
35  virtual void Resize(const Geometry::Size &size) override {
36  stack.Resize(size);
37 
38  if(IsVisible() && HasParent())
39  boundschanged();
40  }
41 
42  virtual Geometry::Point GetLocation() const override {
43  return stack.GetLocation();
44  }
45 
46  virtual Geometry::Size GetSize() const override {
47  return stack.GetSize();
48  }
49 
50  virtual void SetEnabled(bool value) override {
51  if(enabled == value)
52  return;
53 
54  enabled = value;
55 
56  if(!value) {
58  if(HasParent() && IsFocused()) {
59  GetParent().FocusNext();
60  if(IsFocused())
62  }
63  }
64  else {
65  if(!HasParent() || GetParent().IsEnabled()) {
67  }
68  }
69  }
70 
71  virtual bool IsEnabled() const override {
72  return enabled;
73  }
74 
75  protected:
76  ComponentStack &stack; //allocate on heap due to its size.
77 
78  bool enabled = true;
79  bool parentenabled = true;
80 
82  virtual void parentenabledchanged(bool state) override {
83  if(enabled && !state) {
85  }
86  else if(enabled && state) {
88  }
89 
90  parentenabled = state;
91  }
92 
93  virtual void focused() override {
96  FocusEvent();
97  }
98 
99  virtual void focuslost() override {
102  FocusEvent();
103  }
104 
105  virtual void removed() override {
106  Widget::removed();
107 
109  }
110 
111  virtual void addto(Layer &layer) override {
112  layer.Add(stack);
113  }
114 
115 
116  virtual void removefrom(Layer &layer) override {
117  layer.Remove(stack);
118  }
119 
120 
121  virtual void setlayerorder(Layer &, int order) override {
122  stack.PlaceBefore(order);
123  }
124 
125  private:
126  virtual void show() override {
127  stack.Show();
128 
129  if(HasParent())
130  boundschanged();
131  }
132 
133  virtual void hide() override {
134  stack.Hide();
135 
136  if(HasParent())
137  boundschanged();
138  }
139  };
140 
141 } }
Gorgon::UI::Widget::HasParent
bool HasParent() const
Returns if this widget has a parent.
Definition: Widget.h:140
Gorgon::UI::Disabled
@ Disabled
Component is visible when the widget is disabled.
Definition: Template.h:184
Gorgon::UI::ComponentStackWidget::stack
ComponentStack & stack
Definition: ComponentStackWidget.h:76
Widget.h
Gorgon::UI::Widget::focused
virtual void focused()
This is called after the focus is transferred to this widget.
Definition: Widget.cpp:102
Gorgon::UI::ComponentStack
Component stack is the backbone of a widget.
Definition: ComponentStack.h:25
Gorgon::Layer::Add
void Add(Layer &layer)
Adds the given layer as a child.
Definition: Layer.cpp:23
ComponentStack.h
Gorgon::Layer::GetLocation
Geometry::Point GetLocation() const
Returns the current location of the layer.
Definition: Layer.h:403
Gorgon::UI::Widget::Move
void Move(int x, int y)
Moves this widget to the given position.
Definition: Widget.h:45
Gorgon::UI::ComponentStackWidget::IsEnabled
virtual bool IsEnabled() const override
Returns whether the widget is enabled.
Definition: ComponentStackWidget.h:71
Gorgon::UI::ComponentStackWidget::GetSize
virtual Geometry::Size GetSize() const override
Returns the size of the widget.
Definition: ComponentStackWidget.h:46
Gorgon::UI::Widget::FocusEvent
Event< Widget > FocusEvent
This event will be fired when the widget receives or looses focus.
Definition: Widget.h:174
Gorgon::UI::Template
This class stores visual information about a widget template.
Definition: Template.h:392
Gorgon::UI::ComponentStackWidget::parentenabledchanged
virtual void parentenabledchanged(bool state) override
This function is called when the parent's enabled state changes.
Definition: ComponentStackWidget.h:82
Gorgon::UI::ComponentStackWidget::focused
virtual void focused() override
This is called after the focus is transferred to this widget.
Definition: ComponentStackWidget.h:93
Gorgon::UI::ComponentStackWidget::ComponentStackWidget
ComponentStackWidget(ComponentStackWidget &&)=default
Gorgon::UI::Widget::removed
virtual void removed()
Called after this widget is removed from its parent.
Definition: Widget.cpp:83
Gorgon::UI::ComponentStackWidget::enabled
bool enabled
Definition: ComponentStackWidget.h:78
Gorgon::UI::ComponentStackWidget::removefrom
virtual void removefrom(Layer &layer) override
When called, widget should remove itself from the given layer.
Definition: ComponentStackWidget.h:116
Gorgon::UI::Template::GetSize
Geometry::Size GetSize() const
Returns the size of the template.
Definition: Template.h:520
Gorgon::UI::ComponentStack::RemoveCondition
void RemoveCondition(ComponentCondition condition, bool transition=true)
Removes a condition and its associated components.
Definition: ComponentStack.h:54
Gorgon::UI::Widget::Resize
virtual void Resize(int w, int h)
Changes the size of the widget.
Definition: Widget.h:54
Gorgon::UI::ComponentStackWidget::Move
virtual void Move(const Geometry::Point &location) override
Moves this widget to the given position.
Definition: ComponentStackWidget.h:26
Gorgon::UI::ComponentStackWidget::~ComponentStackWidget
virtual ~ComponentStackWidget()
Definition: ComponentStackWidget.h:20
Gorgon::UI::Widget::GetParent
WidgetContainer & GetParent() const
Returns the parent of this widget, throws if it does not have a parent.
Definition: Widget.cpp:30
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::basic_Size
This class represents a 2D geometric size.
Definition: Size.h:23
Gorgon::UI::ComponentStackWidget::SetEnabled
virtual void SetEnabled(bool value) override
Sets the enabled state of the widget.
Definition: ComponentStackWidget.h:50
Gorgon::Layer::PlaceBefore
void PlaceBefore(int before)
Places this layer before the given index.
Definition: Layer.h:290
Gorgon::UI::ComponentStackWidget::parentenabled
bool parentenabled
Definition: ComponentStackWidget.h:79
Gorgon::UI::ComponentStack::Resize
virtual void Resize(const Geometry::Size &value) override
Notifies the stack about a size change.
Definition: ComponentStack.h:245
Gorgon::UI::WidgetContainer::ForceRemoveFocus
void ForceRemoveFocus()
Forcefully removes the focus from the focused widget.
Definition: WidgetContainer.cpp:347
Gorgon::Layer::Move
virtual void Move(const Geometry::Point &location)
Moves this layer to the given location.
Definition: Layer.h:327
Gorgon::UI::ComponentStackWidget::addto
virtual void addto(Layer &layer) override
When called, widget should locate itself on to this layer.
Definition: ComponentStackWidget.h:111
Gorgon::UI::ComponentStackWidget::GetLocation
virtual Geometry::Point GetLocation() const override
Returns the location of the widget.
Definition: ComponentStackWidget.h:42
Gorgon::Layer::Remove
void Remove(Layer &layer)
Removes the given layer.
Definition: Layer.h:203
Gorgon::Layer
This class is the base class for all layer types.
Definition: Layer.h:79
Gorgon::Geometry::basic_Point
This class represents a 2D point.
Definition: Point.h:32
Gorgon::UI::ComponentStack::AddCondition
void AddCondition(ComponentCondition condition, bool transition=true)
Adds a condition and its associated components to the stack.
Definition: ComponentStack.h:48
Gorgon::UI::ComponentStackWidget::removed
virtual void removed() override
Called after this widget is removed from its parent.
Definition: ComponentStackWidget.h:105
Gorgon::UI::Focused
@ Focused
Widget has the focus.
Definition: Template.h:190
Gorgon::UI::Widget::IsFocused
bool IsFocused() const
Returns if this widget is focused.
Definition: Widget.h:98
Gorgon::UI::Widget::focuslost
virtual void focuslost()
This is called after the focus is lost.
Definition: Widget.cpp:96
Gorgon::Layer::Hide
virtual void Hide()
Hides this layer.
Definition: Layer.h:456
Gorgon::Layer::Show
virtual void Show()
Displays this layer.
Definition: Layer.h:453
Gorgon::UI::ComponentStackWidget::Resize
virtual void Resize(const Geometry::Size &size) override
Changes the size of the widget.
Definition: ComponentStackWidget.h:35
Gorgon::UI::ComponentStackWidget::ComponentStackWidget
ComponentStackWidget(const Template &temp, std::map< ComponentTemplate::Tag, std::function< Widget *(const Template &)>> generators={})
Definition: ComponentStackWidget.h:16
Gorgon::UI::Widget::boundschanged
virtual void boundschanged()
Call this function when the widget bounds is changed.
Definition: Widget.cpp:62
WidgetContainer.h
Gorgon::UI::WidgetContainer::FocusNext
bool FocusNext()
Focuses the next widget that accepts focus.
Definition: WidgetContainer.cpp:141
Gorgon::UI::ComponentStackWidget::setlayerorder
virtual void setlayerorder(Layer &, int order) override
When called, widget should reorder itself in layer hierarchy.
Definition: ComponentStackWidget.h:121
Gorgon::UI::ComponentStackWidget
This class acts as a widget base that uses component stack to handle rendering, resizing and other op...
Definition: ComponentStackWidget.h:14
Gorgon::UI::Widget::IsVisible
bool IsVisible() const
Returns if the widget is visible.
Definition: Widget.h:113
Gorgon::UI::ComponentStack::FinalizeTransitions
void FinalizeTransitions()
Finalizes on-going transitions immediately.
Definition: ComponentStack.cpp:666
Gorgon::UI::ComponentTemplate::Tag
Tag
Tags mark a component to be modified in a way meaningful to specific widgets.
Definition: Template.h:850
Gorgon::UI::ComponentStackWidget::focuslost
virtual void focuslost() override
This is called after the focus is lost.
Definition: ComponentStackWidget.h:99
Gorgon::Layer::GetSize
Geometry::Size GetSize() const
Returns the size of the layer.
Definition: Layer.h:362
Gorgon::UI::Widget
This class is the base for all widgets.
Definition: Widget.h:16