mirror of
https://github.com/danbulant/cushy
synced 2026-05-19 20:28:42 +00:00
Undocumented and unsupported, but this allows generating example images. This push is testing that the image makes it through CI. Refs #125
50 lines
1.1 KiB
Rust
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();
|
|
}
|