package miaou-core
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6
doc/miaou-core.style/Miaou_style/Selector/index.html
Module Miaou_style.SelectorSource
CSS-like selector system for widget styling.
Selectors allow targeting specific widgets and their states. They support:
- Widget names:
"table","modal","flex_layout" - Pseudo-classes:
":focus",":selected",":hover" - Positional:
":first-child",":last-child",":nth-child(even)",":nth-child(odd)",":nth-child(3)" - Combinators:
"parent > child"(direct child),"ancestor descendant"(any descendant)
Example selectors:
"table"- matches any table widget"table:focus"- matches focused table"flex_layout > :nth-child(even)"- matches even children of flex_layout"modal .button:focus"- matches focused button inside modal
type pseudo_class = | Focus(*:focus - widget has input focus
*)| Selected(*:selected - item is selected
*)| Hover(*:hover - mouse is over (if supported)
*)| Disabled(*:disabled - widget is disabled
*)| First_child(*:first-child - first child of parent
*)| Last_child(*:last-child - last child of parent
*)| Nth_child_even(*:nth-child(even) - even-indexed children
*)| Nth_child_odd(*:nth-child(odd) - odd-indexed children
*)| Nth_child of int(*:nth-child(n) - specific index (1-based)
*)
Pseudo-class selectors
val pseudo_class_of_yojson :
Yojson.Safe.t ->
pseudo_class Ppx_deriving_yojson_runtime.error_ortype simple_selector = {element : string option;(*Widget name, or None for universal selector
*)pseudo_classes : pseudo_class list;(*Pseudo-classes to match
*)
}A single selector part (element + pseudo-classes)
val simple_selector_of_yojson :
Yojson.Safe.t ->
simple_selector Ppx_deriving_yojson_runtime.error_orCombinator between selector parts
type t = {parts : (simple_selector * combinator option) list;(*List of (selector, combinator_to_next) pairs. Last element should have
*)Nonecombinator.
}A complete selector (chain of simple selectors with combinators)
type match_context = {widget_name : string;(*Name of the widget being styled
*)focused : bool;(*Whether widget has focus
*)selected : bool;(*Whether widget/item is selected
*)hover : bool;(*Whether mouse is hovering
*)disabled : bool;(*Whether widget is disabled
*)child_index : int option;(*Index among siblings (0-based)
*)child_count : int option;(*Total number of siblings
*)ancestors : string list;(*Ancestor widget names (nearest first)
*)
}Context for matching selectors against widgets
Default match context
Create a simple context with just widget name
Selector parsing
Parse a selector string.
Examples:
"table"-> matches widget named "table""table:focus"-> matches focused table":first-child"-> matches first child of any parent"flex > :nth-child(even)"-> even children of flex"modal .button"-> button inside modal (any depth)
Returns None if parsing fails.
Selector matching
Check if a selector matches the given context
Selector specificity
Specificity for ordering selectors. Higher values are more specific. Follows CSS specificity rules: (pseudo-class count, element count)
Calculate specificity of a selector
Compare two specificities. Returns positive if first is more specific.