Expand description
yog-kit — MVVM screens for Yog mods.
A screen is a .yui file with x:ViewModel="MyVm" plus a plain Rust
view model. yog build compiles the markup into a View (widget tree,
compiled {x:Bind ...} bindings, command dispatch) and this crate hosts
it: it owns the view model, re-evaluates bindings after every change,
routes input (clicks, hover, scrolling, text boxes, Tab focus, list
keyboard selection, Esc) and draws the result.
ⓘ
// src/counter.rs, next to src/counter.yui
yog_api::ui_include!("counter");
use yog_kit::prelude::*;
#[derive(Default)]
pub struct CounterVm { count: u32 }
impl ViewModel for CounterVm {}
impl CounterVm {
pub fn increment(&mut self) { self.count += 1 }
}
// src/lib.rs: counter::register(registry); ... counter::open();The view model never touches widgets: the markup binds to its fields and
methods, and commands call its methods. [testing::TestHost] drives a
screen without the game.
Modules§
- bind
- Binding helpers used by generated
.yuicode: aSlotremembers a binding’s last value so widgets are only patched when it changes, and the conversion functions turn view-model values into widget values with readable compile errors. - items
- Lists: an
ItemsHostkeeps one template instance per item of anItemsControl/ListView/ContentPresenter, reconciled by key, so an update only patches what changed. With a fixeditem_heightonly the rows in (and near) view are built — the rest are two spacers. - prelude
- Everything a code-behind file needs.
Structs§
- Action
- A typed click target:
owner0 = the screen,k= items controlk;slot= the command (orAction::SELECT);index= the item index inside an items control (0 elsewhere). - Cx
- What a command or view-model hook can ask of its screen. Requests run right after the call returns.
- List
Part - One list (ListView / ItemsControl) of a view.
- Parts
- The interactive parts of a view, created by
View::build: scrollers, text boxes, lists, and the Tab focus order. Indices are the order they were added. - Screen
- Hosts the compiled view
Was a Yog screen. - Screen
Handle - A cloneable, thread-safe handle to a registered screen’s view model.
- Screen
Meta - Static facts about a screen, from its
<Screen>attributes. - Scroller
Part - One scrolling container of a view.
- State
Flags - Interaction state bits of a widget — see
Widget::state. - Text
BoxPart - One text box of a view.
- Update
- What a
View::updatechanged, plus what it can ask of the host. - Viewport
- A scroller’s visible window during an update.
- Widget
- A single widget in the UI tree.
Enums§
- Anchor
- Where a screen’s content sits in the GUI.
- View
Event - Input for a view’s
View::dispatch, produced by the host.
Traits§
- View
- A compiled screen — implemented by
.yuicodegen only. - View
Model - A screen’s state and logic. Implement it (often with no methods) for the
type named by the
.yuifile’sx:ViewModel.
Functions§
- handle_
of - The handle of the registered screen
W. - inventory_
of - The inventory screen
W’s markup lays out — where its<Slot>s and<PlayerInventory>land at the design size — orNonefor a plain screen. Its id is the screen’s: a block opens it withBlockDef::inventory(ID).