core: center spinner over button content

This commit is contained in:
2026-11-14 08:24:46 +07:00
parent c3e3c37731
commit 59ab6eb921
2 changed files with 46 additions and 35 deletions
+25 -19
View File
@@ -145,7 +145,7 @@ impl Button {
self self
} }
/// Shows the spinner in place of the icon and suppresses activation. /// Shows the spinner in place of the content and suppresses activation.
pub fn loading(mut self, loading: bool) -> Self { pub fn loading(mut self, loading: bool) -> Self {
self.loading = loading; self.loading = loading;
self self
@@ -271,7 +271,6 @@ impl RenderOnce for Button {
.when(self.icon.is_none(), |button| button.px(metrics.padding_x)) .when(self.icon.is_none(), |button| button.px(metrics.padding_x))
}) })
.line_height(relative(1.0)) .line_height(relative(1.0))
.gap_2()
.rounded(theme.radius.control) .rounded(theme.radius.control)
.text_size(metrics.text_size) .text_size(metrics.text_size)
.border_1() .border_1()
@@ -279,31 +278,38 @@ impl RenderOnce for Button {
.when_some(background, |button, background| button.bg(background)) .when_some(background, |button, background| button.bg(background))
.text_color(foreground) .text_color(foreground)
.when_some(a11y_label, |button, label| button.aria_label(label)) .when_some(a11y_label, |button, label| button.aria_label(label))
.child(
h_flex()
.gap_2()
.when(self.loading, |content| content.invisible())
.map(|content| {
if icon_trailing {
content
.when_some(self.label, |content, label| content.child(label))
.children(self.children)
.when_some(self.icon, |content, icon| {
content.child(icon.size(metrics.icon_size).color(foreground))
})
} else {
content
.when_some(self.icon, |content, icon| {
content.child(icon.size(metrics.icon_size).color(foreground))
})
.when_some(self.label, |content, label| content.child(label))
.children(self.children)
}
}),
)
.when(self.loading, |button| { .when(self.loading, |button| {
button.child( button.child(
h_flex().absolute().inset_0().justify_center().child(
Spinner::new((self.id.clone(), "spinner")) Spinner::new((self.id.clone(), "spinner"))
.with_size(self.size) .with_size(self.size)
.variant(crate::spinner::SpinnerVariant::Icon) .variant(crate::spinner::SpinnerVariant::Icon)
.color(foreground), .color(foreground),
),
) )
}) })
.when(!self.loading, |button| {
if icon_trailing {
button
.when_some(self.label, |button, label| button.child(label))
.children(self.children)
.when_some(self.icon, |button, icon| {
button.child(icon.size(metrics.icon_size).color(foreground))
})
} else {
button
.when_some(self.icon, |button, icon| {
button.child(icon.size(metrics.icon_size).color(foreground))
})
.when_some(self.label, |button, label| button.child(label))
.children(self.children)
}
})
.child( .child(
canvas(record_anchor_bounds(self.id.clone()), |_, _, _, _| {}) canvas(record_anchor_bounds(self.id.clone()), |_, _, _, _| {})
.absolute() .absolute()
+13 -8
View File
@@ -104,7 +104,7 @@ impl DropdownMenu {
self self
} }
/// Shows the spinner in place of the icon and suppresses activation. /// Shows the spinner in place of the content and suppresses activation.
pub fn loading(mut self, loading: bool) -> Self { pub fn loading(mut self, loading: bool) -> Self {
self.loading = loading; self.loading = loading;
self self
@@ -275,20 +275,25 @@ impl RenderOnce for DropdownMenu {
.color(foreground), .color(foreground),
) )
}) })
.child(
h_flex()
.gap_2()
.when(self.loading, |content| content.invisible())
.when_some(self.icon, |content, icon| {
content.child(icon.size(metrics.icon_size).color(foreground))
})
.when_some(self.label, |content, label| content.child(label)),
)
.when(self.loading, |zone| { .when(self.loading, |zone| {
zone.child( zone.child(
h_flex().absolute().inset_0().justify_center().child(
Spinner::new((self.id.clone(), "spinner")) Spinner::new((self.id.clone(), "spinner"))
.with_size(self.size) .with_size(self.size)
.variant(crate::spinner::SpinnerVariant::Icon) .variant(crate::spinner::SpinnerVariant::Icon)
.color(foreground), .color(foreground),
),
) )
}) });
.when(!self.loading, |zone| {
zone.when_some(self.icon, |zone, icon| {
zone.child(icon.size(metrics.icon_size).color(foreground))
})
})
.when_some(self.label, |zone, label| zone.child(label));
let main = if inert { let main = if inert {
main main