Widget.widget
The base widget class. It contains methods to be called by children widgets, event if the base class does not handle child widgets.
Setting and getting property values should be done by using get_...
and set_...
methods. When a property has no set_...
method, it should not be modified from out of the class (but can be set by inheriting classes).
inherit Stk.Object.o
method as_widget : widget
All widgets should have a as_...
method to coerce to its own class.
method coerce : widget
w#coerce
returns the widget coerced to widget
type.
method equal : widget -> bool
Widget equality based on their unique Object
.o.id.
method parent : widget option
Returns parent widget, is any.
method top_widget : widget
Returns the top widget, going up through parent widgets until the one with no parent.
w#top_window
returns the SDL window the widget is displayed in, if any.
method wdata : wdata option
method set_wdata : wdata option -> unit
method geometry : Stk.G.t
Geometry of widget, relative to its parent.
method g_inner : Stk.G.t
Inner geometry, relative to top-left corner of the widget. This is the rectangle used by widget after removing border widths and paddings from its allocated geometry.
w#desktop_coords ~x ~y
converts the given coordinates relative to widget top-left corner to desktop coordinates.
w#to_top_window_coords ~x ~y
converts the given coordinates relative to widget top-left corner to coordinates relative to top widget's top window.
A frozen widget will not ask for rendering (but can render). This is useful when a lot of computations are performed and each may require rendering. Freezing a widget will block rendering request from children widgets, until all is ready. They unfreezing the widget will ask for its rendering.
A widget may require a resizing, i.e. ask its parent to compute its allocated geometry, typically because its size constraints changed. A widget can ignore its own requests for resizing or the ones from its children, for example when doing some updates that will need many resizings it is more performant to do one resizing when everything is computed. The Flex
.flex widget uses this.
A Props
.selected widget will render differently, using different background and foreground colors.
method bg_color : Stk.Color.t
method set_bg_color : Stk.Color.t -> unit
Props
.bg_color property.
method bg_color_selected : Stk.Color.t
method set_bg_color_selected : Stk.Color.t -> unit
Props
.bg_color_selected property.
method bg_color_focused : Stk.Color.t
method set_bg_color_focused : Stk.Color.t -> unit
Props
.bg_color_focused property.
method bg_color_hover : Stk.Color.t
method set_bg_color_hover : Stk.Color.t -> unit
Props
.bg_color_hover property.
method fg_color : Stk.Color.t
method set_fg_color : Stk.Color.t -> unit
Props
.fg_color property.
method fg_color_selected : Stk.Color.t
method set_fg_color_selected : Stk.Color.t -> unit
Props
.fg_color_selected property.
method fg_color_focused : Stk.Color.t
method set_fg_color_focused : Stk.Color.t -> unit
Props
.fg_color_focused property.
method fg_color_hover : Stk.Color.t
method set_fg_color_hover : Stk.Color.t -> unit
Props
.fg_color_hover property.
method padding : int Stk.Props.trbl
method set_padding : int Stk.Props.trbl -> unit
method margin : int Stk.Props.trbl
method set_margin : int Stk.Props.trbl -> unit
method border_width : int Stk.Props.trbl
method set_border_width : int Stk.Props.trbl -> unit
method border_color : Stk.Color.t Stk.Props.trbl
method set_border_color : Stk.Color.t Stk.Props.trbl -> unit
method set_border_color_ : Stk.Color.t ->
Stk.Color.t ->
Stk.Color.t ->
Stk.Color.t ->
unit
method set_border_color__ : Stk.Color.t -> unit
Props
.border_color property.
method border_color_selected : Stk.Color.t Stk.Props.trbl
method set_border_color_selected : Stk.Color.t Stk.Props.trbl -> unit
method set_border_color_selected_ : Stk.Color.t ->
Stk.Color.t ->
Stk.Color.t ->
Stk.Color.t ->
unit
method set_border_color_selected__ : Stk.Color.t -> unit
Props
.border_color_selected property.
method border_color_focused : Stk.Color.t Stk.Props.trbl
method set_border_color_focused : Stk.Color.t Stk.Props.trbl -> unit
method set_border_color_focused_ : Stk.Color.t ->
Stk.Color.t ->
Stk.Color.t ->
Stk.Color.t ->
unit
method set_border_color_focused__ : Stk.Color.t -> unit
Props
.border_color_focused property.
method border_color_hover : Stk.Color.t Stk.Props.trbl
method set_border_color_hover : Stk.Color.t Stk.Props.trbl -> unit
method set_border_color_hover_ : Stk.Color.t ->
Stk.Color.t ->
Stk.Color.t ->
Stk.Color.t ->
unit
method set_border_color_hover__ : Stk.Color.t -> unit
Props
.border_color_hover property.
method text_valign : Stk.Props.text_valign
method set_text_valign : Stk.Props.text_valign -> unit
Props
.text_valign property.
method show_rect : Stk.G.t -> unit
method show_child_rect : Stk.G.t -> unit
method visible_rect : Stk.G.t
Returns the visible rectangle of the widget.
Returns the visible rectangle of the given child widget.
method focused_widget : widget option
w#grab_focus()
make widget v
tries to grab focus. The widget must be visible and sensitive, with Props
.can_focus and Props
.focusable set to true
. The last
optional argument is used internally by some widgets containing various children. Returns true
if the focus could be grabbed, else false
.
w#set_handle_hovering b
sets handling hovering to b
. Handling hovering means that mouse cursor motions are tracked to trigger Mouse_enter
and Mouse_leave
events. Default is to ignore hovering to avoid computations. It is used for some wigets, like menu item or buttons for which such a visual feedback is important. Mouse cursor hovering affect the background, foreground and border colors of a widget.
method bg_color_now : Stk.Color.t
Current background color, depending on mouse hovering, Props
.is_focus and Props
.selected properties.
method fg_color_now : Stk.Color.t
Current foreground color, depending on mouse hovering, Props
.is_focus and Props
.selected properties.
method border_color_now : Stk.Color.t Stk.Props.trbl
Current border color, depending on mouse hovering, Props
.is_focus and Props
.selected properties.