// <auto-generated>
// Generated by yog from src/$NAME$.yui — do not edit: changes are lost
// on the next `yog build` / `yog check` / `yog ui gen`. Edit the .yui
// file (Yog-IDLE's screen designer) instead.
// </auto-generated>
//
// Pulled into the screen's code-behind module with:
//
// yog_api::ui_include!("$NAME$");
/// The UI id this screen registers under (`register_ui`, `on_ui_render`, `open_ui`).
#[allow(dead_code)]
pub const ID: &str = $ID_LIT$;
/// Design-time size in GUI pixels.
#[allow(dead_code)]
pub const WIDTH: f32 = $WIDTH$;
#[allow(dead_code)]
pub const HEIGHT: f32 = $HEIGHT$;
/// `on_click`/`on_change`/`on_submit` events raised by this screen's widgets.
#[allow(dead_code)]
pub mod events {
$EVENTS$}
/// Ids of this screen's named widgets (for `Widget::find_mut`, `UiRoot::find_rect`).
#[allow(dead_code)]
pub mod ids {
$IDS$}
/// The screen's widget tree, positioned at (0, 0).
#[allow(dead_code)]
pub fn build() -> ::yog_api::ui::Widget {
#[allow(unused_imports)]
$UI_USE$
$BODY$
}
/// The screen laid out for a `screen_w` × `screen_h` GUI, anchored $ANCHOR$
/// — `customize` may change the tree first (dynamic text, enabled state, ...).
#[allow(dead_code)]
pub fn root_with(
screen_w: f32,
screen_h: f32,
customize: impl FnOnce(&mut ::yog_api::ui::Widget),
) -> ::yog_api::ui::UiRoot {
use ::yog_api::ui::{widget, FlexDir, Units};
let mut content = build();
customize(&mut content);
let screen = widget::panel(FlexDir::Column)
.w(Units::Px(screen_w))
.h(Units::Px(screen_h))
.child($PLACE$);
let mut ui = ::yog_api::ui::UiRoot::new(ID, screen);
ui.layout(screen_w, screen_h);
ui
}
/// [`root_with`] without changes.
#[allow(dead_code)]
pub fn root(screen_w: f32, screen_h: f32) -> ::yog_api::ui::UiRoot {
root_with(screen_w, screen_h, |_| {})
}
static __YUI_LAST: ::std::sync::Mutex<Option<::yog_api::ui::UiRoot>> = ::std::sync::Mutex::new(None);
/// Draws the screen — call from `on_ui_render(ID, ...)`. Remembers the
/// layout for [`click`].
#[allow(dead_code)]
pub fn render(gfx: &::yog_api::GfxContext) {
render_with(gfx, |_| {})
}
/// [`render`], changing the tree first (see [`root_with`]).
#[allow(dead_code)]
pub fn render_with(gfx: &::yog_api::GfxContext, customize: impl FnOnce(&mut ::yog_api::ui::Widget)) {
let (w, h) = gfx.screen_size();
let ui = root_with(w as f32, h as f32, customize);
ui.render(gfx);
if let Ok(mut last) = __YUI_LAST.lock() {
*last = Some(ui);
}
}
/// The `on_click` event of the widget under a `"click:X:Y"` UI event (what
/// `register_ui`'s handler receives) — `None` for other events or a miss.
#[allow(dead_code)]
pub fn click(event: &str) -> Option<String> {
let mut parts = event.strip_prefix("click:")?.split(':');
let x: f32 = parts.next()?.parse().ok()?;
let y: f32 = parts.next()?.parse().ok()?;
let last = __YUI_LAST.lock().ok()?;
last.as_ref()?.hit_test(x, y)?.on_click.clone()
}
/// Runs `f` on the layout drawn by the last [`render`] — for reading
/// rects and scroll state (`UiRoot::find_node`) when handling UI events.
/// `None` before the first render.
#[allow(dead_code)]
pub fn with_last<R>(f: impl FnOnce(&::yog_api::ui::UiRoot) -> R) -> Option<R> {
let last = __YUI_LAST.lock().ok()?;
last.as_ref().map(f)
}
/// Feeds a UI event to the text box `id` (one of [`ids`]) as laid out by the
/// last [`render`] — call from `register_ui`'s handler; pass the same state
/// to `TextBoxState::apply` in [`render_with`]'s customize. `Ignored` before
/// the first render or for an unknown id.
#[allow(dead_code)]
pub fn text_box(
id: &str,
state: &mut ::yog_api::ui::TextBoxState,
event: &str,
) -> ::yog_api::ui::TextBoxEvent {
with_last(|ui| ui.find_node(id).map(|node| state.handle(event, node)))
.flatten()
.unwrap_or(::yog_api::ui::TextBoxEvent::Ignored)
}
/// Opens the screen (modal: $MODAL$, pauses the game: $PAUSE$).
#[allow(dead_code)]
pub fn open() {
::yog_api::open_ui(ID, $MODAL$, $PAUSE$);
}
/// Closes the screen if it's open (what Esc does) — for a Done/Cancel
/// button. Takes effect after the current event handler returns.
#[allow(dead_code)]
pub fn close() {
::yog_api::close_ui(ID);
}