core: center spinner over button content
This commit is contained in:
+25
-19
@@ -145,7 +145,7 @@ impl Button {
|
||||
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 {
|
||||
self.loading = loading;
|
||||
self
|
||||
@@ -271,7 +271,6 @@ impl RenderOnce for Button {
|
||||
.when(self.icon.is_none(), |button| button.px(metrics.padding_x))
|
||||
})
|
||||
.line_height(relative(1.0))
|
||||
.gap_2()
|
||||
.rounded(theme.radius.control)
|
||||
.text_size(metrics.text_size)
|
||||
.border_1()
|
||||
@@ -279,31 +278,38 @@ impl RenderOnce for Button {
|
||||
.when_some(background, |button, background| button.bg(background))
|
||||
.text_color(foreground)
|
||||
.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| {
|
||||
button.child(
|
||||
h_flex().absolute().inset_0().justify_center().child(
|
||||
Spinner::new((self.id.clone(), "spinner"))
|
||||
.with_size(self.size)
|
||||
.variant(crate::spinner::SpinnerVariant::Icon)
|
||||
.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(
|
||||
canvas(record_anchor_bounds(self.id.clone()), |_, _, _, _| {})
|
||||
.absolute()
|
||||
|
||||
@@ -104,7 +104,7 @@ impl DropdownMenu {
|
||||
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 {
|
||||
self.loading = loading;
|
||||
self
|
||||
@@ -275,20 +275,25 @@ impl RenderOnce for DropdownMenu {
|
||||
.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| {
|
||||
zone.child(
|
||||
h_flex().absolute().inset_0().justify_center().child(
|
||||
Spinner::new((self.id.clone(), "spinner"))
|
||||
.with_size(self.size)
|
||||
.variant(crate::spinner::SpinnerVariant::Icon)
|
||||
.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 {
|
||||
main
|
||||
|
||||
Reference in New Issue
Block a user