10 #include "tb_geometry.h"
12 #include "tb_linklist.h"
13 #include "tb_widget_value.h"
14 #include "tb_object.h"
15 #include "tb_font_desc.h"
23 class TBWidgetListener;
24 class TBLongClickTimer;
55 EVENT_TYPE_POINTER_DOWN,
56 EVENT_TYPE_POINTER_UP,
57 EVENT_TYPE_POINTER_MOVE,
60 EVENT_TYPE_MULTI_GESTURE,
62 EVENT_TYPE_FINGER_DOWN,
64 EVENT_TYPE_FINGER_MOVE,
99 MAKE_ENUM_FLAG_COMBO(MODIFIER_KEYS);
103 TB_KEY_UNDEFINED = 0,
104 TB_KEY_UP, TB_KEY_DOWN, TB_KEY_LEFT, TB_KEY_RIGHT,
105 TB_KEY_PAGE_UP, TB_KEY_PAGE_DOWN, TB_KEY_HOME, TB_KEY_END,
106 TB_KEY_TAB, TB_KEY_BACKSPACE, TB_KEY_INSERT, TB_KEY_DELETE,
107 TB_KEY_ENTER, TB_KEY_ESC,
108 TB_KEY_F1, TB_KEY_F2, TB_KEY_F3, TB_KEY_F4, TB_KEY_F5, TB_KEY_F6,
109 TB_KEY_F7, TB_KEY_F8, TB_KEY_F9, TB_KEY_F10, TB_KEY_F11, TB_KEY_F12
127 SPECIAL_KEY special_key;
130 MODIFIER_KEYS modifierkeys;
138 key(0), special_key(TB_KEY_UNDEFINED), modifierkeys(TB_MODIFIER_NONE),
touch(false) {}
142 count(1),
key(0), special_key(TB_KEY_UNDEFINED), modifierkeys(modifierkeys),
150 bool IsPointerEvent()
const {
return type == EVENT_TYPE_POINTER_DOWN ||
151 type == EVENT_TYPE_POINTER_UP ||
152 type == EVENT_TYPE_POINTER_MOVE; }
153 bool IsKeyEvent()
const {
return type == EVENT_TYPE_KEY_DOWN ||
154 type == EVENT_TYPE_KEY_UP; }
171 :
TBWidgetEvent(EVENT_TYPE_MULTI_GESTURE, target_x, target_y, 1),
198 :
TBWidgetEvent(type, target_x, target_y, 1), x(x), y(y), dx(dx), dy(dy)
220 WIDGET_STATE_NONE = 0,
221 WIDGET_STATE_DISABLED = 1,
222 WIDGET_STATE_FOCUSED = 2,
223 WIDGET_STATE_PRESSED = 4,
224 WIDGET_STATE_SELECTED = 8,
225 WIDGET_STATE_HOVERED = 16,
227 WIDGET_STATE_ALL = WIDGET_STATE_DISABLED |
228 WIDGET_STATE_FOCUSED |
229 WIDGET_STATE_PRESSED |
230 WIDGET_STATE_SELECTED |
238 WIDGET_GRAVITY_NONE = 0,
239 WIDGET_GRAVITY_LEFT = 1,
240 WIDGET_GRAVITY_RIGHT = 2,
241 WIDGET_GRAVITY_TOP = 4,
242 WIDGET_GRAVITY_BOTTOM = 8,
244 WIDGET_GRAVITY_LEFT_RIGHT = WIDGET_GRAVITY_LEFT | WIDGET_GRAVITY_RIGHT,
245 WIDGET_GRAVITY_TOP_BOTTOM = WIDGET_GRAVITY_TOP | WIDGET_GRAVITY_BOTTOM,
246 WIDGET_GRAVITY_ALL = WIDGET_GRAVITY_LEFT_RIGHT | WIDGET_GRAVITY_TOP_BOTTOM,
247 WIDGET_GRAVITY_DEFAULT = WIDGET_GRAVITY_LEFT | WIDGET_GRAVITY_TOP
281 , max_w(10000),
max_h(10000)
301 static const int UNSPECIFIED = TB_INVALID_DIMENSION;
303 , max_w(UNSPECIFIED),
max_h(UNSPECIFIED)
304 , pref_w(UNSPECIFIED),
pref_h(UNSPECIFIED) {}
310 void SetWidth(
int width) { min_w = max_w = pref_w = width; }
324 static const int NO_RESTRICTION = 10000;
339 available_h == NO_RESTRICTION ? NO_RESTRICTION : available_h - vertical_padding);
346 ConstrainByLPMax(available_h, lp.
min_h, lp.
max_h));
350 available_h == sc.available_h; }
353 int ConstrainByLPMax(
int constraint,
int lp_min,
int lp_max)
const
355 if (constraint == NO_RESTRICTION)
356 return lp_max != LayoutParams::UNSPECIFIED ? lp_max : NO_RESTRICTION;
357 int ret = constraint;
358 if (lp_min != LayoutParams::UNSPECIFIED)
359 ret = MAX(ret, lp_min);
360 if (lp_max != LayoutParams::UNSPECIFIED)
361 ret = MIN(ret, lp_max);
385 enum WIDGET_INVOKE_INFO {
386 WIDGET_INVOKE_INFO_NORMAL,
387 WIDGET_INVOKE_INFO_NO_CALLBACKS
439 void SetSize(
int width,
int height);
496 {
return (T*) GetWidgetByIDInternal(
id, GetTypeId<T>()); }
594 void SetSkinBg(
const TBID &skin_bg, WIDGET_INVOKE_INFO info = WIDGET_INVOKE_INFO_NORMAL);
614 void SetClickByKey(
bool click_by_key) { m_packed.click_by_key = click_by_key; }
620 void SetWantLongClick(
bool want_long_click) { m_packed.want_long_click = want_long_click; }
793 virtual void OnResized(
int old_w,
int old_h);
875 bool CanScrollX()
const {
return max_x > min_x; }
876 bool CanScrollY()
const {
return max_y >
min_y; }
877 bool CanScrollLeft()
const {
return x > min_x; }
878 bool CanScrollRight()
const {
return x < max_x; }
879 bool CanScrollUp()
const {
return y >
min_y; }
880 bool CanScrollDown()
const {
return y <
max_y; }
881 bool CanScroll()
const {
return CanScrollX() || CanScrollY(); }
1035 void InvokePaint(
const PaintProps &parent_paint_props);
1063 bool InvokePointerDown(
int x,
int y,
int click_count, MODIFIER_KEYS modifierkeys,
bool touch);
1065 bool InvokePointerUp(
int x,
int y,
int click_count, MODIFIER_KEYS modifierkeys,
bool touch);
1069 bool InvokeWheel(
int x,
int y,
int delta_x,
int delta_y, MODIFIER_KEYS modifierkeys);
1072 bool InvokeMultiGesture(
float dTheta,
float dDist,
int targetx,
int targety,
float x,
float y, uint16_t numFingers);
1074 bool InvokeFingerMotion(
int x,
int y,
float cx,
float cy,
float dx,
float dy,
int finger);
1076 bool InvokeFingerDown(
int x,
int y,
float cx,
float cy,
float dx,
float dy,
int finger);
1078 bool InvokeFingerUp(
int x,
int y,
float cx,
float cy,
float dx,
float dy,
int finger);
1082 bool InvokeKey(
int key, SPECIAL_KEY special_key, MODIFIER_KEYS modifierkeys,
bool down);
1128 TBID m_skin_bg_expected;
1144 uint16_t is_group_root : 1;
1145 uint16_t is_focusable : 1;
1146 uint16_t click_by_key : 1;
1147 uint16_t has_key_pressed_state : 1;
1148 uint16_t ignore_input : 1;
1149 uint16_t is_dying : 1;
1150 uint16_t is_cached_ps_valid : 1;
1151 uint16_t no_automatic_hover_state : 1;
1152 uint16_t is_panning : 1;
1153 uint16_t want_long_click : 1;
1154 uint16_t visibility : 2;
1155 uint16_t inflate_child_z : 1;
1157 uint16_t m_packed_init;
1170 #ifdef TB_RUNTIME_DEBUG_INFO
1171 double last_measure_time;
1172 double last_layout_time;
1173 #endif // TB_RUNTIME_DEBUG_INFO
1188 void StopLongClickTimer();
1192 TBWidget *FindScrollableWidget(
bool scroll_x,
bool scroll_y);
1194 TBScroller *GetReadyScroller(
bool scroll_x,
bool scroll_y);
1195 TBWidget *GetWidgetByIDInternal(
const TBID &
id,
const TB_TYPE_ID type_id =
nullptr)
const;
1196 void InvokeSkinUpdatesInternal(
bool force_update);
1197 void InvokeProcessInternal();
1198 static void SetHoveredWidget(
TBWidget *widget,
bool touch);
1199 static void SetCapturedWidget(
TBWidget *widget);
1200 void HandlePanningOnMove(
int x,
int y);
1201 void StartLongClickTimer(
bool touch);
1203 void MaybeInvokeLongClickOrContextMenu(
bool touch);
1212 #endif // TB_WIDGETS_H
void SetHeight(int height)
Set both min max and preferred height to the given height.
Definition: tb_widgets.h:313
AXIS
Definition: tb_widgets.h:251
TBLinkListOf is a double linked linklist.
Definition: tb_linklist.h:122
int max_h
The maximum preferred width and height.
Definition: tb_widgets.h:290
int available_w
The available width and height.
Definition: tb_widgets.h:327
TYPE
The current type of the value.
Definition: tb_value.h:64
int min_h
The minimal preferred width and height.
Definition: tb_widgets.h:315
Before the reference widget (visually behind reference).
Definition: tb_widgets.h:374
WIDGET_VISIBILITY
Defines widget visibility, used with TBWidget::SetVisibility.
Definition: tb_widgets.h:379
SIZE_DEP
Defines how the size in one axis depend on the other axis when a widgets size is affected by constrai...
Definition: tb_widgets.h:259
The width is dependant on the height.
Definition: tb_widgets.h:263
TBFontFace represents a loaded font that can measure and render strings.
Definition: tb_font_renderer.h:142
The widget was hit, any child may be hit too.
Definition: tb_widgets.h:400
The toplevel (Visually drawn on top of everything else).
Definition: tb_widgets.h:368
WIDGET_GRAVITY
TBWidget gravity (may be combined).
Definition: tb_widgets.h:237
The bottomlevel (Visually drawn behind everything else).
Definition: tb_widgets.h:369
WIDGET_FOCUS_REASON
Definition: tb_widgets.h:390
LayoutParams defines size preferences for a TBWidget that are set on the widget to override size pref...
Definition: tb_widgets.h:298
The height is dependant on the width.
Definition: tb_widgets.h:265
TBWindow is a TBWidget that provides some window-like features.
Definition: tb_window.h:33
Simple point class.
Definition: tb_geometry.h:15
Vertical layout.
Definition: tb_widgets.h:253
Click event is what should be used to trig actions in almost all cases.
Definition: tb_widgets.h:45
Set focus by navigation (i.e.
Definition: tb_widgets.h:391
int min_h
The minimal preferred width and height.
Definition: tb_widgets.h:289
WIDGET_Z
Defines widget z level, used with TBWidget::SetZ, TBWidget::AddChild.
Definition: tb_widgets.h:367
int pref_h
The preferred width and height.
Definition: tb_widgets.h:291
Invoked by the platform when one or multiple files has been dropped on the widget.
Definition: tb_widgets.h:86
int max_h
The maximum preferred width and height.
Definition: tb_widgets.h:316
Specifies size constraints used during size calculations.
Definition: tb_widgets.h:321
Horizontal layout.
Definition: tb_widgets.h:252
Invisible and no layout. Interaction disabled.
Definition: tb_widgets.h:382
Skin element.
Definition: tb_skin.h:168
Invoked when a context menu should be opened at the event x and y coordinates.
Definition: tb_widgets.h:82
WIDGET_Z_REL
Defines widget z level relative to another widget, used with TBWidget::AddChildRelative.
Definition: tb_widgets.h:373
Set focus by pointer (i.e. clicking)
Definition: tb_widgets.h:393
TBID is a wrapper for a uint32_t to be used as ID.
Definition: tb_id.h:18
Both width and height are dependant on each other.
Definition: tb_widgets.h:268
Typed iterator for safe iteration.
Definition: tb_linklist.h:165
Custom event.
Definition: tb_widgets.h:89
void SetWidth(int width)
Set both min max and preferred width to the given width.
Definition: tb_widgets.h:310
TBListAutoDeleteOf is a list (array) of pointers to the specified object type.
Definition: tb_list.h:118
After the reference widget (visually above reference).
Definition: tb_widgets.h:375
SizeConstraints ConstrainByPadding(int horizontal_padding, int vertical_padding) const
Return new constraints reduced by the given padding.
Definition: tb_widgets.h:336
WIDGET_HIT_STATUS
Hit status return value for TBWidget::GetHitStatus.
Definition: tb_widgets.h:398
Definition: tb_object.h:21
Invoked after changing text in a TBTextField, changing selected item in a TBSelectList etc...
Definition: tb_widgets.h:68
TB_ALIGN
Definition: tb_widgets.h:29
INFLATE_INFO contains info passed to TBWidget::OnInflate during resource loading. ...
Definition: tb_widgets_reader.h:21
EVENT_TYPE
Definition: tb_widgets.h:36
Invoked by the platform when a standard keyboard shortcut is pressed.
Definition: tb_widgets.h:77
The widget was not hit.
Definition: tb_widgets.h:399
int pref_h
The preferred width and height.
Definition: tb_widgets.h:317
TBStr is a simple string class.
Definition: tb_str.h:62
No dependency (Faster layout).
Definition: tb_widgets.h:261
Align to the bottom (below)
Definition: tb_widgets.h:33
Simple rectangle class.
Definition: tb_geometry.h:25
Invisible, but layouted. Interaction disabled.
Definition: tb_widgets.h:381
Align to the right side.
Definition: tb_widgets.h:32
Visible (default)
Definition: tb_widgets.h:380
TBValue holds value of a specific type.
Definition: tb_value.h:59
Align to the left side.
Definition: tb_widgets.h:30
Definition: tb_linklist.h:83
TBColor contains a 32bit color.
Definition: tb_color.h:21
Stores the information needed for checking a condition.
Definition: tb_skin.h:91
SIZE_DEP size_dependency
The size dependency when size is affected by constraints.
Definition: tb_widgets.h:292
TBFontDescription describes a font.
Definition: tb_font_desc.h:18
The widget was hit, no children should be hit.
Definition: tb_widgets.h:401
PreferredSize contains size preferences for a TBWidget.
Definition: tb_widgets.h:277
Depth.
Definition: tb_widgets.h:254
SizeConstraints(int w, int h)
Constrain to the given width and height.
Definition: tb_widgets.h:330
SizeConstraints()
No constraints.
Definition: tb_widgets.h:333
Set focus by anything else.
Definition: tb_widgets.h:394
SizeConstraints ConstrainByLayoutParams(const LayoutParams &lp) const
Return new constraints that are constrained by LayoutParams.
Definition: tb_widgets.h:343
One shot timer for long click event.
Definition: tb_widgets.cpp:39
WIDGET_STATE
TBWidget state types (may be combined).
Definition: tb_widgets.h:219
Long click event is sent when the pointer has been down for some time without moving much...
Definition: tb_widgets.h:54
Align to the top (above)
Definition: tb_widgets.h:31