StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use crate::elements::{ConstrainedBox, Empty, Flex, ParentElement}; |
| 2 | use crate::{ |
| 3 | elements::{Container, Element}, |
| 4 | ui_components::components::{UiComponent, UiComponentStyles}, |
| 5 | }; |
| 6 | |
| 7 | pub struct ProgressBar { |
| 8 | progress: f32, |
| 9 | styles: UiComponentStyles, |
| 10 | } |
| 11 | |
| 12 | impl UiComponent for ProgressBar { |
| 13 | type ElementType = Flex; |
| 14 | fn build(self) -> Flex { |
| 15 | let styles = self.styles; |
| 16 | let progress_width = self.progress * styles.width.unwrap(); |
| 17 | Flex::row() |
| 18 | .with_child( |
| 19 | ConstrainedBox::new( |
| 20 | Container::new(Empty::new().finish()) |
| 21 | .with_background(styles.foreground.unwrap()) |
| 22 | .finish(), |
| 23 | ) |
| 24 | .with_width(progress_width) |
| 25 | .with_height(styles.height.unwrap()) |
| 26 | .finish(), |
| 27 | ) |
| 28 | .with_child( |
| 29 | ConstrainedBox::new( |
| 30 | Container::new(Empty::new().finish()) |
| 31 | .with_background(styles.background.unwrap()) |
| 32 | .finish(), |
| 33 | ) |
| 34 | .with_width(styles.width.unwrap() - progress_width) |
| 35 | .with_height(styles.height.unwrap()) |
| 36 | .finish(), |
| 37 | ) |
| 38 | } |
| 39 | |
| 40 | fn with_style(self, styles: UiComponentStyles) -> Self { |
| 41 | ProgressBar { |
| 42 | styles: styles.merge(styles), |
| 43 | ..self |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | impl ProgressBar { |
| 49 | pub fn new(progress: f32, default_styles: UiComponentStyles) -> Self { |
| 50 | ProgressBar { |
| 51 | progress, |
| 52 | styles: default_styles, |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 |