core: center spinner over button content
This commit is contained in:
+29
-23
@@ -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(
|
||||||
Spinner::new((self.id.clone(), "spinner"))
|
h_flex().absolute().inset_0().justify_center().child(
|
||||||
.with_size(self.size)
|
Spinner::new((self.id.clone(), "spinner"))
|
||||||
.variant(crate::spinner::SpinnerVariant::Icon)
|
.with_size(self.size)
|
||||||
.color(foreground),
|
.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(
|
.child(
|
||||||
canvas(record_anchor_bounds(self.id.clone()), |_, _, _, _| {})
|
canvas(record_anchor_bounds(self.id.clone()), |_, _, _, _| {})
|
||||||
.absolute()
|
.absolute()
|
||||||
|
|||||||
@@ -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(
|
||||||
Spinner::new((self.id.clone(), "spinner"))
|
h_flex().absolute().inset_0().justify_center().child(
|
||||||
.with_size(self.size)
|
Spinner::new((self.id.clone(), "spinner"))
|
||||||
.variant(crate::spinner::SpinnerVariant::Icon)
|
.with_size(self.size)
|
||||||
.color(foreground),
|
.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 {
|
let main = if inert {
|
||||||
main
|
main
|
||||||
|
|||||||
Reference in New Issue
Block a user