What’s the correct way of showing an error on a widget? I was thinking about something like the following:
/// Just an example style, I still need to choose a color palette.
const ACTIVE: Style = Style {
background: iced::Background::Color(Color::WHITE),
border: Border {
color: Color::BLACK,
width: 1.0,
radius: Radius {
top_left: 0.,
top_right: 0.,
bottom_right: 0.,
bottom_left: 0.,
},
},
icon: Color::BLACK,
placeholder: Color::BLACK,
value: Color::BLACK,
selection: Color::BLACK,
};
/// This helper function is used in the `view` method, everywhere I need a text input with this particular style.
pub fn custom_text_input<'a, Message>(
placeholder: &str,
value: &str,
is_error: bool,
) -> TextInput<'a, Message>
where
Message: 'a + Clone,
{
text_input(placeholder, value).style(|_, status| match status {
text_input::Status::Active => {
if is_error {
ACTIVE
else {
// I was thinking to duplicate the ACTIVE style, where the color of the border is red, for example.
ACTIVE_ERROR
},
text_input::Status::Hovered => todo!(),
text_input::Status::Focused => todo!(),
text_input::Status::Disabled => todo!(),
})
}
Is this the intended approach? What is everyone else using?