package stk

  1. Overview
  2. Docs

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 wtree : widget tree

Tree representation of widget and its children.

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.

method top_window : Tsdl.Sdl.window option

w#top_window returns the SDL window the widget is displayed in, if any.

Widget data

method wdata : wdata option
method set_wdata : wdata option -> unit

Geometry

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.

method to_desktop_coords : x:int -> y:int -> int * int

w#desktop_coords ~x ~y converts the given coordinates relative to widget top-left corner to desktop coordinates.

method to_top_window_coords : x:int -> y:int -> int * int

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.

Freezing and resizing

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.

method freeze : unit
method unfreeze : unit

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.

method ignore_need_resize : unit

Ignore requests for resizing.

method handle_need_resize : unit

Do not ignore requests for resizing.

Properties

method selected : bool
method set_selected : bool -> unit

A Props.selected widget will render differently, using different background and foreground colors.

method fill : bool
method set_fill : bool -> unit

Props.fill property.

method font : Tsdl_ttf.Ttf.font

Get the SDL font from the widget properties.

method bg_fill_borders : bool
method set_bg_fill_borders : bool -> unit

Props.bg_fill_borders property.

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 sensitive : bool
method set_sensitive : bool -> unit

Props.sensitive property.

method focusable : bool
method set_focusable : bool -> unit

Props.focusable property.

method can_focus : bool
method set_can_focus : bool -> unit

Props.can_focus property.

method show_on_focus : bool
method set_show_on_focus : bool -> unit

Props.show_on_focus property.

method padding : int Stk.Props.trbl
method set_padding : int Stk.Props.trbl -> unit
method set_padding_ : int -> int -> int -> int -> unit
method set_padding__ : int -> unit

Props.padding property.

method margin : int Stk.Props.trbl
method set_margin : int Stk.Props.trbl -> unit
method set_margin_ : int -> int -> int -> int -> unit
method set_margin__ : int -> unit

Props.margin property.

method hmargin : int * int

w#hmargin returns horizontal margins as (left margin, right margin).

method vmargin : int * int

w#vmargin returns vertical margins as (top margin, bottom margin).

method border_width : int Stk.Props.trbl
method set_border_width : int Stk.Props.trbl -> unit
method set_border_width_ : int -> int -> int -> int -> unit
method set_border_width__ : int -> unit

Props.border_width property.

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 hexpand : int
method set_hexpand : int -> unit

Props.hexpand property.

method vexpand : int
method set_vexpand : int -> unit

Props.vexpand property.

method hfill : bool
method set_hfill : bool -> unit

Props.hfill property.

method vfill : bool
method set_vfill : bool -> unit

Props.vfill property.

method text_valign : Stk.Props.text_valign
method set_text_valign : Stk.Props.text_valign -> unit

Props.text_valign property.

method is_focus : bool

Props.is_focus property.

method has_focus : bool

Props.has_focus property.

method set_visible : bool -> unit
method visible : bool

Props.visible property.

Showing (parts of) widget

method show : unit
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.

method child_visible_rect : widget -> Stk.G.t

Returns the visible rectangle of the given child widget.

Focus

method focused_widget : widget option
method release_focus : bool
method grab_focus : ?last:bool -> unit -> bool

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.

method focus_next : bool

Give focus to next focusable widget.

method focus_prev : bool

Give focus to previous focusable widget.

Misc

method set_handle_hovering : bool -> unit

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.

OCaml

Innovation. Community. Security.