Expand description
Custom components — a mod’s own reusable widgets, used from .yui
markup like the built-in elements (the user controls of WPF/WinForms).
A component is a function from its properties to a Widget tree,
plus a description of those properties (name, type, default, doc) that
Yog-IDLE’s screen designer shows in its toolbox and property grid:
use yog_api::ui::component::{Component, Prop, Props};
use yog_api::ui::{widget, FlexDir, Units, Widget};
pub struct StatBar;
impl Component for StatBar {
const NAME: &'static str = "StatBar";
const DOC: &'static str = "A labelled progress bar.";
const PROPS: &'static [Prop] = &[
Prop::text("label", "HP"),
Prop::number("value", "0.5").doc("Filled fraction, 0..1"),
Prop::color("fill", "#FF55FF55"),
Prop::event("on_select"),
];
fn build(p: &Props) -> Widget {
widget::panel(FlexDir::Row)
.child(widget::label(p.text("label")))
.child(widget::spacer().w(Units::Px(p.number("value") * 60.0)).h(Units::Px(6.0)).bg(p.color("fill")))
}
}
yog_api::ui_component!(StatBar);<StatBar x="8" y="8" w="120" label="Mana" value="0.3" fill="#FF5555FF"/>yog build turns such an element into component::build("StatBar", &[("label", "Mana"), ...]) followed by the usual builder calls for the
common attributes (x, y, w, h, bg, on_click, …) — so only
the component’s own properties reach Component::build, as strings,
read back typed through Props.
designer is the screen designer’s door into a mod: the designer host
(a process of Yog-IDLE’s) loads the mod’s library built for the host
machine and calls yog_ui_designer (exported by export_mod!) to list
the components and draw them through a recording YogGfxApi.
Modules§
- 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§
- Component
Spec - 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§
- Prop
Kind - A property’s type: how
.yuiwrites it and how the designer edits it.
Constants§
- COMMON_
ATTRS - The attributes every
.yuielement takes (yog buildapplies them to a component’s widget with builder calls — they never reach itsProps).
Traits§
- Component
- A custom component: see the module docs.
Functions§
- apply_
style - One common style attribute applied to
was generated code would (layout attributes — position, size, dock, flex — are left to the caller; malformed values are ignored). - build
- The component
namebuilt from.yuiattribute 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
buildshows for a component it can’t build. - find
- The registered component
name. - parse_
color #RRGGBB,#AARRGGBBor0xAARRGGBB(as.yuicolors).- register
- Adds
Cto 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