package miaou-core

  1. Overview
  2. Docs
Miaou core/widgets (no drivers, no SDL)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.5.2.tar.gz
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
Sourcetype pseudo_class =
  1. | Focus
    (*

    :focus - widget has input focus

    *)
  2. | Selected
    (*

    :selected - item is selected

    *)
  3. | Hover
    (*

    :hover - mouse is over (if supported)

    *)
  4. | Disabled
    (*

    :disabled - widget is disabled

    *)
  5. | First_child
    (*

    :first-child - first child of parent

    *)
  6. | Last_child
    (*

    :last-child - last child of parent

    *)
  7. | Nth_child_even
    (*

    :nth-child(even) - even-indexed children

    *)
  8. | Nth_child_odd
    (*

    :nth-child(odd) - odd-indexed children

    *)
  9. | Nth_child of int
    (*

    :nth-child(n) - specific index (1-based)

    *)

Pseudo-class selectors

Sourceval pseudo_class_to_yojson : pseudo_class -> Yojson.Safe.t
Sourcetype simple_selector = {
  1. element : string option;
    (*

    Widget name, or None for universal selector

    *)
  2. pseudo_classes : pseudo_class list;
    (*

    Pseudo-classes to match

    *)
}

A single selector part (element + pseudo-classes)

Sourceval simple_selector_to_yojson : simple_selector -> Yojson.Safe.t
Sourcetype combinator =
  1. | Descendant
    (*

    space: ancestor descendant

    *)
  2. | Child
    (*

    >: parent > child

    *)

Combinator between selector parts

Sourceval combinator_to_yojson : combinator -> Yojson.Safe.t
Sourcetype t = {
  1. parts : (simple_selector * combinator option) list;
    (*

    List of (selector, combinator_to_next) pairs. Last element should have None combinator.

    *)
}

A complete selector (chain of simple selectors with combinators)

Sourceval to_yojson : t -> Yojson.Safe.t
Sourcetype match_context = {
  1. widget_name : string;
    (*

    Name of the widget being styled

    *)
  2. focused : bool;
    (*

    Whether widget has focus

    *)
  3. selected : bool;
    (*

    Whether widget/item is selected

    *)
  4. hover : bool;
    (*

    Whether mouse is hovering

    *)
  5. disabled : bool;
    (*

    Whether widget is disabled

    *)
  6. child_index : int option;
    (*

    Index among siblings (0-based)

    *)
  7. child_count : int option;
    (*

    Total number of siblings

    *)
  8. ancestors : string list;
    (*

    Ancestor widget names (nearest first)

    *)
}

Context for matching selectors against widgets

Sourceval empty_context : match_context

Default match context

Sourceval context_of_widget : string -> match_context

Create a simple context with just widget name

Selector parsing

Sourceval parse : string -> t option

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.

Sourceval parse_exn : string -> t

Parse a selector string, raising Invalid_argument on failure

Sourceval to_string : t -> string

Convert selector back to string representation

Selector matching

Sourceval matches : t -> match_context -> bool

Check if a selector matches the given context

Selector specificity

Sourcetype specificity = int * int

Specificity for ordering selectors. Higher values are more specific. Follows CSS specificity rules: (pseudo-class count, element count)

Sourceval specificity : t -> specificity

Calculate specificity of a selector

Sourceval compare_specificity : specificity -> specificity -> int

Compare two specificities. Returns positive if first is more specific.