package miaou-core
Install
dune-project
Dependency
Authors
Maintainers
Sources
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
Effect for getting the current match context (for selector matching)
Running with context
Run a computation with a specific theme (immutable). This sets up the effect handler for theme access.
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
Effect for updating the theme at runtime (used by set_theme)
Set the current theme. Only works when running under with_mutable_theme. Silently ignored if no mutable handler is installed.
Reload the theme from disk and apply it. Returns the newly loaded theme.
Run a computation with both theme and match context
val with_child_context :
?widget_name:string ->
?focused:bool ->
?selected:bool ->
?index:int ->
?count:int ->
?ancestors:string list ->
(unit -> 'a) ->
'aRun a computation with updated match context (for child widgets). Inherits the current theme.
Accessing current context
Get the current theme. Returns Theme.default if no handler is installed.
Get the current match context. Returns Selector.empty_context if no handler.
Convenience style accessors
Get resolved style for current context (applies all matching rules)
Get the default border style (character set)
Higher-level helpers
Apply current style to a string
Get style for a named widget, applying all matching rules