Skip to main content

yog_cli/yui/
mod.rs

1//! `.yui` screen files — the declarative form of a `yog-ui` widget tree that
2//! Yog-IDLE's screen designer edits — and their code generation.
3//!
4//! A `.yui` file is a small XAML-like XML document: one element per widget,
5//! attributes named after the `yog-ui` builder methods they become:
6//!
7//! ```xml
8//! <Screen id="mymod:main_menu" width="176" height="166" anchor="center" bg="#C0101010" padding="8">
9//!   <Label id="title" x="8" y="6" text="Main Menu" color="#FFFFFF" no_wrap="true"/>
10//!   <Button x="38" y="40" w="100" h="20" text="Play" bg="#FF555555" on_click="play"/>
11//!   <Column x="8" y="70" w="160" gap="2">
12//!     <Label text="Flowing child"/>
13//!   </Column>
14//! </Screen>
15//! ```
16//!
17//! `yog build` (and `yog check`, `yog ui gen`) turns `src/**/foo.yui` into
18//! `.yog-build/generated/**/foo.g.rs` — WPF's `MainWindow.g.cs`: generated
19//! into the build directory on every build, never committed, pulled into the
20//! screen's hand-written code-behind module with `yog_api::ui_include!("foo")`.
21//! See `docs/yui.md` in Yog-IDLE for the full format.
22
23use yog_data::Diagnostic;
24
25mod anchor;
26mod attr_code;
27mod elements;
28mod files;
29mod screen;
30mod values;
31mod widget;
32
33pub use files::{
34    GENERATED_DIR, Generated, find_yui_files, generate_all, generate_file, generated_path,
35    include_name, is_book_page_file, project_root,
36};
37pub use screen::{generate_for, generate_with};
38pub use values::{HEX_MARK, color, const_name, pascal, set_resource_refs, text_expr};
39pub use yog_formats::yui::{Element, parse as parse_xml};
40
41pub(crate) use anchor::Anchor;
42pub(crate) use elements::{is_builtin, is_common_attr, is_custom_component};
43pub(crate) use screen::{screen_frame, screen_theme};
44pub(crate) use values::{
45    Names, boolean, color_attr, image_source, is_image_value, number, snake, str_consts, text_attr,
46};
47pub(crate) use widget::static_widget;
48
49#[cfg(test)]
50pub use screen::generate;
51
52/// The import generated widget-building code starts with.
53pub(crate) const UI_USE: &str =
54    "use ::yog_api::ui::{widget, Align, Dock, FlexDir, FocusStyle, Units};";
55
56/// `line N: <Kind> msg`.
57pub(crate) fn err<T>(el: &Element, msg: impl std::fmt::Display) -> Result<T, Diagnostic> {
58    Err(Diagnostic::from(format!("<{}> {msg}", el.name)).at_line(el.line))
59}
60
61/// Prefix of a custom component property's value that is a Rust
62/// expression (a `String`) rather than text — set by the component
63/// generator for bound properties; never in a `.yui`.
64pub(crate) const RAW_VALUE: &str = "\u{1}rs:";
65
66/// Attribute-name prefix of a raw builder call (`__rs0="action(...)"`)
67/// that the view-model generator attaches to elements; never in a `.yui`.
68pub(crate) const RAW_CALL: &str = "__rs";
69
70#[cfg(test)]
71mod tests;