Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-widgets/src/builder.rs
StratoSDK / crates / strato-widgets / src / builder.rs
1//! Widget builder utilities
2 
3use crate::widget::Widget;
4// Removed unused strato_core::layout::Constraints import
5 
6/// Widget builder for fluent API
7pub struct WidgetBuilder<W: Widget> {
8 widget: W,
9}
10 
11impl<W: Widget> WidgetBuilder<W> {
12 /// Create a new widget builder
13 pub fn new(widget: W) -> Self {
14 Self { widget }
15 }
16 
17 /// Build the widget
18 pub fn build(self) -> W {
19 self.widget
20 }
21}
22 
23/// Extension trait for widget building
24pub trait BuilderExt: Sized {
25 /// Wrap in a builder
26 fn builder(self) -> WidgetBuilder<Self>
27 where
28 Self: Widget,
29 {
30 WidgetBuilder::new(self)
31 }
32}
33 
34impl<T> BuilderExt for T where T: Widget {}
35