Skip to content

Commit b81fa8c

Browse files
committed
make unavailable mods less intrusive.
1 parent 5c7ba42 commit b81fa8c

File tree

2 files changed

+66
-51
lines changed

2 files changed

+66
-51
lines changed

src/main.rs

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![windows_subsystem = "windows"]
22

33
use anyhow::Result;
4-
use iced::alignment::Horizontal;
54
use iced::futures::TryFutureExt;
65
use serde::Deserialize;
76

@@ -11,7 +10,7 @@ mod install_velvet;
1110
mod theme;
1211
pub mod write_json;
1312

14-
use iced::widget::{Column, Space, button, checkbox, column, pick_list, text};
13+
use iced::widget::{Column, Space, button, checkbox, column, container, pick_list, text, tooltip};
1514
use iced::{Alignment, Element, Length, Size, Task, Theme, application, theme::Palette, window};
1615

1716
#[derive(Deserialize)]
@@ -51,7 +50,7 @@ enum Status {
5150
Idle,
5251
Installing,
5352
NoVersion,
54-
Success(Option<Vec<String>>),
53+
Success(Vec<String>),
5554
Failure(String),
5655
}
5756

@@ -124,16 +123,16 @@ impl Velvet {
124123
};
125124
}
126125
Message::Done(value) => match value {
127-
Ok(x) => match x.is_empty() {
128-
true => self.status = Status::Success(None),
129-
false => {
130-
self.status = Status::Success(Some(x));
126+
Ok(x) => {
127+
let missing_mods = !x.is_empty();
128+
self.status = Status::Success(x);
129+
if missing_mods {
131130
return window::get_latest()
132-
.and_then(move |id| window::resize(id, (500.0, 350.0).into()));
133-
}
134-
},
135-
Err(x) => {
136-
self.status = Status::Failure(x);
131+
.and_then(move |id| window::resize(id, (500.0, 275.0).into()));
132+
};
133+
}
134+
Err(e) => {
135+
self.status = Status::Failure(e);
137136
return window::get_latest()
138137
.and_then(move |id| window::resize(id, (500.0, 275.0).into()));
139138
}
@@ -143,75 +142,74 @@ impl Velvet {
143142
}
144143

145144
fn view(&self) -> Column<Message> {
146-
let (button_message, extra_message): (&str, Element<Message>) = match &self.status {
147-
Status::Idle => ("Install", column!().into()),
148-
Status::Installing => ("Installing...", column!().into()),
149-
Status::NoVersion => ("No version selected!", column!().into()),
145+
let (button_message, extra_message): (&str, Option<Element<Message>>) = match &self.status {
146+
Status::Idle => ("Install", None),
147+
Status::Installing => ("Installing...", None),
148+
Status::NoVersion => ("No version selected!", None),
150149
Status::Success(mods) => (
151150
"Finished!",
152-
match mods {
153-
Some(mods) => {
151+
if !mods.is_empty() {
152+
Some({
154153
let mut mod_string = String::new();
155154
mod_string.push_str(&mods[0]);
156155
for name in mods.iter().skip(1) {
157156
mod_string.push_str(", ");
158157
mod_string.push_str(name);
159158
}
160-
column![
161-
text("The mods"),
162-
text(mod_string)
163-
.color(theme::LOVE)
164-
.align_x(Horizontal::Center),
165-
text("were unavailable.")
166-
]
167-
.align_x(Alignment::Center)
159+
tooltip(
160+
"Hover to see unavailable mods.",
161+
container(text(mod_string)),
162+
tooltip::Position::FollowCursor,
163+
)
164+
.style(theme::container_style)
168165
.into()
169-
}
170-
None => column!().into(),
166+
})
167+
} else {
168+
None
171169
},
172170
),
173-
Status::Failure(message) => ("Error!", text(message).color(theme::LOVE).into()),
171+
Status::Failure(e) => ("Error!", Some(text(e).color(theme::LOVE).into())),
174172
};
173+
175174
column![
176-
Space::with_height(Length::Fixed(10.0)),
177175
text("Enter Minecraft version:").size(20),
178-
Space::with_height(Length::Fixed(5.0)),
179176
pick_list(
180177
self.version_list.clone(),
181178
self.version.clone(),
182179
Message::Update
183180
)
184181
.placeholder("Loading...")
185182
.width(Length::Fixed(200.0))
186-
.style(|_, status| theme::pick_list_style(status))
187-
.menu_style(|_| theme::menu_style()),
188-
Space::with_height(Length::Fixed(5.0)),
183+
.style(theme::pick_list_style)
184+
.menu_style(theme::menu_style),
185+
Space::with_height(Length::Fill),
189186
checkbox("Show snapshots", self.snapshot)
190187
.on_toggle(Message::Snapshot)
191-
.style(|_, status| theme::checkbox_style(status)),
192-
Space::with_height(Length::Fill),
188+
.style(theme::checkbox_style),
193189
column![
194190
checkbox("Vanilla - Performance enhancing modlist.", self.vanilla,)
195191
.on_toggle(Message::VButton)
196-
.style(|_, status| theme::checkbox_style(status)),
197-
Space::with_height(Length::Fixed(5.0)),
192+
.style(theme::checkbox_style),
198193
checkbox("Beauty - Immersive and beautiful modlist.", self.beauty,)
199194
.on_toggle(Message::BButton)
200-
.style(|_, status| theme::checkbox_style(status)),
201-
Space::with_height(Length::Fixed(5.0)),
195+
.style(theme::checkbox_style),
202196
checkbox("Optifine - Optifine resource pack parity.", self.optifine,)
203197
.on_toggle(Message::OButton)
204-
.style(|_, status| theme::checkbox_style(status)),
198+
.style(theme::checkbox_style),
205199
]
206200
.align_x(Alignment::Start),
207201
Space::with_height(Length::Fill),
208-
extra_message,
209-
Space::with_height(Length::Fill),
210202
button(button_message)
211203
.on_press(Message::Pressed)
212-
.style(|_, status| theme::button_style(status)),
213-
Space::with_height(Length::Fixed(10.0)),
204+
.style(theme::button_style),
205+
if let Some(message) = extra_message {
206+
message
207+
} else {
208+
column![].into()
209+
},
214210
]
211+
.spacing(5.0)
212+
.padding(10.0)
215213
.align_x(Alignment::Center)
216214
.width(Length::Fill)
217215
.height(Length::Fill)

src/theme.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use iced::{
2-
Background, Border, Color, Shadow, Vector,
2+
Background, Border, Color, Shadow, Theme, Vector,
33
border::Radius,
44
color,
55
overlay::menu,
6-
widget::{button, checkbox, pick_list},
6+
widget::{button, checkbox, container, pick_list},
77
};
88

99
// rosé pine.
@@ -15,7 +15,24 @@ pub const SUBTLE: Color = color!(0x908caa);
1515
pub const LOVE: Color = color!(0xeb6f92);
1616
pub const FOAM: Color = color!(0x9ccfd8);
1717

18-
pub fn pick_list_style(status: pick_list::Status) -> pick_list::Style {
18+
pub fn container_style(_: &Theme) -> container::Style {
19+
container::Style {
20+
text_color: None,
21+
background: Some(Background::Color(BASE)),
22+
border: Border {
23+
color: LOVE,
24+
width: 1.0,
25+
radius: Radius::new(10.0),
26+
},
27+
shadow: Shadow {
28+
color: BASE,
29+
offset: Vector::new(0.0, 0.0),
30+
blur_radius: 0.0,
31+
},
32+
}
33+
}
34+
35+
pub fn pick_list_style(_: &Theme, status: pick_list::Status) -> pick_list::Style {
1936
pick_list::Style {
2037
text_color: TEXT,
2138
placeholder_color: SUBTLE,
@@ -32,7 +49,7 @@ pub fn pick_list_style(status: pick_list::Status) -> pick_list::Style {
3249
}
3350
}
3451

35-
pub fn menu_style() -> menu::Style {
52+
pub fn menu_style(_: &Theme) -> menu::Style {
3653
menu::Style {
3754
text_color: TEXT,
3855
background: Background::Color(SURFACE),
@@ -46,7 +63,7 @@ pub fn menu_style() -> menu::Style {
4663
}
4764
}
4865

49-
pub fn checkbox_style(status: checkbox::Status) -> checkbox::Style {
66+
pub fn checkbox_style(_: &Theme, status: checkbox::Status) -> checkbox::Style {
5067
checkbox::Style {
5168
background: Background::Color(match status {
5269
checkbox::Status::Active { is_checked } if is_checked => FOAM,
@@ -64,7 +81,7 @@ pub fn checkbox_style(status: checkbox::Status) -> checkbox::Style {
6481
}
6582
}
6683

67-
pub fn button_style(status: button::Status) -> button::Style {
84+
pub fn button_style(_: &Theme, status: button::Status) -> button::Style {
6885
button::Style {
6986
background: Some(Background::Color(LOVE)),
7087
text_color: match status {

0 commit comments

Comments
 (0)