Change summary
crates/feedback2/src/feedback_modal.rs | 22 +++++++++++++---------
crates/gpui2/src/element.rs | 18 ------------------
crates/ui2/src/components/keybinding.rs | 12 +++++++-----
3 files changed, 20 insertions(+), 32 deletions(-)
Detailed changes
@@ -319,10 +319,12 @@ impl Render for FeedbackModal {
"Characters: {}",
characters_remaining
))
- .when_else(
- valid_character_count,
- |this| this.color(Color::Success),
- |this| this.color(Color::Error)
+ .color(
+ if valid_character_count {
+ Color::Success
+ } else {
+ Color::Error
+ }
)
),
)
@@ -349,11 +351,13 @@ impl Render for FeedbackModal {
.color(Color::Muted)
// TODO: replicate this logic when clicking outside the modal
// TODO: Will require somehow overriding the modal dismal default behavior
- .when_else(
- has_feedback,
- |this| this.on_click(dismiss_prompt),
- |this| this.on_click(dismiss)
- )
+ .map(|this| {
+ if has_feedback {
+ this.on_click(dismiss_prompt)
+ } else {
+ this.on_click(dismiss)
+ }
+ })
)
.child(
Button::new("send_feedback", submit_button_text)
@@ -69,24 +69,6 @@ pub trait IntoElement: Sized {
self.map(|this| if condition { then(this) } else { this })
}
- fn when_else(
- self,
- condition: bool,
- then: impl FnOnce(Self) -> Self,
- otherwise: impl FnOnce(Self) -> Self,
- ) -> Self
- where
- Self: Sized,
- {
- self.map(|this| {
- if condition {
- then(this)
- } else {
- otherwise(this)
- }
- })
- }
-
fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self
where
Self: Sized,
@@ -98,11 +98,13 @@ impl RenderOnce for Key {
div()
.py_0()
- .when_else(
- single_char,
- |el| el.w(rems(14. / 16.)).flex().flex_none().justify_center(),
- |el| el.px_0p5(),
- )
+ .map(|this| {
+ if single_char {
+ this.w(rems(14. / 16.)).flex().flex_none().justify_center()
+ } else {
+ this.px_0p5()
+ }
+ })
.h(rems(14. / 16.))
.text_ui()
.line_height(relative(1.))