plushie/node

Tree node types for plushie’s UI tree.

PropValue is a JSON-like union representing wire-compatible values. Node is the fundamental tree building block – widget builders produce these, tree operations consume them, and the protocol encoder serializes them to wire format.

Types

A node in the UI tree. Produced by widget builders, consumed by tree operations and the protocol encoder.

  • id: widget identifier (scoped during normalization)
  • kind: widget type string (“button”, “column”, etc.)
  • props: encoded property values (string-keyed)
  • children: child nodes
pub type Node {
  Node(
    id: String,
    kind: String,
    props: dict.Dict(String, PropValue),
    children: List(Node),
  )
}

Constructors

A wire-compatible value. Covers all JSON/MessagePack primitive types. Widget builders convert typed Gleam values (Length, Padding, Color, etc.) into PropValue at build() time.

pub type PropValue {
  StringVal(String)
  IntVal(Int)
  FloatVal(Float)
  BoolVal(Bool)
  NullVal
  BinaryVal(BitArray)
  ListVal(List(PropValue))
  DictVal(dict.Dict(String, PropValue))
}

Constructors

  • StringVal(String)
  • IntVal(Int)
  • FloatVal(Float)
  • BoolVal(Bool)
  • NullVal
  • BinaryVal(BitArray)

    Raw binary data. Encoded as base64 on the JSON wire format and as raw bytes on the MessagePack wire format.

  • ListVal(List(PropValue))
  • DictVal(dict.Dict(String, PropValue))

Values

pub fn add_child(node: Node, child: Node) -> Node

Append a child to a node.

pub fn empty_container() -> Node

An empty container node, useful as a default root.

pub fn new(id: String, kind: String) -> Node

Create a node with no props and no children.

pub fn with_children(node: Node, children: List(Node)) -> Node

Replace a node’s children.

pub fn with_prop(
  node: Node,
  key: String,
  value: PropValue,
) -> Node

Set a single prop on a node.

pub fn with_props(
  node: Node,
  props: List(#(String, PropValue)),
) -> Node

Set multiple props on a node.

Search Document