Remove when_else

Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
Joseph T. Lyons 2023-12-07 12:37:07 -05:00
parent 393be3cedf
commit 7c19650a40
3 changed files with 20 additions and 32 deletions

View File

@ -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)

View File

@ -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,

View File

@ -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.))