cushy/guide/guide-examples/examples/composition-makewidget.rs
Jonathan Johnson 15b8b3e452
Moved example generation into cushy
Undocumented and unsupported, but this allows generating example images.

This push is testing that the image makes it through CI.

Refs #125
2024-05-12 07:58:09 -07:00

50 lines
1.1 KiB
Rust

use cushy::value::{Dynamic, IntoValue, Value};
use cushy::widgets::input::InputValue;
fn composition_makewidget() -> impl cushy::widget::MakeWidget {
// ANCHOR: definition
use cushy::widget::{MakeWidget, WidgetInstance};
struct FormField {
label: Value<String>,
field: WidgetInstance,
}
impl FormField {
pub fn new(label: impl IntoValue<String>, field: impl MakeWidget) -> Self {
Self {
label: label.into_value(),
field: field.make_widget(),
}
}
}
// ANCHOR_END: definition
// ANCHOR: makewidget
impl MakeWidget for FormField {
fn make_widget(self) -> WidgetInstance {
self.label
.align_left()
.and(self.field)
.into_rows()
.make_widget()
}
}
FormField::new(
"Label",
Dynamic::<String>::default()
.into_input()
.placeholder("Field"),
)
// ANCHOR_END: makewidget
}
fn main() {
cushy::example!(composition_makewidget).untested_still_frame();
}
#[test]
fn runs() {
main();
}