add sizable trait
This commit is contained in:
@@ -8,7 +8,9 @@ use gpui::{
|
||||
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||
Styled as _, Window, div, relative,
|
||||
};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
|
||||
use crate::common::Sizable;
|
||||
|
||||
/// A progress bar. With a `value` in `0..=1` it paints a determinate fill.
|
||||
#[derive(IntoElement)]
|
||||
@@ -16,6 +18,7 @@ pub struct Progress {
|
||||
id: ElementId,
|
||||
value: f32,
|
||||
indeterminate: bool,
|
||||
size: Size,
|
||||
a11y_label: Option<SharedString>,
|
||||
}
|
||||
|
||||
@@ -29,6 +32,7 @@ impl Progress {
|
||||
id: id.into(),
|
||||
value,
|
||||
indeterminate: false,
|
||||
size: Size::default(),
|
||||
a11y_label: None,
|
||||
}
|
||||
}
|
||||
@@ -49,12 +53,21 @@ impl Progress {
|
||||
}
|
||||
}
|
||||
|
||||
impl Sizable for Progress {
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Progress {
|
||||
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors;
|
||||
let ramps = theme.ramps;
|
||||
let radius = theme.radius;
|
||||
let metrics = theme.sizes.resolve(self.size);
|
||||
|
||||
let track_height = metrics.icon_size / 4.0;
|
||||
let value = self.value.clamp(0.0, 1.0);
|
||||
|
||||
div()
|
||||
@@ -73,7 +86,7 @@ impl RenderOnce for Progress {
|
||||
.child(
|
||||
div()
|
||||
.w_full()
|
||||
.h_1p5()
|
||||
.h(track_height)
|
||||
.rounded(radius.full)
|
||||
.bg(colors.border)
|
||||
.child(if self.indeterminate {
|
||||
|
||||
Reference in New Issue
Block a user