add sizable trait

This commit is contained in:
2026-10-29 07:56:23 +07:00
parent 3808b1519f
commit 1b29c2c940
19 changed files with 442 additions and 69 deletions
+15 -2
View File
@@ -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 {