Widget

Base class for all widgets.

@dmlwidget
class Widget : MenuItemActionHandler {}

Constructors

this
this()

empty parameter list constructor - for usage by factory

this
this(string ID)

create with ID parameter

Destructor

~this
~this()
Undocumented in source.

Members

Functions

addChild
Widget addChild(Widget item)

adds child, returns added item

addChildren
Widget addChildren(Widget[] items)

adds child, returns added item

addOnCheckChangeListener
Widget addOnCheckChangeListener(bool delegate(Widget, bool) listener)

helper function to add onCheckChangeListener in method chain

addOnClickListener
Widget addOnClickListener(bool delegate(Widget) listener)

helper function to add onCheckChangeListener in method chain

addOnFocusChangeListener
Widget addOnFocusChangeListener(bool delegate(Widget, bool) listener)

helper function to add onFocusChangeListener in method chain

animate
void animate(long interval)

animates window; interval is time left from previous draw, in hnsecs (1/10000000 of second)

applyAlign
void applyAlign(Rect rc, Point sz)

Applies alignment for content of size sz - set rectangle rc to aligned value of content inside of initial value of rc.

applyMargins
void applyMargins(Rect rc)

Helper function: applies margins to rectangle

applyPadding
void applyPadding(Rect rc)

Helper function: applies padding to rectangle

canShowPopupMenu
bool canShowPopupMenu(int x, int y)

returns true if widget can show popup menu (e.g. by mouse right click at point x,y)

cancelLayout
void cancelLayout()
Undocumented in source. Be warned that the author may not have intended to support it.
cancelTimer
void cancelTimer(ulong timerId)

cancel timer - pass value returned from setTimer() as timerId parameter

child
inout(Widget) child(int index)

returns child by index

childById
T childById(string id, bool deepSearch)

find child of specified type T by id, returns null if not found or cannot be converted to type T

childIndex
int childIndex(Widget item)

returns index of widget in child list, -1 if passed widget is not a child of this widget

compareId
bool compareId(string id)

compare widget id with specified value, returs true if matches

createTooltip
Widget createTooltip(int mouseX, int mouseY, uint alignment, int x, int y)

will be called from window once tooltip request timer expired; if null is returned, popup will not be shown; you can change alignment and position of popup here

dispatchAction
bool dispatchAction(Action a)

call to dispatch action

drawFocusRect
void drawFocusRect(DrawBuf buf, Rect rc)

draws focus rectangle, if enabled in styles

executeInUiThread
void executeInUiThread(void delegate() runnable)

execute delegate later in UI thread if this widget will be still available (can be used to modify UI from background thread, or just to postpone execution of action)

fillHorizontal
Widget fillHorizontal()

sets layoutWidth=FILL_PARENT

fillParent
Widget fillParent()

sets layoutWidth=FILL_PARENT and layoutHeight=FILL_PARENT

fillVertical
Widget fillVertical()

sets layoutHeight=FILL_PARENT

findFocusableChild
Widget findFocusableChild(bool defaultOnly)

searches children for first focusable item, returns null if not found

findKeyAction
Action findKeyAction(uint keyCode, uint flags)

map key to action

focusGroupWidget
Widget focusGroupWidget()

find nearest parent of this widget with focusGroup flag, returns topmost parent if no focusGroup flag set to any of parents.

getCursorType
uint getCursorType(int x, int y)

returns mouse cursor type for widget

handleAction
bool handleAction(Action a)

override to handle specific actions

handleActionStateChanged
void handleActionStateChanged()

called when state of action assigned on widget is changed

handleActionStateRequest
bool handleActionStateRequest(Action a)

override to handle specific actions state (e.g. change enabled state for supported actions)

handleCheckChange
void handleCheckChange(bool checked)

override to handle check changes

handleClick
bool handleClick()
Undocumented in source. Be warned that the author may not have intended to support it.
handleDoubleClick
bool handleDoubleClick()
Undocumented in source. Be warned that the author may not have intended to support it.
handleFocusChange
void handleFocusChange(bool focused, bool receivedFocusFromKeyboard)

override to handle focus changes

handleFontChanged
void handleFontChanged()

override to handle font changes

handleMoveFocusUsingKeys
bool handleMoveFocusUsingKeys(KeyEvent event)
Undocumented in source. Be warned that the author may not have intended to support it.
hideSoftKeyboard
void hideSoftKeyboard()
insertChild
Widget insertChild(Widget item, int index)

inserts child at given index, returns inserted item

invalidate
void invalidate()

request redraw

isActionEnabled
bool isActionEnabled(Action action)

override to change popup menu items state

isChild
bool isChild(Widget item, bool deepSearch)

returns true if item is child of this widget (when deepSearch == true - returns true if item is this widget or one of children inside children tree).

isPointInside
bool isPointInside(Point pt)
isPointInside
bool isPointInside(int x, int y)

returns true if point is inside of this widget

layout
void layout(Rect rc)

Set widget rectangle to specified value and layout widget contents. (Step 2 of two phase layout).

measure
void measure(int parentWidth, int parentHeight)

Measure widget according to desired width and height constraints. (Step 1 of two phase layout).

measuredContent
void measuredContent(int parentWidth, int parentHeight, int contentWidth, int contentHeight)

helper function for implement measure() when widget's content dimensions are known

onDraw
void onDraw(DrawBuf buf)

Draw widget at its position to buffer

onEvent
bool onEvent(CustomEvent event)

handle custom event

onKeyEvent
bool onKeyEvent(KeyEvent event)

process key event, return true if event is processed.

onMenuItemAction
bool onMenuItemAction(Action action)
Undocumented in source. Be warned that the author may not have intended to support it.
onMouseEvent
bool onMouseEvent(MouseEvent event)

process mouse event; return true if event is processed by widget.

onThemeChanged
void onThemeChanged()

handle theme change: e.g. reload some themed resources

onTimer
bool onTimer(ulong id)

handle timer; return true to repeat timer event after next interval, false cancel timer

removeAllChildren
void removeAllChildren(bool destroyObj)
Undocumented in source. Be warned that the author may not have intended to support it.
removeChild
Widget removeChild(Widget child)

removes child, returns removed item

removeChild
Widget removeChild(string id)

removes child by ID, returns removed item

removeChild
Widget removeChild(int index)

removes child, returns removed item

requestActionsUpdate
void requestActionsUpdate(bool immediateUpdate)

set action update request flag, will be cleared after redraw

requestLayout
void requestLayout()

request relayout of widget and its children

scheduleTooltip
void scheduleTooltip(long delay, uint alignment, int x, int y)

schedule tooltip

setBoolProperty
bool setBoolProperty(string name, bool value)

set string property value, for ML loaders

setDoubleProperty
bool setDoubleProperty(string name, double value)

set double property value, for ML loaders

setDstringProperty
bool setDstringProperty(string name, dstring value)

set string property value, for ML loaders

setFocus
Widget setFocus(FocusReason reason)

sets focus to this widget or suitable focusable child, returns previously focused widget

setIntProperty
bool setIntProperty(string name, int value)

set int property value, for ML loaders

setRectProperty
bool setRectProperty(string name, Rect value)

set Rect property value, for ML loaders

setStringListValueListProperty
bool setStringListValueListProperty(string propName, StringListValue[] values)

StringListValue list values

setStringProperty
bool setStringProperty(string name, string value)

set string property value, for ML loaders

setTimer
ulong setTimer(long intervalMillis)

set new timer to call onTimer() after specified interval (for recurred notifications, return true from onTimer)

setUIStringListProperty
bool setUIStringListProperty(string propName, UIString[] values)

UIString list values

setUistringProperty
bool setUistringProperty(string name, UIString value)

set string property value, for ML loaders

setWindowFocusedFlag
bool setWindowFocusedFlag(bool flg)
Undocumented in source. Be warned that the author may not have intended to support it.
showPopupMenu
void showPopupMenu(int x, int y)

shows popup menu at (x,y)

showSoftKeyboard
void showSoftKeyboard()

Shows system virtual keyabord where applicable

updateActionState
void updateActionState(bool force)

call to update state for action (if action is assigned for widget)

updateActionState
bool updateActionState(Action a, bool force, bool allowDefault)

ask for update state of some action (unles force=true, checks window flag actionsUpdateRequested), returns true if action state is changed

updateStateFromAction
void updateStateFromAction(Action a)

apply enabled, visibile and checked state for this widget from action's state

Properties

acceleratorMap
ActionMap acceleratorMap [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
action
Action action [@property setter]

action to emit on click

action
Action action [@property setter]

action to emit on click

action
const(Action) action [@property getter]

action to emit on click

alignment
ubyte alignment [@property getter]

returns alignment (combined vertical and horizontal)

alignment
ubyte alignment [@property setter]

sets alignment (combined vertical and horizontal)

alpha
uint alpha [@property getter]

widget drawing alpha value (0=opaque .. 255=transparent)

alpha
uint alpha [@property setter]

set widget drawing alpha value (0=opaque .. 255=transparent)

animating
bool animating [@property getter]

returns true is widget is being animated - need to call animate() and redraw

backgroundColor
uint backgroundColor [@property getter]

returns background color

backgroundColor
uint backgroundColor [@property setter]

set background color for widget - override one from style

backgroundColor
string backgroundColor [@property setter]

set background color for widget - from string like "#5599CC" or "white"

backgroundDrawable
DrawableRef backgroundDrawable [@property getter]

background drawable

backgroundDrawable
DrawableRef backgroundDrawable [@property setter]

background drawable

backgroundImageId
string backgroundImageId [@property getter]

background image id

backgroundImageId
string backgroundImageId [@property setter]

background image id

canCheck
bool canCheck [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
canClick
bool canClick [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
canFocus
bool canFocus [@property getter]

returns true if widget is focusable and visible and enabled

checkable
bool checkable [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
checkable
bool checkable [@property getter]

when true, control supports Checked state

checked
bool checked [@property getter]

get checked state

checked
bool checked [@property setter]

set checked state

childCount
int childCount [@property getter]

returns number of children of this widget

clickable
bool clickable [@property getter]

when true, user can click this control, and get onClick listeners called

clickable
bool clickable [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
enabled
bool enabled [@property getter]

return true if state has State.Enabled flag set

enabled
bool enabled [@property setter]

change enabled state

focusGroup
bool focusGroup [@property setter]

set focus group flag for container widget

focusGroup
bool focusGroup [@property getter]

When focus group is set for some parent widget, focus from one of containing widgets can be moved using keyboard only to one of other widgets containing in it and cannot bypass bounds of focusGroup.

focusGroupFocused
bool focusGroupFocused [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
focusGroupFocused
bool focusGroupFocused [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
focusRectColors
const(uint[]) focusRectColors [@property getter]

returns colors to draw focus rectangle (one for solid, two for vertical gradient) or null if no focus rect should be drawn for style

focusable
bool focusable [@property getter]

whether widget can be focused

focusable
bool focusable [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
focused
bool focused [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
font
FontRef font [@property getter]

returns font set for widget using style or set manually

fontFace
string fontFace [@property getter]

returns font face

fontFace
string fontFace [@property setter]

set font face for widget - override one from style

fontFamily
FontFamily fontFamily [@property getter]

returns font family

fontFamily
FontFamily fontFamily [@property setter]

set font family for widget - override one from style

fontItalic
bool fontItalic [@property getter]

returns font style (italic/normal)

fontItalic
bool fontItalic [@property setter]

set font style (italic/normal) for widget - override one from style

fontSize
int fontSize [@property getter]

returns font size in pixels

fontSize
int fontSize [@property setter]

set font size for widget - override one from style

fontWeight
int fontWeight [@property setter]

set font weight for widget - override one from style

fontWeight
ushort fontWeight [@property getter]

returns font weight

halign
Align halign [@property getter]

returns vertical alignment

hasTooltip
bool hasTooltip [@property getter]

returns true if widget has tooltip to show

height
int height [@property getter]

returns current height of widget in pixels

id
string id [@property getter]

returns widget id, null if not set

id
string id [@property setter]

set widget id

instanceCount
int instanceCount [@property getter]

for debug purposes - number of created widget objects, not yet destroyed

layoutHeight
int layoutHeight [@property setter]

sets layout height options (WRAP_CONTENT, FILL_PARENT, or some constant value)

layoutHeight
int layoutHeight [@property getter]

returns layout height options (WRAP_CONTENT, FILL_PARENT, some constant value or percent but only for one widget in layout)

layoutWeight
int layoutWeight [@property getter]

returns layout weight (while resizing to fill parent, widget will be resized proportionally to this value)

layoutWeight
int layoutWeight [@property setter]

sets layout weight (while resizing to fill parent, widget will be resized proportionally to this value)

layoutWidth
int layoutWidth [@property setter]

sets layout width options (WRAP_CONTENT, FILL_PARENT, or some constant value)

layoutWidth
int layoutWidth [@property getter]

returns layout width options (WRAP_CONTENT, FILL_PARENT, some constant value or percent but only for one widget in layout)

left
int left [@property getter]

returns widget rectangle left position

margins
int margins [@property setter]

set margins for widget with the same value for left, top, right, bottom - override one from style

margins
Rect margins [@property setter]

set margins for widget - override one from style

margins
Rect margins [@property getter]

get margins (between widget bounds and its background)

maxHeight
int maxHeight [@property getter]

returns max height constraint (SIZE_UNSPECIFIED if no constraint set)

maxHeight
int maxHeight [@property setter]

set max height constraint (SIZE_UNSPECIFIED for no constraint)

maxWidth
int maxWidth [@property getter]

returns max width constraint (SIZE_UNSPECIFIED if no constraint set)

maxWidth
int maxWidth [@property setter]

set max width constraint (SIZE_UNSPECIFIED for no constraint)

measuredHeight
measuredHeight [@property getter]

returns measured height (calculated during measure() call)

measuredWidth
measuredWidth [@property getter]

returns measured width (calculated during measure() call)

minHeight
int minHeight [@property getter]

returns min height constraint

minHeight
int minHeight [@property setter]

set max height constraint (0 for no constraint)

minWidth
int minWidth [@property getter]

returns min width constraint

minWidth
int minWidth [@property setter]

set max width constraint (0 for no constraint)

needDraw
bool needDraw [@property getter]

returns true if redraw is required for widget and its children

needLayout
bool needLayout [@property getter]

returns true if layout is required for widget and its children

ownStyle
Style ownStyle [@property getter]

enforces widget's own style - allows override some of style properties

padding
int padding [@property setter]

set padding for widget to the same value for left, top, right, bottom - override one from style

padding
Rect padding [@property setter]

set padding for widget - override one from style

padding
Rect padding [@property getter]

get padding (between background bounds and content of widget)

parent
Widget parent [@property getter]

returns parent widget, null for top level widget

parent
Widget parent [@property setter]

sets parent for widget

popupMenu
MenuItem popupMenu [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
popupMenu
MenuItem popupMenu [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
pos
Rect pos [@property getter]

returns widget rectangle

resetState
uint resetState [@property setter]

remove state flags (set of flags from State enum)

setState
uint setState [@property setter]

add state flags (set of flags from State enum)

state
uint state [@property setter]

set new widget state (set of flags from State enum)

state
uint state [@property getter]

widget state (set of flags from State enum)

stateStyle
const(Style) stateStyle [@property getter]

returns style for current widget state

style
uint style [@property setter]

accessor to style - by lookup in theme by styleId (if style id is not set, theme base style will be used).

style
const(Style) style [@property getter]

accessor to style - by lookup in theme by styleId (if style id is not set, theme base style will be used).

styleId
string styleId [@property setter]

set widget style id

styleId
string styleId [@property getter]

returns widget style id, null if not set

tabOrder
ushort tabOrder [@property getter]

tab order - hint for focus movement using Tab/Shift+Tab

tabOrder
ushort tabOrder [@property setter]
Undocumented in source. Be warned that the author may not have intended to support it.
text
UIString text [@property setter]

sets widget content text (override to support this)

text
dstring text [@property setter]

sets widget content text (override to support this)

text
dstring text [@property getter]

returns widget content text (override to support this)

textColor
string textColor [@property setter]

set text color for widget - from string like "#5599CC" or "white"

textColor
uint textColor [@property setter]

set text color (ARGB 32 bit value)

textColor
uint textColor [@property getter]

get text color (ARGB 32 bit value)

textFlags
uint textFlags [@property setter]

set text flags (bit set of TextFlag enum values)

textFlags
uint textFlags [@property getter]

get text flags (bit set of TextFlag enum values)

tooltipText
dstring tooltipText [@property getter]

tooltip text - when not empty, widget will show tooltips automatically; for advanced tooltips - override hasTooltip and createTooltip

tooltipText
dstring tooltipText [@property setter]

tooltip text - when not empty, widget will show tooltips automatically; for advanced tooltips - override hasTooltip and createTooltip

tooltipText
UIString tooltipText [@property setter]

tooltip text - when not empty, widget will show tooltips automatically; for advanced tooltips - override hasTooltip and createTooltip

top
int top [@property getter]

returns widget rectangle top position

trackHover
bool trackHover [@property setter]

set new trackHover flag value (when true, widget will change Hover state while mouse is moving)

trackHover
bool trackHover [@property getter]

mouse movement processing flag (when true, widget will change Hover state while mouse is moving)

valign
Align valign [@property getter]

returns horizontal alignment

visibility
Visibility visibility [@property setter]

sets widget visibility (Visible, Invisible, Gone)

visibility
Visibility visibility [@property getter]

returns widget visibility (Visible, Invisible, Gone)

visible
bool visible [@property getter]

returns true if this widget and all its parents are visible

wantsKeyTracking
bool wantsKeyTracking [@property getter]

override and return true to track key events even when not focused

width
int width [@property getter]

returns current width of widget in pixels

window
Window window [@property getter]

returns window (if widget or its parent is attached to window)

window
Window window [@property setter]

sets window (to be used for top level widget from Window implementation). TODO: hide it from API?

Static functions

applyAlign
void applyAlign(Rect rc, Point sz, Align ha, Align va)

Applies alignment for content of size sz - set rectangle rc to aligned value of content inside of initial value of rc.

Static variables

FOCUS_RECT_PADDING
enum FOCUS_RECT_PADDING;
Undocumented in source.

Variables

_acceleratorMap
ActionMap _acceleratorMap;
Undocumented in source.
_action
Action _action;
Undocumented in source.
_backgroundDrawable
DrawableRef _backgroundDrawable;
Undocumented in source.
_checkable
bool _checkable;
Undocumented in source.
_checked
bool _checked;
Undocumented in source.
_clickable
bool _clickable;
Undocumented in source.
_focusGroup
bool _focusGroup;
Undocumented in source.
_focusable
bool _focusable;
Undocumented in source.
_id
string _id;

widget id

_measuredHeight
int _measuredHeight;

height measured by measure()

_measuredWidth
int _measuredWidth;

width measured by measure()

_needDraw
bool _needDraw;

true to force redraw

_needLayout
bool _needLayout;

true to force layout

_ownStyle
Style _ownStyle;

own copy of style - to override some of style properties, null of no properties overriden

_parent
Widget _parent;

parent widget

_popupMenu
MenuItem _popupMenu;
Undocumented in source.
_pos
Rect _pos;

current widget position, set by layout()

_state
uint _state;

widget state (set of flags from State enum)

_styleId
string _styleId;

style id to lookup style in theme

_tabOrder
ushort _tabOrder;
Undocumented in source.
_tooltipText
UIString _tooltipText;
Undocumented in source.
_trackHover
bool _trackHover;

does widget need to track mouse Hover

_visibility
Visibility _visibility;

widget visibility: either Visible, Invisible, Gone

_window
Window _window;

window (to be used for top level widgets only!)

checkChange
Signal!OnCheckHandler checkChange;

checked state change event listener (bool delegate(Widget, bool))

click
Signal!OnClickHandler click;

on click event listener (bool delegate(Widget))

doubleClick
Signal!OnDoubleClickHandler doubleClick;

On double click event listener (bool delegate(Widget))

focusChange
Signal!OnFocusHandler focusChange;

focus state change event listener (bool delegate(Widget, bool))

keyEvent
Signal!OnKeyHandler keyEvent;

key event listener (bool delegate(Widget, KeyEvent)) - return true if event is processed by handler

keyToAction
Listener!OnKeyActionHandler keyToAction;

action by key lookup handler

mouseEvent
Signal!OnMouseHandler mouseEvent;

mouse event listener (bool delegate(Widget, MouseEvent)) - return true if event is processed by handler

onAction
Signal!OnActionHandler onAction;

action handlers

Meta