Gorgon Game Engine
ListItem.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../UI/ComponentStackWidget.h"
4 #include "../Property.h"
5 #include "Registry.h"
6 #include "../Graphics/Bitmap.h"
7 
8 #include <limits>
9 
10 namespace Gorgon { namespace Widgets {
11 
33  class ListItem : public virtual UI::ComponentStackWidget {
34  public:
35 
37  ListItem(const UI::Template &temp);
38 
41  void SetText(const std::string &value);
42 
44  std::string GetText() const {
45  return text;
46  }
47 
48 
50  void SetIndex(long value);
51 
53  int GetIndex() const {
54  return index;
55  }
56 
57 
61  void SetIcon(const Graphics::Bitmap &value);
62 
66  void SetIcon(const Graphics::Animation &value);
67 
71 
75 
77  void RemoveIcon();
78 
80  bool HasIcon() const {
81  return icon != nullptr;
82  }
83 
86  const Graphics::Animation &GetIcon() const {
87  if(!HasIcon())
88  throw std::runtime_error("This widget has no icon.");
89 
90  return *icon;
91  }
92 
94  void OwnIcon();
95 
97  void OwnIcon(const Graphics::Animation &value);
98 
100  void OwnIcon(Graphics::Bitmap &&value);
101 
102 
103 
107  void SetSelected(bool value);
108 
110  bool GetSelected() const {
111  return selected;
112  }
113 
114 
117  void SetParity(Parity value);
118 
120  Parity GetParity() const {
121  return parity;
122  }
123 
124 
130  void SetOpened(YesNoUnset value);
131 
134  return opened;
135  }
136 
140  void SetPosition(ItemPosition value);
141 
144  return position;
145  }
146 
147  virtual bool Activate() override;
148 
151 
157 
158 
159  protected:
160  virtual bool allowfocus() const override;
161 
162  private:
163  std::string text;
164 
165  long index = 0;
166 
167  const Graphics::Animation *icon = nullptr;
168  const Graphics::AnimationProvider *iconprov = nullptr;
169  bool ownicon = false;
170 
171  bool focus = false;
172 
173  bool selected = false;
174 
175  Parity parity = Parity::None;
176 
177  YesNoUnset opened = YesNoUnset::Unset;
178 
179  ItemPosition position = ItemPosition::Nowhere;
180 
181  };
182 
183 } }
Gorgon::UI::Last
@ Last
In a list this denotes the item is at the last place.
Definition: Template.h:239
Gorgon::Widgets::ListItem::SetParity
void SetParity(Parity value)
Set odd/even parity of the widget.
Definition: ListItem.cpp:119
Gorgon::UI::ComponentStackWidget::stack
ComponentStack & stack
Definition: ComponentStackWidget.h:76
Gorgon::UI::First
@ First
In a list this denotes the item is at the first place.
Definition: Template.h:233
Gorgon::Widgets::ListItem::OwnIcon
void OwnIcon()
Transfers the ownership of the current icon.
Definition: ListItem.cpp:79
Gorgon::Widgets::ListItem::allowfocus
virtual bool allowfocus() const override
Should return true if the widget can be focused.
Definition: ListItem.cpp:206
Gorgon::UI::Even
@ Even
In lists denotes the item is in even position.
Definition: Template.h:230
Gorgon::Widgets::ListItem::ClickEvent
Event< ListItem > ClickEvent
Fired when the item is clicked. This includes clicks to toggle area.
Definition: ListItem.h:150
Gorgon::UI::ComponentTemplate::Icon
@ Icon
Data will effect the displayed graphics.
Definition: Template.h:678
Gorgon::UI::ComponentStack::SetData
void SetData(ComponentTemplate::DataEffect effect, const std::string &text)
Sets the data for a specific data effect.
Definition: ComponentStack.cpp:725
Gorgon::Event
This class provides event mechanism.
Definition: Event.h:134
Gorgon::ItemPosition
ItemPosition
Defines where an item is located in a list.
Definition: Types.h:158
Gorgon::Graphics::AnimationProvider
A regular drawable animation provider.
Definition: Animations.h:28
Gorgon::Widgets::ListItem
This widget is designed to be used by Listbox, Table, Grid and Treeview.
Definition: ListItem.h:33
Gorgon::UI::ComponentStack::ComponentAt
int ComponentAt(Geometry::Point location)
Returns the index of the component at the given location.
Definition: ComponentStack.h:339
Gorgon::UI::Template
This class stores visual information about a widget template.
Definition: Template.h:392
Gorgon::Widgets::ListItem::GetSelected
bool GetSelected() const
Return selection status.
Definition: ListItem.h:110
Gorgon::Widgets::ListItem::Activate
virtual bool Activate() override
Activates the widget.
Definition: ListItem.cpp:96
Gorgon::Widgets::ListItem::HasIcon
bool HasIcon() const
Returns if the label has an icon.
Definition: ListItem.h:80
Gorgon::UI::Odd
@ Odd
In lists denotes the item is in odd position.
Definition: Template.h:227
Gorgon::UI::Opened
@ Opened
This condition is triggered when the widget is opened like a combobox showing its list part.
Definition: Template.h:213
Gorgon::UI::ComponentTemplate::ToggleTag
@ ToggleTag
Definition: Template.h:871
Gorgon::UI::Closed
@ Closed
This condition is triggered when the widget is closed like a tree view item that is folded,...
Definition: Template.h:220
Gorgon::UI::ComponentStack::RemoveCondition
void RemoveCondition(ComponentCondition condition, bool transition=true)
Removes a condition and its associated components.
Definition: ComponentStack.h:54
Gorgon::UI::ComponentStack::RemoveData
void RemoveData(ComponentTemplate::DataEffect effect)
Removes the data associated with data effect.
Definition: ComponentStack.cpp:759
Gorgon::Widgets::ListItem::GetIndex
int GetIndex() const
Returns the index of the Item in the Listbox.
Definition: ListItem.h:53
Gorgon::UI::ComponentTemplate::Text
@ Text
Works only for TextholderTemplate, data will affect the text that is displayed.
Definition: Template.h:651
ListItem.h
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Widgets::ListItem::SetIconProvider
void SetIconProvider(const Graphics::AnimationProvider &value)
Changes the icon on the label.
Definition: ListItem.cpp:54
Gorgon::ItemPosition::Last
@ Last
Item is the last item.
Gorgon::Graphics::AnimationProvider::CreateAnimation
virtual Animation & CreateAnimation(Gorgon::Animation::ControllerBase &timer) const override=0
This function should create a new animation with the given controller and if owner parameter is set t...
Gorgon::Widgets::ListItem::GetParity
Parity GetParity() const
Returns the odd/even parity.
Definition: ListItem.h:120
Gorgon::Widgets::ListItem::GetText
std::string GetText() const
Returns the currently displayed text.
Definition: ListItem.h:44
Gorgon::Widgets::ListItem::SetIndex
void SetIndex(long value)
Sets the index of the ListItem in the Listbox.
Definition: ListItem.cpp:30
Gorgon::Widgets::ListItem::SetSelected
void SetSelected(bool value)
Sets selection status of the widget.
Definition: ListItem.cpp:104
Gorgon::Graphics::Bitmap
This object contains an bitmap image.
Definition: Bitmap.h:25
Gorgon::UI::ComponentStack::IndexOfTag
int IndexOfTag(ComponentTemplate::Tag tag)
Returns the index of the component with the specified tag.
Definition: ComponentStack.cpp:1437
Gorgon::Widgets::ListItem::GetOpened
YesNoUnset GetOpened() const
Returns whether the item is opened and displaying subitems.
Definition: ListItem.h:133
Gorgon::Widgets::ListItem::GetIcon
const Graphics::Animation & GetIcon() const
Returns the icon on the label.
Definition: ListItem.h:86
Gorgon::Widgets::ListItem::RemoveIcon
void RemoveIcon()
Removes the icon on the label.
Definition: ListItem.cpp:67
Gorgon::Widgets::ListItem::ListItem
ListItem(const UI::Template &temp)
Constructor requires template. ListItem.
Definition: ListItem.cpp:6
Gorgon::Widgets::ListItem::GetPosition
ItemPosition GetPosition() const
Returns the position of this item in the list. This is not automated.
Definition: ListItem.h:143
Gorgon::Animation::Base::DeleteAnimation
virtual void DeleteAnimation() const
Deletes this animation.
Definition: Animation.h:379
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::Widgets::ListItem::ToggleEvent
Event< ListItem > ToggleEvent
If template has a ToggleTag, this will be raised only if that component is clicked.
Definition: ListItem.h:156
Registry.h
Gorgon::UI::ComponentStack::SetClickEvent
void SetClickEvent(std::function< void(ComponentTemplate::Tag, Geometry::Point, Input::Mouse::Button)> handler)
Sets the mouse down event.
Definition: ComponentStack.h:490
Gorgon::Graphics::Animation
A regular drawable animation.
Definition: Animations.h:14
Gorgon::Widgets::ListItem::SetPosition
void SetPosition(ItemPosition value)
Sets the position of this item in the list.
Definition: ListItem.cpp:164
Gorgon::UI::State2
@ State2
Second state of the widget, first state is Always.
Definition: Template.h:201
Gorgon::Widgets::ListItem::SetText
void SetText(const std::string &value)
Changes the text displayed.
Definition: ListItem.cpp:24
Gorgon::Input::Mouse::Middle
@ Middle
Definition: Mouse.h:35
Gorgon::UI::ComponentTemplate::NoTag
@ NoTag
Definition: Template.h:851
Gorgon::YesNoUnset
YesNoUnset
This enumeration helps with systems that has boolen parameters that can be unset/empty.
Definition: Types.h:63
Gorgon::ItemPosition::First
@ First
Item is the first item.
Gorgon::Parity
Parity
Marks the parity as Odd or Even.
Definition: Types.h:151
Gorgon::UI::ComponentStack::GetTemplate
const Template & GetTemplate() const
Returns the template used by this stack.
Definition: ComponentStack.h:256
Gorgon::Parity::None
@ None
Gorgon::UI::ComponentStack::HandleMouse
void HandleMouse(Input::Mouse::Button accepted=Input::Mouse::Button::All)
This function instructs stack to handle mouse to automatically change hover/down states,...
Definition: ComponentStack.cpp:1023
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::Alone
@ Alone
In a list this denotes the item alone.
Definition: Template.h:242
Gorgon::YesNoUnset::Unset
@ Unset
Gorgon::Widgets::ListItem::SetOpened
void SetOpened(YesNoUnset value)
Sets whether the item is opened and displaying subitems.
Definition: ListItem.cpp:141
Gorgon::Widgets::ListItem::SetIcon
void SetIcon(const Graphics::Bitmap &value)
Changes the icon on the label.
Definition: ListItem.cpp:49