add sizable trait
This commit is contained in:
@@ -4,9 +4,9 @@ use gpui::{
|
||||
RenderOnce, Role, SharedString, StatefulInteractiveElement as _, Styled as _, Toggled, Window,
|
||||
div, px,
|
||||
};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
use gpui_native_theme::{ActiveTheme as _, Size};
|
||||
|
||||
use crate::common::{h_flex, v_flex};
|
||||
use crate::common::{Sizable, h_flex, v_flex};
|
||||
|
||||
/// The group's change reporter, fired with the clicked radio's value.
|
||||
type ChangeHandler<V> = std::rc::Rc<dyn Fn(V, &mut Window, &mut App)>;
|
||||
@@ -72,6 +72,7 @@ where
|
||||
id: ElementId,
|
||||
selected: Option<V>,
|
||||
children: Vec<Radio<V>>,
|
||||
size: Size,
|
||||
a11y_label: Option<SharedString>,
|
||||
on_change: Option<ChangeHandler<V>>,
|
||||
}
|
||||
@@ -89,6 +90,7 @@ where
|
||||
id: id.into(),
|
||||
selected: None,
|
||||
children: Vec::new(),
|
||||
size: Size::default(),
|
||||
a11y_label: None,
|
||||
on_change: None,
|
||||
}
|
||||
@@ -125,6 +127,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> Sizable for RadioGroup<V>
|
||||
where
|
||||
V: Clone + PartialEq + 'static,
|
||||
{
|
||||
fn apply_size(&mut self, size: Size) {
|
||||
self.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> RenderOnce for RadioGroup<V>
|
||||
where
|
||||
V: Clone + PartialEq + 'static,
|
||||
@@ -134,6 +145,7 @@ where
|
||||
let colors = theme.colors;
|
||||
let ramps = theme.ramps;
|
||||
let radius = theme.radius;
|
||||
let metrics = theme.sizes.resolve(self.size);
|
||||
let selected = self.selected;
|
||||
let on_change = self.on_change;
|
||||
let group_label = self.a11y_label;
|
||||
@@ -141,7 +153,7 @@ where
|
||||
v_flex()
|
||||
.id(self.id)
|
||||
.gap_2()
|
||||
.text_sm()
|
||||
.text_size(metrics.text_size)
|
||||
.role(Role::RadioGroup)
|
||||
.when_some(group_label.clone(), |group, label| group.aria_label(label))
|
||||
.children(self.children.into_iter().map(move |radio| {
|
||||
@@ -182,7 +194,7 @@ where
|
||||
h_flex()
|
||||
.justify_center()
|
||||
.flex_none()
|
||||
.size_4()
|
||||
.size(metrics.icon_size)
|
||||
.rounded(radius.full)
|
||||
.border_1()
|
||||
.when(is_selected, |indicator| {
|
||||
@@ -192,7 +204,7 @@ where
|
||||
.hover(|style| style.bg(ramps.primary.hover))
|
||||
.child(
|
||||
div()
|
||||
.size_2()
|
||||
.size(metrics.icon_size / 2.0)
|
||||
.rounded(radius.full)
|
||||
.bg(colors.primary_foreground),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user