Stk.Props
Properties and their values.
Exception raised when trying to register a property but a property with the same name is already registered. The argument is the property name.
Describre what to do after a property is updated:
Resize
: widget will claim that it needs resizing.Render
: widget will claim that it needs to be rendered.Action f
: call f ()
.val name : 'a prop -> string
Get property name.
val after : 'a prop -> 'a post_action list
Get property post action list.
val prop_to_string : 'a prop -> 'a -> string
prop_to_string p v
returns a string representation of a property value v
, using the Ocf
wrapper assoociated to property p
.
val pp_prop : 'a prop -> Stdlib.Format.formatter -> 'a -> unit
pp_prop p ppf v
pretty-prints value v
of property p
to formatter ppf
.
module type PT = sig ... end
What is required to handle a property value: a type, a comparison function and an optional Ocf
wrapper.
type 'a mk_prop =
?after:'a post_action list ->
?default:'a ->
?inherits:bool ->
string ->
'a prop
The type of functions creating properties. The property name is required. The property is then registered in a table. Creating a property when a property with the same name already exists raises Property_exists
. Options arguments are:
after
: a description of actions to perform after the value of a property changed. This is used in widgets to automatically perform these actions.default
: a default value for this property. This is the value returned by get
when no value is defined for a property.inherits
(default is true
indicates whether the value for this property is inherited by a widget when this widget is added to a parent widget (see Widget.widget.set_parent
).module type Prop_type = sig ... end
Type a of property, with a function mk_prop
to create properties of this type.
Creating a property type from a value description.
val trbl : top:'a -> right:'a -> bottom:'a -> left:'a -> 'a trbl
val trbl_ : 'a -> 'a -> 'a -> 'a -> 'a trbl
trbl_ top right bottom left
is a label-less equivalent of trbl_ ~top ~right ~bottom ~left
.
val trbl__ : 'a -> 'a trbl
trbl__ x
is equivalent to trbl ~top:x ~right:x ~bottom:x ~left:x
.
trbl_of t
copies t
except fields given as optional arguments.
val trbl_ocf_wrapper : 'a Ocf.Wrapper.t -> 'a trbl Ocf.Wrapper.t
Ocf
.wrapper for trbl
, using the given wrapper for values.
module PFont_desc : Prop_type with type t = Font.font_desc
module PTrbl_color : Prop_type with type t = Color.t trbl
module PPair_float : Prop_type with type t = float * float
val int_prop : int mk_prop
val float_prop : float mk_prop
val bool_prop : bool mk_prop
val string_prop : string mk_prop
val uchar_prop : Stdlib.Uchar.t mk_prop
val font_desc_prop : Font.font_desc mk_prop
val float_pair_prop : (float * float) mk_prop
val keystate_prop : Key.keystate mk_prop
type props = t
The property-to-value map of each Object.o
(including widgets) are referred to as their "properties". We add a props
type to represent this denomination.
val empty : unit -> t
Returns a new empty property map.
val default : t
Default properties. By now it is empty. Can be used internally for debugging.
get t p
returns the value of property p
in t
, or else the default value of p
. If p
has no value in t
and p
has no default value, then exception Misc.error.Missing_prop
is raised.
set_opt t p (Some v)
gives value v
to property p
in t
. set_opt t p None
removes value associated to p
in t
.
update t p v
set value v
to propery p
in t
. If v
is the same as previousvalue for p
in t
, then returns None
, else returns Some x
with x
being the optional previous value associated to p
in t
.
val to_string : t -> string
to_string t
returns a string representation of t
, mainly for debugging purpose.
val pp : Stdlib.Format.formatter -> t -> unit
pp ppf t
pretty-prints t
to the given formatter, using to_string
.
merge t1 t2
returns a new !t
using map merging function (see Map
.S.merge). The optional argument use_inherits
(false
by default) change the way to handle the case where a property p
has a value v
in t1
and no value in t2
. When use_inherits = false
, p
is given value v
in the new map. When use_inherits = true
, then p
is given value v
in the new map only if p
was defined with ~inherits:true
(which is the default, see mk_prop
).
fold f t acc
folds over properties defined in t
.
All properties are not inherited, except when specified else. The name of a property is the same as its OCaml ident. For example property padding
has name "padding"
, except is specified else.
Border color of a widget when its selected
property is true
.
Border color of a widget when its is_focus
property is true
.
val hexpand : int prop
How many shares of a container free space the widget requires to expand horizontally (see Pack.box.pack
).
val vexpand : int prop
How many shares of a container free space the widget requires to expand vertically (see Pack.box.pack
). Default is 1
.
val visible : bool prop
Whether the widget is visible. Default is true
. Inherited.
val sensitive : bool prop
Whether the widget is sensitive, i.e. responds to user events. Default is true
. Inherited.
The color mask to apply on insensitive widgets. Default is 0x80808044
. Inherited.
val hfill : bool prop
Whether the widget should fill horizontally the allocated space. (used by some containers). Default is true
.
val vfill : bool prop
Whether the widget should fill vertically the allocated space. (used by some containers). Default is true
.
val halign : float prop
Horizontal alignment (not used by all widgets). 0.
means align on the left, 1.0 means align on the right. Default is 0.5
(centered).
val valign : float prop
Same as halign
but for vertical alignment (0.
: align on top, 1.
: align on bottom).
val width : int prop
Width of a widget in pixels. Only some widgets use this property. Other widget's width depend on the way they are packed and their allocated width can be accessed through the Widget.widget.geometry
method. Inherited.
val bg_fill_borders : bool prop
Whether background color should cover borders. Default is false.
val font_desc : Font.font_desc prop
Font description. Inherited. Default is family "DejaVu Sans"
with size 14
.
val bold : bool prop
Whether font to use is bold. Inherited. If set, then the bold flag in font description is set accordingly when retrieving the corresponding SDL font.
Foreground color when widget has its selected
property set to true
. Inherited.
Foreground color when widget has its is_focus
property set to true
. Inherited.
Foreground color, use for example for text. Inherited. Remember that setting background color has no effect if fill
property has value false
.
Foreground color when widget has its selected
property set to true
. Inherited.
Foreground color when widget has its is_focus
property set to true
. Inherited.
Color for "ghost" text (see ghost_text
). Default is 0xccccccff
. Inherited.
Background color of current line (in Textview.textview
widget). Inherited.
Color mask applied on some widgets (buttons) when button is pressed. Default is 0xffffff88
. Inherited.
val has_focus : bool prop
Whether a widget has input focus. It means that the is_focus
property is true
for it and all its parent widgets, and its window has focus too. Default is false
.
val is_focus : bool prop
Widget has the input focus in its parent. Default is false
.
val focusable : bool prop
Whether a widget can have the input focus. Default is false
.
val can_focus : bool prop
Whether the input focus can enter the widget or any of its children. Default is true
.
val show_on_focus : bool prop
Whether a widget getting the focus calls self#show
. Default is true
.
val selected : bool prop
Widget is selected. The way this property is set depends on the widget. Default is false
.
val text : string prop
Text contents, used in some widgets (for example Text.label
). Inherited.
val glyph : int prop
Glyph contents (unicode codepoint), used in some widgets (for example Text.glyph
). Inherited.
val ghost_text : string prop
Ghost text t, i.e. hint text which disappears when user enters some text. Inherited.
val editable : bool prop
Used by some widgets to indicate whether contents is editable (typically text input widgets). Default is true
.
val cursor_width : int prop
Used by some widgets (typically text input) to indicate the cursor width in pixels. Default is 2
. Inherited.
Used by some widgets (typically text input) to indicate the cursor color. Default is Color.red
. Inherited.
Used by some widgets (typically text input) to indicate the active cursor color. Default is Color.red
. Inherited.
val scrollbar_width : int prop
Scrollbar width in pixels. Default is 12
. Inherited.
val scrollbar_handle_min_size : int prop
Scrollbar handle minimum size in pixels. Default is 40
. Inherited.
Scrollbar background color. Default is 0xffffff99
. Inherited. Since scrollbar (by now) is displayed over contents, the background should not be opaque.
val selection_mode : selection_mode prop
Selection mode used by some widgets. Default is Sel_multiple
.
val orientation : orientation prop
Orientation used by several widgets. Default is Vertical
.
val text_valign : text_valign prop
Text vertical alignment for items in Flex.flex
widget. Default is Baseline
.
val get_font : t -> Tsdl_ttf.Ttf.font
val get_font_for_char : t -> Stdlib.Uchar.t -> Tsdl_ttf.Ttf.font
get_font_for_char t uchar
returns the font fn
to use for this char (using get_font
, and returning fallback font (see Font.add_fallback_font
) when character is not available in fn
.
val set_font_size : t -> int -> unit
set_font_size t n
sets font_desc
in t
by changing its size to n
.
val set_from_json :
?vars:Yojson.Safe.t Misc.SMap.t ->
t ->
Yojson.Safe.t ->
unit
val wrapper : t Ocf.Wrapper.t
val to_json : t -> Yojson.Safe.t