Unified · Split
| @@ -319,10 +319,12 @@ impl Render for FeedbackModal { · 318 unmodified lines | |||
| 319 | "Characters: {}", | 319 | "Characters: {}", |
| 320 | characters_remaining | 320 | characters_remaining |
| 321 | )) | 321 | )) |
| 322 | .when_else( | 322 | .color( |
| 323 | valid_character_count, | 323 | if valid_character_count { |
| 324 | |this| this.color(Color::Success), | 324 | Color::Success |
| 325 | |this| this.color(Color::Error) | 325 | } else { |
| 326 | Color::Error | ||
| 327 | } | ||
| 326 | ) | 328 | ) |
| 327 | ), | 329 | ), |
| 328 | ) | 330 | ) |
| @@ -349,11 +351,13 @@ impl Render for FeedbackModal { · 20 unmodified lines | |||
| 349 | .color(Color::Muted) | 351 | .color(Color::Muted) |
| 350 | // TODO: replicate this logic when clicking outside the modal | 352 | // TODO: replicate this logic when clicking outside the modal |
| 351 | // TODO: Will require somehow overriding the modal dismal default behavior | 353 | // TODO: Will require somehow overriding the modal dismal default behavior |
| 352 | .when_else( | 354 | .map(|this| { |
| 353 | has_feedback, | 355 | if has_feedback { |
| 354 | |this| this.on_click(dismiss_prompt), | 356 | this.on_click(dismiss_prompt) |
| 355 | |this| this.on_click(dismiss) | 357 | } else { |
| 356 | ) | 358 | this.on_click(dismiss) |
| 359 | } | ||
| 360 | }) | ||
| 357 | ) | 361 | ) |
| 358 | .child( | 362 | .child( |
| 359 | Button::new("send_feedback", submit_button_text) | 363 | Button::new("send_feedback", submit_button_text) |
| @@ -69,24 +69,6 @@ pub trait IntoElement: Sized { · 68 unmodified lines | |||
| 69 | self.map(|this| if condition { then(this) } else { this }) | 69 | self.map(|this| if condition { then(this) } else { this }) |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | fn when_else( | ||
| 73 | self, | ||
| 74 | condition: bool, | ||
| 75 | then: impl FnOnce(Self) -> Self, | ||
| 76 | otherwise: impl FnOnce(Self) -> Self, | ||
| 77 | ) -> Self | ||
| 78 | where | ||
| 79 | Self: Sized, | ||
| 80 | { | ||
| 81 | self.map(|this| { | ||
| 82 | if condition { | ||
| 83 | then(this) | ||
| 84 | } else { | ||
| 85 | otherwise(this) | ||
| 86 | } | ||
| 87 | }) | ||
| 88 | } | ||
| 89 | |||
| 90 | fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self | 72 | fn when_some<T>(self, option: Option<T>, then: impl FnOnce(Self, T) -> Self) -> Self |
| 91 | where | 73 | where |
| 92 | Self: Sized, | 74 | Self: Sized, |
| @@ -98,11 +98,13 @@ impl RenderOnce for Key { · 97 unmodified lines | |||
| 98 | 98 | ||
| 99 | div() | 99 | div() |
| 100 | .py_0() | 100 | .py_0() |
| 101 | .when_else( | 101 | .map(|this| { |
| 102 | single_char, | 102 | if single_char { |
| 103 | |el| el.w(rems(14. / 16.)).flex().flex_none().justify_center(), | 103 | this.w(rems(14. / 16.)).flex().flex_none().justify_center() |
| 104 | |el| el.px_0p5(), | 104 | } else { |
| 105 | ) | 105 | this.px_0p5() |
| 106 | } | ||
| 107 | }) | ||
| 106 | .h(rems(14. / 16.)) | 108 | .h(rems(14. / 16.)) |
| 107 | .text_ui() | 109 | .text_ui() |
| 108 | .line_height(relative(1.)) | 110 | .line_height(relative(1.)) |