// Generated by the rust_widgets designer. Do not edit by hand.
//
// target profile : desktop (build with `cargo build --no-default-features --features desktop`)
// root control : window
// nodes : 4
// properties : 9
//
// resolved at generation time (not calls in this file):
// - the document's layout was solved into constant coordinates against 640x480
use rust_widgets::core::Rect;
use rust_widgets::view::Node;
use rust_widgets::widget::capability::CapabilityValue;
pub fn build_ui() {
let tree = Node::new("window").key("root").prop("width", CapabilityValue::UInt(640)).prop("height", CapabilityValue::UInt(480)).prop("height", CapabilityValue::Int(480)).prop("title", CapabilityValue::String(String::from("Generated Demo"))).prop("width", CapabilityValue::Int(640)).child(Node::new("label").key("n_0").prop("text", CapabilityValue::String(String::from("Generated from a project document")))).child(Node::new("button").key("n_1").prop("enabled", CapabilityValue::Bool(false)).prop("text", CapabilityValue::String(String::from("Go")))).child(Node::new("slider").key("n_2").prop("value", CapabilityValue::Int(40)));
// The `View` value is the generated tree, and `create_for` is generated too, so this
// program links no JSON parser and no widget-name table (mode 1's weight).
let mut engine = rust_widgets::view::ViewEngine::new();
let report = engine.mount(&GeneratedTree { tree }, &|node| {
let geometry = rust_widgets::core::Rect::new(0, 0, 0, 0);
let text = node
.prop_value("text")
.or_else(|| node.prop_value("title"))
.and_then(|v| v.as_str())
.unwrap_or("");
create_for(&node.widget, geometry, text)
});
let _ = report;
}
/// The generated tree, as a `View`.
struct GeneratedTree {
tree: Node,
}
impl rust_widgets::view::View for GeneratedTree {
fn build(&self) -> Node {
self.tree.clone()
}
}
/// Builds one control for the generated tree.
///
/// The arms are exactly the widget types this file uses, so no name table is linked.
fn create_for(widget: &str, geometry: Rect, text: &str) -> Option<rust_widgets::core::ObjectId> {
let mut control: Option<Box<dyn rust_widgets::widget::Widget>> = match widget {
"button" => Some(Box::new(rust_widgets::widget::Button::new(text.to_string(), geometry))),
"label" => Some(Box::new(rust_widgets::widget::Label::new(text.to_string(), geometry))),
"slider" => Some(Box::new(rust_widgets::widget::Slider::new(geometry))),
"window" => Some(Box::new(rust_widgets::widget::Window::new(text.to_string(), geometry))),
_ => None,
};
// The registry assigns the id; a generated program has exactly one tree, so the
// returned id is the one `ViewEngine` will address it by.
control.take().map(|c| rust_widgets::widget::runtime::register(c)).flatten()
}