KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
KTech::Widget Class Reference

World structure that comprises Textures, behaves as a user interface element, and exists within UI. More...

#include <widget.hpp>

Inheritance diagram for KTech::Widget:
AboutBox Button Frame IntField StringField Switch

Classes

struct  ChildWidget
 This class is undocumented because it's planned to change (see GitHub issue #106).
 

Public Member Functions

 Widget (Engine &engine, Point position=Point(0, 0), std::string name="")
 Construct a Widget.
 
 Widget (Engine &engine, const ID< UI > &parentUI, Point position=Point(0, 0), std::string name="")
 Construct a Widget and immediately enter a UI.
 
virtual ~Widget ()
 Leave parent UI (if in one) and remove itself from Memory.
 
auto AddWidget (const ID< Widget > &widget) -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto RemoveWidget (const ID< Widget > &widget) -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto RemoveAllWidgets () -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto EnterWidget (const ID< Widget > &widget) -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto EnterUI (const ID< UI > &ui) -> bool
 Enter a UI.
 
auto LeaveWidget () -> bool
 Undocumented due to planned changes (see GitHub issue #106).
 
auto LeaveUI () -> bool
 Leave the parent UI.
 
void Select ()
 Enable input callbacks, and call Widget::OnSelect().
 
void Deselect ()
 Disable input callbacks, and call Widget::OnDisable().
 
void Show ()
 Let UI render this Widget, and call Widget::OnShow().
 
void Hide ()
 Don't let UI render this Widget, and call Widget::OnHide().
 

Public Attributes

Engineengine
 Parent Engine.
 
const ID< Widgetm_id {ID<Widget>::Unique()}
 Personal ID.
 
std::string m_name
 String name.
 
ID< UIm_parentUI
 The UI containing this Widget.
 
ID< Widgetm_parentWidget = nullID<Widget>
 Undocumented because it's planned to change (see GitHub issue #106).
 
std::vector< ChildWidget > m_childWidgets
 Undocumented because it's planned to change (see GitHub issue #106).
 
bool m_selected = false
 true: player input reaches the Widget. false: player input doesn't.
 
bool m_shown = true
 true: will be rendered by UI. false: will be ignored by UI.
 
Point m_pos
 World position.
 
std::vector< Texturem_textures = {}
 Comprising Textures.
 
Input::CallbackGroup m_callbackGroup
 Group of all input callbacks, which are enabled and disabled in correspondence to Widget::m_selected.
 

Protected Member Functions

virtual auto OnTick () -> bool
 Virtual function called once each tick.
 
virtual void OnSelect ()
 Virtual function called by Widget::Select().
 
virtual void OnDeselect ()
 Virtual function called by Widget::Deselect().
 
virtual void OnShow ()
 Virtual function called by Widget::Show().
 
virtual void OnHide ()
 Virtual function called by Widget::Hide().
 

Friends

class KTech::Memory
 

Detailed Description

World structure that comprises Textures, behaves as a user interface element, and exists within UI.

This and Object are the most commonly inherited-from world structures. Widget differs from Object because it can only contain Textures, while Object can also have Colliders (which are useless in user interfaces). Widget has functionality intended for user interfaces, which is utilized by the optional widgets in the ktech/widgets/ directory.

See also
AboutBox
Button
Frame
IntField
StringField
Switch

Constructor & Destructor Documentation

◆ Widget() [1/2]

KTech::Widget::Widget ( Engine & engine,
Point position = Point(0, 0),
std::string name = "" )

Construct a Widget.

Parameters
engineParent Engine.
positionWorld position.
nameString name.

◆ Widget() [2/2]

KTech::Widget::Widget ( Engine & engine,
const ID< UI > & parentUI,
Point position = Point(0, 0),
std::string name = "" )

Construct a Widget and immediately enter a UI.

Parameters
engineParent Engine.
parentUIThe UI to enter.
positionWorld position.
nameString name.

◆ ~Widget()

KTech::Widget::~Widget ( )
virtual

Leave parent UI (if in one) and remove itself from Memory.

Additional behavior is undocumented due to planned changes (see GitHub issue #106)

Member Function Documentation

◆ Deselect()

void KTech::Widget::Deselect ( )

Disable input callbacks, and call Widget::OnDisable().

Additional behavior is undocumented due to planned changes (see GitHub issue #106).

See also
Widget::OnDisable().

◆ EnterUI()

auto KTech::Widget::EnterUI ( const ID< UI > & ui) -> bool

Enter a UI.

Parameters
uiThe UI to enter.
Returns
true if entered the given UI. false if the given UI is already the parent UI, doesn't exist in Memory, or failed to add this Widget.

◆ Hide()

void KTech::Widget::Hide ( )

Don't let UI render this Widget, and call Widget::OnHide().

Additional behavior is undocumented due to planned changes (see GitHub issue #106).

See also
Widget::OnHide().

◆ LeaveUI()

auto KTech::Widget::LeaveUI ( ) -> bool

Leave the parent UI.

Returns
true if left the UI. false if the parent UI failed to remove this Widget.

◆ OnDeselect()

void KTech::Widget::OnDeselect ( )
protectedvirtual

Virtual function called by Widget::Deselect().

Usually, you would override this function in your Widget-inherited class to make the Textures (Widget::m_textures) seem unselected in contrast to the one selected Widget in your user interface.

See also
Widget::Deselect()
Button::OnDeselect() for example.

◆ OnHide()

void KTech::Widget::OnHide ( )
protectedvirtual

Virtual function called by Widget::Hide().

Widget::Show() sets Widget::m_shown to false (which tells UI to not render this Widget), so, you aren't supposed to override this function to set each Widget::m_textures->Texture::m_active to false. There's no actual reason to override this function to create a complete Widget. However, you may still want to do something when this Widget is hidden (for example, update a state machine).

See also
Widget::Show()

◆ OnSelect()

void KTech::Widget::OnSelect ( )
protectedvirtual

Virtual function called by Widget::Select().

Usually, you would override this function in your Widget-inherited class to make the Textures (Widget::m_textures) seem selected in contrast to the other, unselected, Widgets in your user interface.

See also
Widget::Select()
Button::OnSelect() for example.

◆ OnShow()

void KTech::Widget::OnShow ( )
protectedvirtual

Virtual function called by Widget::Show().

Widget::Show() sets Widget::m_shown to true (which lets UI render this Widget), so, you aren't supposed to override this function to set each Widget::m_textures->Texture::m_active to true. There's no actual reason to override this function to create a complete Widget. However, you may still want to do something when this Widget is shown (for example, a visual effect).

See also
Widget::Show()

◆ OnTick()

auto KTech::Widget::OnTick ( ) -> bool
protectedvirtual

Virtual function called once each tick.

Called by Memory::CallOnTicks().

Returns
bool value, which is explained in Output::ShouldRenderThisTick().
See also
Memory::CallOnTicks()
Output::ShouldRenderThisTick()

◆ Select()

void KTech::Widget::Select ( )

Enable input callbacks, and call Widget::OnSelect().

Additional behavior is undocumented due to planned changes (see GitHub issue #106).

See also
Widget::OnSelect().

◆ Show()

void KTech::Widget::Show ( )

Let UI render this Widget, and call Widget::OnShow().

Additional behavior is undocumented due to planned changes (see GitHub issue #106).

See also
Widget::OnShow().

The documentation for this class was generated from the following files: