Hasty Badger
Small UI library (a branch of Turbo Badger)
|
The base TBWidget class. More...
#include <tb_widgets.h>
Classes | |
class | PaintProps |
PaintProps contains properties needed for painting a widget. More... | |
class | ScrollInfo |
Information about scrolling for a widget at the time of calling GetScrollInfo. More... | |
Public Types | |
enum | INVALIDATE_LAYOUT { INVALIDATE_LAYOUT_TARGET_ONLY, INVALIDATE_LAYOUT_RECURSIVE } |
Type used for InvalidateLayout. More... | |
Public Member Functions | |
TBOBJECT_SUBCLASS (TBWidget, TBTypedObject) | |
For safe typecasting. | |
TBWidget (TBValue::TYPE sync_type=TBValue::TYPE_NULL) | |
virtual | ~TBWidget () |
virtual void | SetRect (const TBRect &rect) |
Set the rect for this widget in its parent. More... | |
const TBRect & | GetRect () const |
See TBWidget::SetRect. | |
void | SetPosition (const TBPoint &pos) |
Set position of this widget in its parent. More... | |
void | SetSize (int width, int height) |
Set size of this widget. More... | |
void | Invalidate () |
Invalidate should be called if the widget need to be repainted, to make sure the renderer repaints it and its children next frame. More... | |
void | InvalidateStates () |
Call if something changes that might need other widgets to update their state. More... | |
void | InvalidateSkinStates () |
Call if something changes that might cause any skin to change due to different state or conditions. More... | |
void | Die () |
Delete the widget with the possibility for some extended life during animations. More... | |
bool | GetIsDying () const |
Return true if this widget or any of its parents is dying. More... | |
void | SetID (const TBID &id) |
Set the id reference for this widgets. More... | |
TBID & | GetID () |
See TBWidget::SetID. | |
const TBID & | GetID () const |
See TBWidget::SetID. | |
void | SetGroupID (const TBID &id) |
Set the group id reference for this widgets. More... | |
TBID & | GetGroupID () |
See TBWidget::SetGroupID. | |
const TBID & | GetGroupID () const |
See TBWidget::SetGroupID. | |
TBWidget * | GetWidgetByID (const TBID &id) const |
Get this widget or any child widget with a matching id, or nullptr if none is found. More... | |
template<class T > | |
T * | GetWidgetByIDAndType (const TBID &id) const |
Get this widget or any child widget with a matching id and type, or nullptr if none is found. More... | |
void | SetState (WIDGET_STATE state, bool on) |
Enable or disable the given state(s). More... | |
bool | GetState (WIDGET_STATE state) const |
Get status of the given state(s). More... | |
void | SetStateRaw (WIDGET_STATE state) |
Set the widget state. More... | |
WIDGET_STATE | GetStateRaw () const |
Get the widget state. More... | |
WIDGET_STATE | GetAutoState () const |
Return the current combined state for this widget. More... | |
void | SetOpacity (float opacity) |
Set opacity for this widget and its children from 0.0 - 1.0. More... | |
float | GetOpacity () const |
See TBWidget::SetOpacity. | |
void | SetVisibility (WIDGET_VISIBILITY vis) |
Set visibility for this widget and its children. More... | |
WIDGET_VISIBILITY | GetVisibility () const |
See TBWidget::SetVisibility. | |
bool | GetVisibilityCombined () const |
Return true if this widget and all its ancestors are visible (has a opacity > 0 and visibility WIDGET_VISIBILITY_VISIBLE) | |
bool | GetDisabled () const |
Return true if this widget or any of its parents are disabled (has state WIDGET_STATE_DISABLED). More... | |
void | AddChild (TBWidget *child, WIDGET_Z z=WIDGET_Z_TOP, WIDGET_INVOKE_INFO info=WIDGET_INVOKE_INFO_NORMAL) |
Add the child to this widget. More... | |
void | AddChildRelative (TBWidget *child, WIDGET_Z_REL z, TBWidget *reference, WIDGET_INVOKE_INFO info=WIDGET_INVOKE_INFO_NORMAL) |
Add the child to this widget. More... | |
void | RemoveChild (TBWidget *child, WIDGET_INVOKE_INFO info=WIDGET_INVOKE_INFO_NORMAL) |
Remove child from this widget without deleting it. More... | |
void | RemoveFromParent () |
Remove this widget from parent if it has one. More... | |
void | DeleteAllChildren () |
Remove and delete all children in this widget. More... | |
void | SetZ (WIDGET_Z z) |
Sets the z-order of this widget related to its siblings. More... | |
void | SetZInflate (WIDGET_Z z) |
Set the z order in which children are added during resource loading. More... | |
WIDGET_Z | GetZInflate () const |
See TBWidget::SetZInflate. | |
void | SetGravity (WIDGET_GRAVITY g) |
Set the widget gravity (any combination of WIDGET_GRAVITY). More... | |
WIDGET_GRAVITY | GetGravity () const |
See TBWidget::SetGravity. | |
void | SetSkinBg (const TBID &skin_bg, WIDGET_INVOKE_INFO info=WIDGET_INVOKE_INFO_NORMAL) |
Set the skin background for this widget and call OnSkinChanged if it changed. More... | |
TBID | GetSkinBg () const |
Return the current skin background, as set by SetSkinBg. More... | |
TBSkinElement * | GetSkinBgElement () |
Return the skin background element, or nullptr. More... | |
void | SetIsGroupRoot (bool group_root) |
Set if this widget is a group root. More... | |
bool | GetIsGroupRoot () const |
See TBWidget::SetIsGroupRoot. | |
void | SetIsFocusable (bool focusable) |
Set if this widget should be able to receive focus or not. More... | |
bool | GetIsFocusable () const |
See TBWidget::SetIsFocusable. | |
void | SetClickByKey (bool click_by_key) |
Set if this widget should emulate a click when it's focused and pressing enter or space. More... | |
bool | GetClickByKey () const |
See TBWidget::SetClickByKey. | |
void | SetWantLongClick (bool want_long_click) |
Set if this widget should generate long-click event (or context menu event if nothing handles the long click event). More... | |
bool | GetWantLongClick () const |
See TBWidget::SetWantLongClick. | |
void | SetIgnoreInput (bool ignore_input) |
Set if this widget should ignore input, as if it didn't exist. More... | |
bool | GetIgnoreInput () const |
See TBWidget::SetIgnoreInput. | |
bool | GetIsInteractable () const |
Get if this widget wants interaction depending on various states. More... | |
bool | SetFocus (WIDGET_FOCUS_REASON reason, WIDGET_INVOKE_INFO info=WIDGET_INVOKE_INFO_NORMAL) |
Set this widget to be the focused widget. More... | |
bool | GetIsFocused () const |
See TBWidget::SetFocus. | |
bool | SetFocusRecursive (WIDGET_FOCUS_REASON reason=WIDGET_FOCUS_REASON_UNKNOWN) |
Call SetFocus on all children and their children, until a widget is found that accepts it. More... | |
bool | MoveFocus (bool forward) |
Move focus from the currently focused widget to another focusable widget. More... | |
TBWidget * | GetWidgetAt (int x, int y, bool include_children) const |
Returns the child widget that contains the coordinate or nullptr if no one does. More... | |
TBWidget * | GetChildFromIndex (int index) const |
Get the child at the given index, or nullptr if there was no child at that index. More... | |
int | GetIndexFromChild (TBWidget *child) const |
Get the child index of the given widget (that must be a child of this widget). More... | |
TBStr | GetTextByID (const TBID &id) |
Get the text of a child widget with the given id, or an empty string if there was no widget with that id. More... | |
int | GetValueByID (const TBID &id) |
Get the value of a child widget with the given id, or 0 if there was no widget with that id. More... | |
TBWidget * | GetNextDeep (const TBWidget *bounding_ancestor=nullptr) const |
Get the next node in depth search of the widget tree. More... | |
TBWidget * | GetPrevDeep () const |
Get the prev node in depth search of the widget tree. More... | |
TBWidget * | GetLastLeaf () const |
Get the last leaf of a depth search of the widget tree. More... | |
TBWidget * | GetFirstChild () const |
Get the widget's first child. More... | |
TBWidget * | GetLastChild () const |
Get the widget's last child. More... | |
TBLinkListOf< TBWidget >::Iterator | GetIteratorForward () |
Create an iterator to iterate through the widget's children, forward. More... | |
TBLinkListOf< TBWidget >::Iterator | GetIteratorBackward () |
Create an iterator to iterate through the widget's children, backward. More... | |
bool | IsAncestorOf (TBWidget *other_widget) const |
Return true if this widget is the same or a ancestor of other_widget. More... | |
bool | IsEventDestinationFor (TBWidget *other_widget) const |
Return true if this widget is the same as other_widget or if other_widget events are going through this widget (See GetEventDestination()) | |
void | AddListener (TBWidgetListener *listener) |
Add a listener to this widget. More... | |
void | RemoveListener (TBWidgetListener *listener) |
See TBWidget::AddListener. | |
bool | HasListener (TBWidgetListener *listener) const |
See TBWidget::AddListener. | |
virtual bool | OnEvent (const TBWidgetEvent &) |
Callback for handling events. More... | |
virtual void | OnProcess () |
Callback for doing anything that might be needed before paint. More... | |
virtual void | OnProcessAfterChildren () |
Callback for doing anything that might be needed before paint. More... | |
virtual void | OnProcessStates () |
Callback for doing state updates that depend on your application state. More... | |
virtual void | OnPaint (const PaintProps &) |
Callback for painting this widget. More... | |
virtual void | OnPaintChildren (const PaintProps &paint_props) |
Callback for painting child widgets. More... | |
virtual void | OnInvalid () |
Callback for when this widget or any of its children have called Invalidate() | |
virtual void | OnSkinChanged () |
Called when the background skin changes by calling SetSkinBg(), or when the skin has changed indirectly after a skin condition changes in a way that may affect layout. More... | |
virtual void | OnFontChanged () |
Called when the font has changed. More... | |
virtual void | OnFocusChanged (bool) |
Called when the focus has changed. More... | |
virtual void | OnVisibilityChanged () |
Called when the visibility has changed. More... | |
virtual void | OnCaptureChanged (bool) |
Called when the capture has changed. More... | |
virtual void | OnChildAdded (TBWidget *) |
Called when a child widget has been added to this widget (before calling OnAdded on child). More... | |
virtual void | OnChildRemove (TBWidget *) |
Called when a child widget is about to be removed from this widget (before calling OnRemove on child). More... | |
virtual void | OnAdded () |
Called when this widget has been added to a parent (after calling OnChildAdded on parent). More... | |
virtual void | OnRemove () |
Called when a this widget has been removed from its parent (after calling OnChildRemove on parent). More... | |
virtual void | OnDie () |
Called when Die() is called on this widget. More... | |
virtual void | OnResized (int old_w, int old_h) |
Called when this widget has been resized. More... | |
virtual void | OnScroll (int, int) |
Called when this widget has been scrolled. More... | |
virtual void | OnInflateChild (TBWidget *child) |
Called just after a child has been inflated into this widget. More... | |
virtual void | OnInflate (const INFLATE_INFO &info) |
Called when this widget is inflated from resources, before any children have been inflated. More... | |
virtual void | OnDeflate (const INFLATE_INFO &info) |
Called when this widget is deflated to a node, before any children have been deflated. More... | |
virtual WIDGET_HIT_STATUS | GetHitStatus (int x, int y) |
Get hit status tests if this widget should be hit at the given coordinate. More... | |
virtual bool | GetCustomSkinCondition (const TBSkinCondition::CONDITION_INFO &) |
Get if skin condition applies to this widget. More... | |
virtual TBWidget * | GetContentRoot () |
Get this widget or a child widget that should be root for other children. More... | |
TBWidget * | GetParentRoot () |
Get this widget or a parent widget that is the absolute root parent. More... | |
TBWindow * | GetParentWindow () |
Get the closest parent widget that is a TBWindow or nullptr if there is none. More... | |
TBWidget * | GetParent () const |
Get the parent widget, or nullptr if this widget is not added. More... | |
virtual TBWidget * | GetEventDestination () |
Get the widget that should receive the events this widget invoke. More... | |
virtual void | GetChildTranslation (int &x, int &y) const |
Return translation the children should have. More... | |
virtual void | ScrollTo (int, int) |
If this is a widget that scroll children (see GetChildTranslation), it should scroll to the coordinates x, y. More... | |
void | ScrollToSmooth (int x, int y) |
Start the TBScroller for this widget and scroll it to the given position. More... | |
void | ScrollBy (int dx, int dy) |
If this is a widget that scroll children (see GetChildTranslation), it will scroll by delta dx, dy relative to its current position. More... | |
void | ScrollBySmooth (int dx, int dy) |
Start the TBScroller for this widget and scroll it by the given delta. More... | |
virtual ScrollInfo | GetScrollInfo () |
If this is a widget that scroll children (see GetChildTranslation), it should return the current scroll information. More... | |
virtual TBWidget * | GetScrollRoot () |
If this widget is implementing ScrollTo and GetScrollInfo but the corresponding GetChildTranslation is implemented on a child, you should return that child from this method. More... | |
void | ScrollByRecursive (int &dx, int &dy) |
Scroll this widget and/or any parent widgets by the given delta. More... | |
void | ScrollIntoViewRecursive () |
Make this widget visible by calling ScrollIntoView on all parent widgets. | |
void | ScrollIntoView (const TBRect &rect) |
If this is a widget that scroll children (see GetChildTranslation), it will scroll so that rect is visible. More... | |
TBScroller * | GetScroller () |
Return the TBScroller set up for this widget, or nullptr if creation failed. More... | |
virtual void | SetAxis (AXIS) |
Set along which axis the content should be layed out. More... | |
virtual AXIS | GetAxis () const |
See TBWidget::SetAxis. | |
virtual void | SetValue (long) |
Set the value of this widget. More... | |
virtual void | SetValue (const TBValue &value) |
See TBWidget::SetValue. | |
virtual long | GetValue () const |
See TBWidget::SetValue. | |
virtual void | SetValueDouble (double value) |
Set the value in double precision. More... | |
virtual double | GetValueDouble () const |
Return the value in double precision. More... | |
virtual bool | SetText (const TBStr &) |
Set the text of this widget. More... | |
virtual bool | GetText (TBStr &text) const |
Get the text of this widget. More... | |
TBStr | GetText () const |
Get the text of this widget. More... | |
void | Connect (TBWidgetValue *value) |
Connect this widget to a widget value. More... | |
void | Unconnect () |
Unconnect, if this widget is connected to a TBWidgetValue. More... | |
const TBWidgetValueConnection & | GetConnection () const |
Get the widget TBWidgetValue. More... | |
virtual TBRect | GetPaddingRect () |
Get the rectangle inside any padding, relative to this widget. More... | |
virtual PreferredSize | OnCalculatePreferredContentSize (const SizeConstraints &constraints) |
Calculate the preferred content size for this widget. More... | |
virtual PreferredSize | OnCalculatePreferredSize (const SizeConstraints &constraints) |
Calculate the preferred size for this widget. More... | |
PreferredSize | GetPreferredSize (const SizeConstraints &constraints) |
Get the PreferredSize for this widget. More... | |
PreferredSize | GetPreferredSize () |
See TBWidget::GetPreferredSize. | |
virtual void | InvalidateLayout (INVALIDATE_LAYOUT il) |
Invalidate layout for this widget so it will be scheduled for relayout. More... | |
void | SetLayoutParams (const LayoutParams &lp) |
Set layout params. More... | |
const LayoutParams * | GetLayoutParams () const |
Get layout params, or nullptr if not specified. More... | |
void | InvokeProcess () |
Invoke OnProcess and OnProcessAfterChildren on this widget and its children. More... | |
void | InvokeProcessStates (bool force_update=false) |
Invoke OnProcessStates on all child widgets, if state processing is needed (InvalidateStates() has been called) | |
void | InvokePaint (const PaintProps &parent_paint_props) |
Invoke paint on this widget and all its children. | |
void | InvokeFontChanged () |
Invoke OnFontChanged on this widget and recursively on any children that inherit the font. More... | |
bool | InvokeEvent (TBWidgetEvent &ev) |
Invoke a event on this widget. More... | |
bool | InvokePointerDown (int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch) |
See TBWidget::InvokeEvent. | |
bool | InvokePointerUp (int x, int y, int click_count, MODIFIER_KEYS modifierkeys, bool touch) |
See TBWidget::InvokeEvent. | |
void | InvokePointerMove (int x, int y, MODIFIER_KEYS modifierkeys, bool touch) |
See TBWidget::InvokeEvent. | |
bool | InvokeWheel (int x, int y, int delta_x, int delta_y, MODIFIER_KEYS modifierkeys) |
See TBWidget::InvokeEvent. | |
bool | InvokeMultiGesture (float dTheta, float dDist, int targetx, int targety, float x, float y, uint16_t numFingers) |
See TBWidget::InvokeEvent. | |
bool | InvokeFingerMotion (int x, int y, float cx, float cy, float dx, float dy, int finger) |
See TBWidget::InvokeEvent. | |
bool | InvokeFingerDown (int x, int y, float cx, float cy, float dx, float dy, int finger) |
See TBWidget::InvokeEvent. | |
bool | InvokeFingerUp (int x, int y, float cx, float cy, float dx, float dy, int finger) |
See TBWidget::InvokeEvent. | |
bool | InvokeKey (int key, SPECIAL_KEY special_key, MODIFIER_KEYS modifierkeys, bool down) |
Invoke the EVENT_TYPE_KEY_DOWN and EVENT_TYPE_KEY_UP events on the currently focused widget. More... | |
void | ReleaseCapture () |
A widget that receive a EVENT_TYPE_POINTER_DOWN event, will stay "captured" until EVENT_TYPE_POINTER_UP is received. More... | |
void | ConvertToRoot (int &x, int &y) const |
Make x and y (relative to this widget) relative to the upper left corner of the root widget. More... | |
void | ConvertFromRoot (int &x, int &y) const |
Make x and y (relative to the upper left corner of the root widget) relative to this widget. More... | |
bool | SetFontDescription (const TBFontDescription &font_desc) |
Set the font description for this widget and any children that inherit the font. More... | |
TBFontDescription | GetFontDescription () const |
Get the font description as set with SetFontDescription. More... | |
TBFontDescription | GetCalculatedFontDescription () const |
Calculate the font description for this widget. More... | |
TBFontFace * | GetFont () const |
Get the TBFontFace for this widget from the current font description (calculated by GetCalculatedFontDescription) | |
void | StopLongClickTimer () |
Public Member Functions inherited from tb::TBTypedObject | |
virtual bool | IsOfTypeId (const TB_TYPE_ID type_id) const |
Returns true if the class or the base class matches the type id. | |
template<class T > | |
T * | SafeCastTo () const |
Returns this object as the given type or nullptr if it's not that type. More... | |
template<class T > | |
bool | IsOfType () const |
Return true if this object can safely be casted to the given type. More... | |
virtual const char * | GetClassName () const |
Get the classname of the object. More... | |
Public Member Functions inherited from tb::TBLinkOf< TBWidget > | |
TBWidget * | GetPrev () const |
TBWidget * | GetNext () const |
Public Member Functions inherited from tb::TBLink | |
bool | IsInList () const |
Return true if the link is currently added to a list. More... | |
Static Public Member Functions | |
static void | SetAutoFocusState (bool on) |
Set if the state WIDGET_STATE_FOCUSED should be set automatically for the focused widget. More... | |
Static Public Member Functions inherited from tb::TBTypedObject | |
template<class T > | |
static TB_TYPE_ID | GetTypeId () |
A static template method that returns a unique id for each type. More... | |
Public Attributes | |
TBValue::TYPE | m_sync_type |
The data type that should be synchronized through TBWidgetValue. More... | |
TBValue | data |
This value is free to use for anything. More... | |
struct { | |
uint16_t is_group_root: 1 | |
uint16_t is_focusable: 1 | |
uint16_t click_by_key: 1 | |
uint16_t has_key_pressed_state: 1 | |
uint16_t ignore_input: 1 | |
uint16_t is_dying: 1 | |
uint16_t is_cached_ps_valid: 1 | |
uint16_t no_automatic_hover_state: 1 | |
uint16_t is_panning: 1 | |
uint16_t want_long_click: 1 | |
uint16_t visibility: 2 | |
uint16_t inflate_child_z: 1 | |
} | m_packed |
uint16_t | m_packed_init |
Public Attributes inherited from tb::TBLink | |
TBLink * | prev |
TBLink * | next |
TBLinkList * | linklist |
Static Public Attributes | |
static TBWidget * | hovered_widget = nullptr |
The currently hovered widget, or nullptr. | |
static TBWidget * | captured_widget = nullptr |
The currently captured widget, or nullptr. | |
static TBWidget * | focused_widget = nullptr |
The currently focused widget, or nullptr. | |
static int | pointer_down_widget_x = 0 |
Pointer x position on down event, relative to the captured widget. | |
static int | pointer_down_widget_y = 0 |
Pointer y position on down event, relative to the captured widget. | |
static int | pointer_move_widget_x = 0 |
Pointer x position on last pointer event, relative to the captured widget (if any) or hovered widget. | |
static int | pointer_move_widget_y = 0 |
Pointer y position on last pointer event, relative to the captured widget (if any) or hovered widget. | |
static bool | cancel_click = false |
true if the pointer up event should not generate a click event. | |
static bool | update_widget_states = true |
true if something has called InvalidateStates() and it still hasn't been updated. | |
static bool | update_skin_states = true |
true if something has called InvalidateSkinStates() and skin still hasn't been updated. | |
static bool | show_focus_state = false |
true if the focused state should be painted automatically. | |
Friends | |
class | TBWidgetListener |
It does iteration of m_listeners for us. | |
class | TBLongClickTimer |
The base TBWidget class.
Subclass this to implement UI controls. Each widget has a background skin (no skin specified by default) which will be used to calculate the default size preferences and padding around the preferred content size.
Note: When you subclass a widget, use the TBOBJECT_SUBCLASS macro to define the type casting functions instead of implementing those manually.
|
virtual |
< A widget must be removed from parent before deleted
void tb::TBWidget::AddChild | ( | TBWidget * | child, |
WIDGET_Z | z = WIDGET_Z_TOP , |
||
WIDGET_INVOKE_INFO | info = WIDGET_INVOKE_INFO_NORMAL |
||
) |
Add the child to this widget.
The child widget will automatically be deleted when this widget is deleted. (If the child isn't removed again with RemoveChild.)
void tb::TBWidget::AddChildRelative | ( | TBWidget * | child, |
WIDGET_Z_REL | z, | ||
TBWidget * | reference, | ||
WIDGET_INVOKE_INFO | info = WIDGET_INVOKE_INFO_NORMAL |
||
) |
Add the child to this widget.
See AddChild for adding a child to the top or bottom. This takes a relative Z and insert the child before or after the given reference widget.
void tb::TBWidget::AddListener | ( | TBWidgetListener * | listener | ) |
Add a listener to this widget.
It should be removed again with RemoveListener before the widget is deleted.
|
inline |
Connect this widget to a widget value.
When this widget invokes EVENT_TYPE_CHANGED, it will automatically update the connected widget value, and any other widgets that may be connected to it.
On connection, the value of this widget will be updated to the value of the given TBWidgetValue.
void tb::TBWidget::ConvertFromRoot | ( | int & | x, |
int & | y | ||
) | const |
Make x and y (relative to the upper left corner of the root widget) relative to this widget.
void tb::TBWidget::ConvertToRoot | ( | int & | x, |
int & | y | ||
) | const |
Make x and y (relative to this widget) relative to the upper left corner of the root widget.
void tb::TBWidget::DeleteAllChildren | ( | ) |
Remove and delete all children in this widget.
Note: This won't invoke Die so there's no chance for widgets to survive or animate. They will be instantly removed and deleted.
void tb::TBWidget::Die | ( | ) |
Delete the widget with the possibility for some extended life during animations.
If any widget listener responds true to OnWidgetDying it will be kept as a child and live until the animations are done, but the widgets and all its children are marked as dying. Dying widgets get no input or focus.
If no widget listener responded, it will be deleted immediately.
WIDGET_STATE tb::TBWidget::GetAutoState | ( | ) | const |
Return the current combined state for this widget.
It will also add some automatic states, such as hovered (if the widget is currently hovered), or pressed etc.
Automatic states: WIDGET_STATE_PRESSED, WIDGET_STATE_HOVERED, WIDGET_STATE_FOCUSED.
Remarks for WIDGET_STATE_FOCUSED: May also be controlled by calling SetAutoFocusState and the define TB_ALWAYS_SHOW_EDIT_FOCUS.
TBFontDescription tb::TBWidget::GetCalculatedFontDescription | ( | ) | const |
Calculate the font description for this widget.
If this widget have unspecified font description, it will be inheritted from parent. If no parent specify any font, the default font description will be returned.
TBWidget * tb::TBWidget::GetChildFromIndex | ( | int | index | ) | const |
Get the child at the given index, or nullptr if there was no child at that index.
Note: Avoid calling this in loops since it does iteration. Consider iterating the widgets directly instead!
|
inlinevirtual |
Return translation the children should have.
Any scrolling of child widgets should be done with this method, by returning the wanted translation.
When reimplementing this, you must also implement ScrollTo and GetScrollInfo so focus-scroll and panning will work automatically when dragging this or any child widget. Note: You can apply the translation on one widget and implement those methods on a parent, by returning this widget from the parents GetScrollRoot().
Reimplemented in tb::TBLayout, tb::TBEditFieldScrollRoot, and tb::TBScrollContainerRoot.
|
inline |
Get the widget TBWidgetValue.
|
inlinevirtual |
Get this widget or a child widget that should be root for other children.
This is useful for widgets having multiple children by default, to specify which one that should get the children.
Reimplemented in tb::TBClickLabel, tb::TBEditField, tb::TBButton, tb::TBSection, tb::TBScrollContainer, and tb::TBTabContainer.
|
inlinevirtual |
Get if skin condition applies to this widget.
This is called when a skin condition has the property PROPERTY_CUSTOM (not a generic one known by skin and the default widget condition context). This can be used to extend the skin conditions support with properties specific to different widgets.
Reimplemented in tb::TBEditField.
bool tb::TBWidget::GetDisabled | ( | ) | const |
Return true if this widget or any of its parents are disabled (has state WIDGET_STATE_DISABLED).
|
inlinevirtual |
Get the widget that should receive the events this widget invoke.
By default the parent.
Reimplemented in tb::TBPopupWindow, and tb::TBMessageWindow.
|
inline |
Get the widget's first child.
|
inline |
Get the font description as set with SetFontDescription.
Use GetCalculatedFontDescription() to get the calculated font description (Inherit from parent widget etc.)
|
virtual |
Get hit status tests if this widget should be hit at the given coordinate.
The default implementation checks the visibility, ignored input flag, rectangle, and disabled status.
Reimplemented in tb::TBResizer, tb::TBButton, tb::TBLayout, tb::TBEditFieldScrollRoot, and tb::TBSimpleLayoutItemWidget.
int tb::TBWidget::GetIndexFromChild | ( | TBWidget * | child | ) | const |
Get the child index of the given widget (that must be a child of this widget).
Note: Avoid calling this in loops since it does iteration. Consider iterating the widgets directly instead!
< Should not happen!
|
inline |
Return true if this widget or any of its parents is dying.
bool tb::TBWidget::GetIsInteractable | ( | ) | const |
Get if this widget wants interaction depending on various states.
Cares about zero opacity, visibility, flag set by SetIgnoreInput, disabled state, and if the widget is currently dying.
|
inline |
Create an iterator to iterate through the widget's children, backward.
|
inline |
Create an iterator to iterate through the widget's children, forward.
|
inline |
Get the widget's last child.
TBWidget * tb::TBWidget::GetLastLeaf | ( | ) | const |
Get the last leaf of a depth search of the widget tree.
|
inline |
Get layout params, or nullptr if not specified.
Note: The layout params has already been applied to the PreferredSize returned from GetPreferredSize so you normally don't need to check these params.
Get the next node in depth search of the widget tree.
|
virtual |
Get the rectangle inside any padding, relative to this widget.
This is the rectangle in which the content should be rendered.
This may be overridden to f.ex deduct space allocated by visible scrollbars managed by this widget. Anything that removes space from the content area.
Reimplemented in tb::TBWindow, and tb::TBScrollContainer.
|
inline |
Get the parent widget, or nullptr if this widget is not added.
TBWidget * tb::TBWidget::GetParentRoot | ( | ) |
Get this widget or a parent widget that is the absolute root parent.
TBWindow * tb::TBWidget::GetParentWindow | ( | ) |
Get the closest parent widget that is a TBWindow or nullptr if there is none.
If this widget is a window itself, this will be returned.
PreferredSize tb::TBWidget::GetPreferredSize | ( | const SizeConstraints & | constraints | ) |
Get the PreferredSize for this widget.
This returns cached data if valid, or calls OnCalculatePreferredSize if needed.
TBWidget * tb::TBWidget::GetPrevDeep | ( | ) | const |
Get the prev node in depth search of the widget tree.
TBScroller * tb::TBWidget::GetScroller | ( | ) |
Return the TBScroller set up for this widget, or nullptr if creation failed.
|
inlinevirtual |
If this is a widget that scroll children (see GetChildTranslation), it should return the current scroll information.
Reimplemented in tb::TBEditField, tb::TBLayout, and tb::TBScrollContainer.
|
inlinevirtual |
If this widget is implementing ScrollTo and GetScrollInfo but the corresponding GetChildTranslation is implemented on a child, you should return that child from this method.
Reimplemented in tb::TBEditField, and tb::TBScrollContainer.
|
inline |
Return the current skin background, as set by SetSkinBg.
TBSkinElement * tb::TBWidget::GetSkinBgElement | ( | ) |
Return the skin background element, or nullptr.
|
inline |
Get status of the given state(s).
Returns true if the given state combination is set.
|
inline |
Get the widget state.
|
inlinevirtual |
Get the text of this widget.
Implemented by most widgets (that has text). returns false if it failed.
Reimplemented in tb::TBClickLabel, tb::TBEditField, tb::TBButton, tb::TBSection, tb::TBWindow, and tb::TBTextField.
|
inline |
Get the text of this widget.
Implemented by most widgets (that has text).
Get the text of a child widget with the given id, or an empty string if there was no widget with that id.
int tb::TBWidget::GetValueByID | ( | const TBID & | id | ) |
Get the value of a child widget with the given id, or 0 if there was no widget with that id.
|
inlinevirtual |
Return the value in double precision.
It only makes sense to use this instead of GetValue() on widgets that store the value as double. F.ex TBScrollBar, TBSlider.
Reimplemented in tb::TBSliderX< VAL_T >, tb::TBScrollBar, tb::TBEditField, and tb::TBTextField.
TBWidget * tb::TBWidget::GetWidgetAt | ( | int | x, |
int | y, | ||
bool | include_children | ||
) | const |
Returns the child widget that contains the coordinate or nullptr if no one does.
If include_children is true, the search will recurse into the childrens children.
Get this widget or any child widget with a matching id, or nullptr if none is found.
|
inline |
Get this widget or any child widget with a matching id and type, or nullptr if none is found.
void tb::TBWidget::Invalidate | ( | ) |
Invalidate should be called if the widget need to be repainted, to make sure the renderer repaints it and its children next frame.
|
virtual |
Invalidate layout for this widget so it will be scheduled for relayout.
Any change to the size preferences for a widget should call this to let parent layout adjust to the change.
Remarks for layout widgets:
Reimplemented in tb::TBLayout, and tb::TBScrollContainer.
void tb::TBWidget::InvalidateSkinStates | ( | ) |
Call if something changes that might cause any skin to change due to different state or conditions.
This is called automatically from InvalidateStates(), when event EVENT_TYPE_CHANGED is invoked, and in various other situations.
void tb::TBWidget::InvalidateStates | ( | ) |
Call if something changes that might need other widgets to update their state.
F.ex if a action availability changes, some widget might have to become enabled/disabled. Calling this will result in a later call to OnProcessStates().
This is done automatically for all invoked events of type: EVENT_TYPE_CLICK, EVENT_TYPE_LONG_CLICK, EVENT_TYPE_CHANGED, EVENT_TYPE_KEYDOWN, EVENT_TYPE_KEYUP.
bool tb::TBWidget::InvokeEvent | ( | TBWidgetEvent & | ev | ) |
Invoke a event on this widget.
This will first check with all registered TBWidgetListener if the event should be dispatched.
If the widgets OnEvent returns false (event not handled), it will continue traversing to GetEventDestination (by default the parent) until a widget handles the event.
Note: When invoking event EVENT_TYPE_CHANGED, this will update the value of other widgets connected to the same group.
Note: Some event types will automatically invalidate states (See InvalidateStates(), InvalidateSkinStates())
Note: Remember that this widgets may be deleted after this call! So if you really must do something after this call and are not sure what the event will cause, use TBWidgetSafePointer to detect self deletion.
void tb::TBWidget::InvokeFontChanged | ( | ) |
Invoke OnFontChanged on this widget and recursively on any children that inherit the font.
bool tb::TBWidget::InvokeKey | ( | int | key, |
SPECIAL_KEY | special_key, | ||
MODIFIER_KEYS | modifierkeys, | ||
bool | down | ||
) |
Invoke the EVENT_TYPE_KEY_DOWN and EVENT_TYPE_KEY_UP events on the currently focused widget.
This will also do some generic key handling, such as cycling focus on tab etc.
void tb::TBWidget::InvokeProcess | ( | ) |
Invoke OnProcess and OnProcessAfterChildren on this widget and its children.
bool tb::TBWidget::IsAncestorOf | ( | TBWidget * | other_widget | ) | const |
Return true if this widget is the same or a ancestor of other_widget.
bool tb::TBWidget::MoveFocus | ( | bool | forward | ) |
Move focus from the currently focused widget to another focusable widget.
It will search for a focusable widget in the same TBWindow (or top root if there is no window) forward or backwards in the widget order.
|
inlinevirtual |
Called when this widget has been added to a parent (after calling OnChildAdded on parent).
Reimplemented in tb::TBDimmer, tb::TBEditField, and tb::TBWindow.
|
virtual |
Calculate the preferred content size for this widget.
This is the size of the actual content. Don't care about padding or other decoration.
Reimplemented in tb::TBClickLabel, tb::TBEditField, tb::TBButton, tb::TBLayout, tb::TBTextField, tb::TBScrollContainer, and tb::TBTabLayout.
|
virtual |
Calculate the preferred size for this widget.
This is the full size of the widget, content + padding + eventual other decoration (but not skin expansion). This is the size that should be used for layouting a widget. The returned PreferredSize also contains minimal size and maximum size.
Reimplemented in tb::TBRadioCheckBox, tb::TBSkinImage, tb::TBSection, and tb::TBWindow.
|
inlinevirtual |
Called when the capture has changed.
Reimplemented in tb::TBButton.
|
inlinevirtual |
Called when a child widget has been added to this widget (before calling OnAdded on child).
Reimplemented in tb::TBWindow, and tb::TBTabLayout.
|
inlinevirtual |
Called when a child widget is about to be removed from this widget (before calling OnRemove on child).
|
virtual |
Called when this widget is deflated to a node, before any children have been deflated.
This will write generic widget properties and add the widget to the node. If overridden, you must call the super implementation.
Reimplemented in tb::TBSliderX< VAL_T >, tb::TBEditField, tb::TBButton, tb::TBLayout, and tb::TBTextField.
|
inlinevirtual |
Called when Die() is called on this widget.
Note: Not called for children to the widget Die() was invoked on even though they are also dying.
Reimplemented in tb::TBMessageWindow, and tb::TBMenuWindow.
|
inlinevirtual |
Callback for handling events.
Return true if the event is handled and should not continue to be handled by any parent widgets.
Reimplemented in tb::TBResizer, tb::TBMover, tb::TBSliderX< VAL_T >, tb::TBScrollBar, tb::TBRadioCheckBox, tb::TBClickLabel, tb::TBEditField, tb::TBButton, tb::TBLayout, tb::TBSelectDropdown, tb::TBWindow, tb::TBSelectList, tb::TBScrollContainer, tb::TBPopupWindow, tb::TBSectionHeader, tb::TBTabContainer, tb::TBMessageWindow, tb::TBInlineSelect, tb::TBMenuWindow, and tb::TBSimpleLayoutItemWidget.
|
inlinevirtual |
Called when the focus has changed.
Reimplemented in tb::TBEditField.
|
inlinevirtual |
Called when the font has changed.
Reimplemented in tb::TBEditField, and tb::TBTextField.
|
virtual |
Called when this widget is inflated from resources, before any children have been inflated.
This will read generic widget properties and add the widget to the hierarchy if it's not already added. If overridden, you must call the super implementation.
Reimplemented in tb::TBSliderX< VAL_T >, tb::TBScrollBar, tb::TBEditField, tb::TBButton, tb::TBLayout, tb::TBSelectDropdown, tb::TBTextField, tb::TBScrollContainer, tb::TBSelectList, tb::TBTabContainer, tb::TBToggleContainer, and tb::TBInlineSelect.
|
virtual |
Called just after a child has been inflated into this widget.
The default implementation will resize the child to it's preferred size and position it according to the gravity. If you implement a layouting widget, you should override this to prevent doing unnecessary measuring.
Reimplemented in tb::TBLayout.
|
inlinevirtual |
Callback for painting this widget.
The skin is already painted and the opacity set to reflect this widgets. This is only called for widgets with a opacity > 0
Reimplemented in tb::TBProgressSpinner, tb::TBEditField, and tb::TBTextField.
|
virtual |
Callback for painting child widgets.
The default implementation is painting all children.
Reimplemented in tb::TBEditField, tb::TBLayout, tb::TBEditFieldScrollRoot, and tb::TBScrollContainerRoot.
|
inlinevirtual |
Callback for doing anything that might be needed before paint.
F.ex Updating invalid layout, formatting text etc.
Reimplemented in tb::TBLayout, tb::TBScrollContainer, tb::TBSelectList, and tb::TBTabContainer.
|
inlinevirtual |
Callback for doing anything that might be needed before paint.
This is called after OnProcess has been called on this widgets children.
Reimplemented in tb::TBSection, and tb::TBSelectList.
|
inlinevirtual |
Callback for doing state updates that depend on your application state.
F.ex setting the disabled state on a widget whose action is currently not available. This callback is called for all widgets before OnProcess if something has called InvalidateStates().
|
inlinevirtual |
Called when a this widget has been removed from its parent (after calling OnChildRemove on parent).
Reimplemented in tb::TBWindow.
|
virtual |
Called when this widget has been resized.
The default implementation move and resize all children according to their gravity.
Reimplemented in tb::TBSliderX< VAL_T >, tb::TBScrollBar, tb::TBEditField, tb::TBLayout, tb::TBWindow, and tb::TBScrollContainer.
|
inlinevirtual |
Called when this widget has been scrolled.
|
inlinevirtual |
Called when the background skin changes by calling SetSkinBg(), or when the skin has changed indirectly after a skin condition changes in a way that may affect layout.
For indirect skin changes, OnSkinChanged is called before validation of layouts is about to happen in InvokeProcess().
Reimplemented in tb::TBButton, tb::TBSelectList, and tb::TBInlineSelect.
|
inlinevirtual |
Called when the visibility has changed.
Note: This is not called when combined visibility change, so it may change visibility because of ancestors without this being called.
void tb::TBWidget::ReleaseCapture | ( | ) |
A widget that receive a EVENT_TYPE_POINTER_DOWN event, will stay "captured" until EVENT_TYPE_POINTER_UP is received.
While captured, all EVENT_TYPE_POINTER_MOVE are sent to it. This method can force release the capture, which may happen, ie. if the TBWidget is removed while captured.
void tb::TBWidget::RemoveChild | ( | TBWidget * | child, |
WIDGET_INVOKE_INFO | info = WIDGET_INVOKE_INFO_NORMAL |
||
) |
Remove child from this widget without deleting it.
|
inline |
Remove this widget from parent if it has one.
void tb::TBWidget::ScrollBy | ( | int | dx, |
int | dy | ||
) |
If this is a widget that scroll children (see GetChildTranslation), it will scroll by delta dx, dy relative to its current position.
void tb::TBWidget::ScrollByRecursive | ( | int & | dx, |
int & | dy | ||
) |
Scroll this widget and/or any parent widgets by the given delta.
dx and dy will be reduced by the amount that was successfully scrolled.
void tb::TBWidget::ScrollBySmooth | ( | int | dx, |
int | dy | ||
) |
Start the TBScroller for this widget and scroll it by the given delta.
Consecutive calls will accumulate the scroll speed.
void tb::TBWidget::ScrollIntoView | ( | const TBRect & | rect | ) |
If this is a widget that scroll children (see GetChildTranslation), it will scroll so that rect is visible.
Rect is relative to this widget.
|
inlinevirtual |
If this is a widget that scroll children (see GetChildTranslation), it should scroll to the coordinates x, y.
This must result in calling OnScroll if scrolling occured.
Reimplemented in tb::TBEditField, tb::TBLayout, and tb::TBScrollContainer.
void tb::TBWidget::ScrollToSmooth | ( | int | x, |
int | y | ||
) |
Start the TBScroller for this widget and scroll it to the given position.
Will cancel any on going smooth scroll operation.
|
static |
Set if the state WIDGET_STATE_FOCUSED should be set automatically for the focused widget.
This value is set to true when moving focus by keyboard, and set to off when clicking with the pointer.
|
inlinevirtual |
Set along which axis the content should be layed out.
Reimplemented in tb::TBSliderX< VAL_T >, tb::TBScrollBar, tb::TBClickLabel, tb::TBButton, tb::TBLayout, tb::TBTabContainer, and tb::TBInlineSelect.
|
inline |
Set if this widget should emulate a click when it's focused and pressing enter or space.
bool tb::TBWidget::SetFocus | ( | WIDGET_FOCUS_REASON | reason, |
WIDGET_INVOKE_INFO | info = WIDGET_INVOKE_INFO_NORMAL |
||
) |
Set this widget to be the focused widget.
It will be the one receiving keyboard input. Widgets can be focused only after enabling it (See SetIsFocusable(true)). Invisible or disabled widgets can not be focused.
If SetFocus is called on a widget in a inactive window, it will succeed (return true), but it won't actually become focused until that window is activated (See TBWindow::SetLastFocus).
Returns true if successfully focused, or if set as last focus in its window.
bool tb::TBWidget::SetFocusRecursive | ( | WIDGET_FOCUS_REASON | reason = WIDGET_FOCUS_REASON_UNKNOWN | ) |
Call SetFocus on all children and their children, until a widget is found that accepts it.
Returns true if some child was successfully focused.
bool tb::TBWidget::SetFontDescription | ( | const TBFontDescription & | font_desc | ) |
Set the font description for this widget and any children that inherit the font.
Setting a unspecified TBFontDescription (no changes made since construction) means it will be inherited from parent (the default).
Returns true and invokes OnFontChanged on all affected widgets, if the font was successfully set.
Returns false and keep the font onchanged if it no matching font exists or fails creation.
void tb::TBWidget::SetGravity | ( | WIDGET_GRAVITY | g | ) |
Set the widget gravity (any combination of WIDGET_GRAVITY).
For child widgets in a layout, the gravity affects how the layout is done depending on the layout settings. For child widgets in a non layout widget, it will do some basic resizing/moving: -left && right: Widget resize horizontally when parent resize. -!left && right: Widget follows the right edge when parent resize. -top && bottom: Widget resize vertically when parent resize. -!top && bottom: Widget follows the bottom edge when parent resize.
|
inline |
Set the group id reference for this widgets.
This id is 0 by default. All widgets with the same group id under the same group root will be automatically changed when one changes its value.
void tb::TBWidget::SetID | ( | const TBID & | id | ) |
Set the id reference for this widgets.
This id is 0 by default. You can use this id to receive the widget from GetWidgetByID (or preferable TBSafeGetByID to avoid dangerous casts).
|
inline |
Set if this widget should ignore input, as if it didn't exist.
|
inline |
Set if this widget should be able to receive focus or not.
|
inline |
Set if this widget is a group root.
Grouped widgets (such as TBRadioButton) will toggle all other widgets with the same group_id under the nearest parent group root. TBWindow is a group root by default.
void tb::TBWidget::SetLayoutParams | ( | const LayoutParams & | lp | ) |
Set layout params.
Calls InvalidateLayout.
void tb::TBWidget::SetOpacity | ( | float | opacity | ) |
Set opacity for this widget and its children from 0.0 - 1.0.
If opacity is 0 (invisible), the widget won't receive any input.
|
inline |
Set position of this widget in its parent.
The position is relative to the parent widget.
|
virtual |
Set the rect for this widget in its parent.
The rect is relative to the parent widget. The skin may expand outside this rect to draw f.ex shadows.
void tb::TBWidget::SetSize | ( | int | width, |
int | height | ||
) |
Set size of this widget.
void tb::TBWidget::SetSkinBg | ( | const TBID & | skin_bg, |
WIDGET_INVOKE_INFO | info = WIDGET_INVOKE_INFO_NORMAL |
||
) |
Set the skin background for this widget and call OnSkinChanged if it changed.
The skin background is used for calculating padding, preferred size etc. if the widget doesn't have any preferences itself.
The skin will be painted according to the current widget state (WIDGET_STATE). If there is no special skin state for WIDGET_STATE_FOCUSED, it will paint the skin element called "generic_focus" (if it exist) after painting all widget children.
It's possible to omit the OnSkinChanged callback using WIDGET_INVOKE_INFO_NO_CALLBACKS.
void tb::TBWidget::SetState | ( | WIDGET_STATE | state, |
bool | on | ||
) |
Enable or disable the given state(s).
The state affects which skin state is used when drawing. Some states are set automatically on interaction. See GetAutoState().
void tb::TBWidget::SetStateRaw | ( | WIDGET_STATE | state | ) |
Set the widget state.
Like SetState but setting the entire state as given, instead of toggling individual states. See SetState for more info on states.
|
inlinevirtual |
Set the text of this widget.
Implemented by most widgets (that has text).
Reimplemented in tb::TBClickLabel, tb::TBEditField, tb::TBButton, tb::TBSection, tb::TBWindow, and tb::TBTextField.
|
inlinevirtual |
Set the value of this widget.
Implemented by most widgets (that has a value). Note: Some widgets also provide special setters with other types (such as double).
Reimplemented in tb::TBSliderX< VAL_T >, tb::TBScrollBar, tb::TBRadioCheckBox, tb::TBProgressSpinner, tb::TBButton, tb::TBSelectDropdown, tb::TBSection, tb::TBSelectList, tb::TBTabContainer, tb::TBToggleContainer, and tb::TBInlineSelect.
|
inlinevirtual |
Set the value in double precision.
It only makes sense to use this instead of SetValue() on widgets that store the value as double. F.ex TBScrollBar, TBSlider.
Reimplemented in tb::TBSliderX< VAL_T >, tb::TBScrollBar, tb::TBEditField, and tb::TBTextField.
void tb::TBWidget::SetVisibility | ( | WIDGET_VISIBILITY | vis | ) |
Set visibility for this widget and its children.
If visibility is not WIDGET_VISIBILITY_VISIBLE, the widget won't receive any input.
|
inline |
Set if this widget should generate long-click event (or context menu event if nothing handles the long click event).
The default is false.
void tb::TBWidget::SetZ | ( | WIDGET_Z | z | ) |
Sets the z-order of this widget related to its siblings.
When a widget is added with AddChild, it will be placed at the top in the parent (Above previously added widget). SetZ can be used to change the order.
|
inline |
Set the z order in which children are added during resource loading.
|
inline |
Unconnect, if this widget is connected to a TBWidgetValue.
TBValue tb::TBWidget::data |
This value is free to use for anything.
It's not used by TBWidget itself. Initially TYPE_NULL.
TBValue::TYPE tb::TBWidget::m_sync_type |
The data type that should be synchronized through TBWidgetValue.