Skip to content

Commit 0b1c448

Browse files
authored
Merge pull request #51 from unsecretised/styling
Improve styling code
2 parents 3980175 + f943f05 commit 0b1c448

2 files changed

Lines changed: 31 additions & 22 deletions

File tree

src/app.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ impl App {
6161
},
6262
]
6363
}
64-
pub fn render(&self, show_icons: bool) -> impl Into<iced::Element<'_, Message>> {
64+
pub fn render(&self, theme: &crate::config::Theme) -> impl Into<iced::Element<'_, Message>> {
6565
let mut tile = Row::new().width(Fill).height(55);
6666

67-
if show_icons {
67+
if theme.show_icons {
6868
if let Some(icon) = &self.icons {
6969
tile = tile
7070
.push(Viewer::new(icon).height(35).width(35))
@@ -83,6 +83,7 @@ impl App {
8383
Text::new(&self.name)
8484
.height(Fill)
8585
.width(Fill)
86+
.color(theme.text_color(1.))
8687
.align_y(Vertical::Center),
8788
)
8889
.on_press(Message::RunFunction(self.open_command.clone()))
@@ -98,7 +99,7 @@ impl App {
9899
);
99100

100101
tile = tile
101-
.push(container(Text::new(&self.desc)).padding(15))
102+
.push(container(Text::new(&self.desc).color(theme.text_color(0.4))).padding(15))
102103
.width(Fill);
103104

104105
container(tile)
@@ -204,7 +205,7 @@ impl Tile {
204205
frontmost: None,
205206
focused: false,
206207
config: config.clone(),
207-
theme: config.theme.to_owned().to_iced_theme(),
208+
theme: config.theme.to_owned().into(),
208209
open_hotkey_id: keybind_id,
209210
},
210211
Task::batch([open.map(|_| Message::OpenWindow)]),
@@ -394,8 +395,7 @@ impl Tile {
394395

395396
let mut search_results = Column::new();
396397
for result in &self.results {
397-
search_results =
398-
search_results.push(result.render(self.config.theme.clone().show_icons));
398+
search_results = search_results.push(result.render(&self.config.theme));
399399
}
400400

401401
Column::new()

src/config.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,11 @@ impl Default for Theme {
5555
}
5656
}
5757

58-
impl Theme {
59-
pub fn to_iced_theme(&self) -> iced::Theme {
60-
let text_color = self.text_color;
61-
let bg_color = self.background_color;
58+
impl From<Theme> for iced::Theme {
59+
fn from(value: Theme) -> Self {
6260
let palette = iced::theme::Palette {
63-
background: iced::Color {
64-
r: bg_color.0,
65-
g: bg_color.1,
66-
b: bg_color.2,
67-
a: self.background_opacity,
68-
},
69-
text: iced::Color {
70-
r: text_color.0,
71-
g: text_color.1,
72-
b: text_color.2,
73-
a: 1.,
74-
},
61+
background: value.bg_color(),
62+
text: value.text_color(1.),
7563
primary: iced::Color {
7664
r: 0.22,
7765
g: 0.55,
@@ -101,6 +89,27 @@ impl Theme {
10189
}
10290
}
10391

92+
impl Theme {
93+
pub fn text_color(&self, opacity: f32) -> iced::Color {
94+
let theme = self.to_owned();
95+
iced::Color {
96+
r: theme.text_color.0,
97+
g: theme.text_color.1,
98+
b: theme.text_color.2,
99+
a: opacity,
100+
}
101+
}
102+
103+
pub fn bg_color(&self) -> iced::Color {
104+
iced::Color {
105+
r: self.background_color.0,
106+
g: self.background_color.1,
107+
b: self.background_color.2,
108+
a: self.background_opacity,
109+
}
110+
}
111+
}
112+
104113
#[derive(Debug, Clone, Deserialize, Serialize)]
105114
#[serde(default)]
106115
pub struct Buffer {

0 commit comments

Comments
 (0)