Skip to main content

Module component

Module component 

Source
Expand description

Custom components — a mod’s own reusable widgets, used from .yui markup like the built-in elements (the user controls of WPF).

A component is a .yui file with a <Component> root: its properties and events declared in markup, its body bound to them with {x:Bind ...}, and an optional code-behind .rs for methods the bindings call (see Yog-IDLE’s docs/yui.md, “Components”):

<Component name="StatBar" description="A labelled progress bar." icon="item:experience_bottle"
           design_w="120" design_h="10">
    <Property name="label" type="text" default="HP"/>
    <Property name="value" type="number" default="0.5" doc="Filled fraction, 0..1" category="Data"/>
    <Row w="100%" gap="4">
        <Label text="{x:Bind label}"/>
        <Spacer w="{x:Bind bar_w()}" h="6" bg="#FF55FF55"/>
    </Row>
</Component>

yog build generates the Component implementation from it (a struct with one typed field per property, NAME, the designer metadata, PROPS, build) and registers it (yog_api::ui_component!) — this module is that code’s runtime: the registry, Props (the instance’s attribute values, read back typed), bind (binding conversions) and designer, Yog-IDLE’s door into a mod built for the host machine.

A screen uses a component like any element: <StatBar x="8" y="8" w="120" label="Mana" value="0.3"/> becomes component::build("StatBar", &[("label", "Mana"), ("value", "0.3")]) followed by the builder calls for the common attributes (x, y, w, h, bg, on_click, …).

Modules§

bind
Conversions of {x:Bind ...} values to what a bound attribute takes (generated component code calls these).
designer
The screen designer’s protocol (see the module docs): one C-ABI entry point, yog_ui_designer, taking a text request and answering through a write callback.

Structs§

ComponentSpec
A registered component (see register).
Prop
One property of a component.
Props
A component’s property values: what the element set, else the defaults.

Enums§

PropKind
A property’s type: how .yui writes it and how the designer edits it.

Constants§

COMMON_ATTRS
The attributes every .yui element takes (yog build applies them to a component’s widget with builder calls — they never reach its Props).

Traits§

Component
A custom component — implemented by the code yog build generates from a <Component> .yui (see the module docs).

Functions§

apply_style
One common style attribute applied to w as generated code would (layout attributes — position, size, dock, flex — are left to the caller; malformed values are ignored).
build
The component name built from .yui attribute values (what generated screen code calls). An unknown name gives a red error box rather than a panic, so a screen with a typo still opens.
components
Every registered component, in registration order.
error_box
What build shows for a component it can’t build.
find
The registered component name.
parse_color
#RRGGBB, #AARRGGBB or 0xAARRGGBB (as .yui colors), or a decimal 0xAARRGGBB value (what a bound u32 property arrives as).
register
Adds C to this library’s components (a later registration of the same name replaces the earlier one). yog_api::ui_component! calls this when the mod’s library loads.
register_spec