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/Style_context/index.html

Module Miaou_style.Style_contextSource

Effect-based style context for implicit theme access.

This module provides a way to access the current theme and style context without explicitly threading it through all function calls. It uses OCaml 5 effects for this purpose.

Usage:

(* At application startup or driver level *)
Style_context.with_theme (Theme_loader.load ()) (fun () ->
  (* In any nested code, theme is accessible *)
  let theme = Style_context.current_theme () in
  ...
)

(* Or use convenience functions *)
let my_view () =
  let border_style = Style_context.border ~focus:true in
  let text_style = Style_context.primary () in
  ...

Widgets can also push their own context for their children:

let render_children children =
  children |> List.mapi (fun i child ->
    Style_context.with_child_context 
      ~index:i 
      ~count:(List.length children)
      ~ancestors:[widget_name]
      (fun () -> child.render ())
  )

Theme effects

Sourcetype Effect.t +=
  1. | Get_theme : Theme.t Effect.t

Effect for getting the current theme

Sourcetype Effect.t +=
  1. | Get_match_context : Selector.match_context Effect.t

Effect for getting the current match context (for selector matching)

Running with context

Sourceval with_theme : Theme.t -> (unit -> 'a) -> 'a

Run a computation with a specific theme (immutable). This sets up the effect handler for theme access.

Sourceval with_mutable_theme : Theme.t -> (unit -> 'a) -> 'a

Run a computation with a mutable theme that can be updated at runtime. Use set_theme or reload_theme to change the theme during execution. This is the recommended way for drivers to set up the theme context.

Runtime theme updates

Sourcetype Effect.t +=
  1. | Set_theme : Theme.t -> unit Effect.t

Effect for updating the theme at runtime (used by set_theme)

Sourceval set_theme : Theme.t -> unit

Set the current theme. Only works when running under with_mutable_theme. Silently ignored if no mutable handler is installed.

Sourceval reload_theme : unit -> Theme.t

Reload the theme from disk and apply it. Returns the newly loaded theme.

Sourceval with_context : Theme.t -> Selector.match_context -> (unit -> 'a) -> 'a

Run a computation with both theme and match context

Sourceval with_child_context : ?widget_name:string -> ?focused:bool -> ?selected:bool -> ?index:int -> ?count:int -> ?ancestors:string list -> (unit -> 'a) -> 'a

Run a computation with updated match context (for child widgets). Inherits the current theme.

Accessing current context

Sourceval current_theme : unit -> Theme.t

Get the current theme. Returns Theme.default if no handler is installed.

Sourceval current_context : unit -> Selector.match_context

Get the current match context. Returns Selector.empty_context if no handler.

Convenience style accessors

Sourceval current_style : unit -> Theme.widget_style

Get resolved style for current context (applies all matching rules)

Sourceval primary : unit -> Style.t

Get a semantic style from the theme

Sourceval secondary : unit -> Style.t
Sourceval accent : unit -> Style.t
Sourceval error : unit -> Style.t
Sourceval warning : unit -> Style.t
Sourceval success : unit -> Style.t
Sourceval info : unit -> Style.t
Sourceval text : unit -> Style.t
Sourceval text_muted : unit -> Style.t
Sourceval text_emphasized : unit -> Style.t
Sourceval background : unit -> Style.t
Sourceval background_secondary : unit -> Style.t
Sourceval selection : unit -> Style.t
Sourceval border : ?focus:bool -> unit -> Style.t

Get border style, optionally based on focus state

Sourceval default_border_style : unit -> Border.style

Get the default border style (character set)

Higher-level helpers

Sourceval styled : string -> string

Apply current style to a string

Sourceval styled_with : Style.t -> string -> string

Apply a semantic style to a string

Sourceval widget_style : string -> Theme.widget_style

Get style for a named widget, applying all matching rules