Skip to content

Commit

Permalink
update styling for text_input
Browse files Browse the repository at this point in the history
  • Loading branch information
B0ney committed Nov 5, 2023
1 parent 1746699 commit f3abd6e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
9 changes: 6 additions & 3 deletions src/screen/config/custom_filters/file_size.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fmt::Display;

use crate::widget::helpers::control;
use crate::theme::TextInputStyle;
use crate::widget::Element;
use data::config::filters::{size::Modifier, Size};
use iced::widget::{column, pick_list, row, slider, text_input};
Expand All @@ -26,7 +27,8 @@ pub fn view<'a>(filter: &Size) -> Element<'a, Message> {
.parse::<u64>()
.map(Message::SetMin)
.unwrap_or(Message::Ignore)
}),
})
.style(TextInputStyle::Inverted),
pick_list(Modifier::ALL, Some(filter.min_modifier), Message::SetMinModifier)
]
.spacing(8)
Expand All @@ -35,14 +37,15 @@ pub fn view<'a>(filter: &Size) -> Element<'a, Message> {
"MAX:",
text_input("", &format!("{}", filter.max)).on_input(|input| {
if input.is_empty() {
return Message::SetMin(0);
return Message::SetMax(0);
}

input
.parse::<u64>()
.map(Message::SetMax)
.unwrap_or(Message::Ignore)
}),
})
.style(TextInputStyle::Inverted),
pick_list(Modifier::ALL, Some(filter.max_modifier), Message::SetMaxModifier)
]
.spacing(8)
Expand Down
33 changes: 23 additions & 10 deletions src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced::widget::{
button, checkbox, container, pick_list, progress_bar, radio, rule, scrollable, slider, text,
text_input, vertical_slider,
button, checkbox, container, pick_list, progress_bar, radio, rule, scrollable, slider, text, text_input,
vertical_slider,
};
use iced::{application, overlay, Background, Color};

Expand All @@ -14,7 +14,7 @@ impl Theme {
&self.0
}
// pub fn load(&mut self, theme: data::Theme) {
// let _ =
// let _ =
// }
}

Expand Down Expand Up @@ -129,9 +129,7 @@ impl button::StyleSheet for Theme {
}

fn pressed(&self, style: &Self::Style) -> button::Appearance {
button::Appearance {
..self.active(style)
}
button::Appearance { ..self.active(style) }
}
}

Expand Down Expand Up @@ -448,18 +446,33 @@ impl text::StyleSheet for Theme {
}
}

#[derive(Default, Clone, Copy)]
pub enum TextInputStyle {
#[default]
Normal,
Inverted,
}

impl text_input::StyleSheet for Theme {
type Style = ();
type Style = TextInputStyle;

fn active(&self, _style: &Self::Style) -> text_input::Appearance {
fn active(&self, style: &Self::Style) -> text_input::Appearance {
let p = self.inner();

text_input::Appearance {
let default = text_input::Appearance {
background: Background::Color(p.base.foreground),
border_radius: 8.0.into(),
border_width: 1.2,
border_color: p.base.border,
icon_color: p.base.foreground,
};

match style {
TextInputStyle::Normal => default,
TextInputStyle::Inverted => text_input::Appearance {
background: p.base.background.into(),
..default
},
}
}

Expand All @@ -485,7 +498,7 @@ impl text_input::StyleSheet for Theme {
}

fn selection_color(&self, _style: &Self::Style) -> iced::Color {
self.inner().normal.primary
Color { a: 0.5, ..self.inner().normal.primary}
}

fn disabled(&self, style: &Self::Style) -> text_input::Appearance {
Expand Down

0 comments on commit f3abd6e

Please sign in to comment.