StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | //! Widget builder utilities |
| 2 | |
| 3 | use crate::widget::Widget; |
| 4 | // Removed unused strato_core::layout::Constraints import |
| 5 | |
| 6 | /// Widget builder for fluent API |
| 7 | pub struct WidgetBuilder<W: Widget> { |
| 8 | widget: W, |
| 9 | } |
| 10 | |
| 11 | impl<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 |
| 24 | pub 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 | |
| 34 | impl<T> BuilderExt for T where T: Widget {} |
| 35 |