Skip to content

Commit 56c142f

Browse files
committed
Bump version to 0.5.0 and move GUI logic to module
1 parent 8bd135f commit 56c142f

File tree

4 files changed

+137
-131
lines changed

4 files changed

+137
-131
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "explora_map_poll"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
edition = "2021"
55
authors = ["Maarten Van Coile <maarten.vancoile@me.com>"]
66
license = "MIT OR Apache-2.0"
@@ -14,8 +14,6 @@ iced = "0.14"
1414

1515
[package.metadata.bundle]
1616
# This section is used by `cargo-bundle` to generate OS-specific bundles.
17-
18-
# General bundle metadata
1917
name = "Explora Map Poll"
2018
identifier = "eu.maartenvancoile.explora_map_poll"
2119
icon = [

src/application.rs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
use std::time::Duration;
2+
3+
use iced::widget::{button, checkbox, column, container, row, scrollable, space, text, tooltip};
4+
use iced::{clipboard, Task};
5+
use iced::{Alignment, Element, Length};
6+
7+
const MAP_SIZES: [u32; 4] = [3500, 3750, 4000, 4250];
8+
const MAX_SEED: u32 = 2_147_483_645;
9+
10+
#[derive(Debug, Clone)]
11+
pub enum Message {
12+
RefreshPressed,
13+
CopyPressed,
14+
StagingToggled(bool),
15+
}
16+
17+
#[derive(Default)]
18+
pub struct App {
19+
poll: String,
20+
staging: bool,
21+
}
22+
23+
impl App {
24+
pub fn new() -> Self {
25+
let mut app = Self::default();
26+
app.refresh_seed();
27+
app.staging = false;
28+
app
29+
}
30+
31+
pub fn refresh_seed(&mut self) {
32+
let mut temp = String::from("/poll topic::world_map: Next map vote! :world_map:");
33+
for (i, size) in MAP_SIZES.into_iter().enumerate() {
34+
temp.push_str(
35+
format!(
36+
"\noption{index}:Map {size}: https://rustmaps.com/map/{size}_{seed}",
37+
index = i + 1,
38+
seed = fastrand::u32(..MAX_SEED)
39+
)
40+
.as_str(),
41+
);
42+
if self.staging {
43+
temp.push_str("/staging");
44+
}
45+
}
46+
self.poll = temp;
47+
}
48+
49+
pub fn update(app: &mut App, message: Message) -> Task<Message> {
50+
match message {
51+
Message::RefreshPressed => {
52+
app.refresh_seed();
53+
Task::none()
54+
}
55+
Message::CopyPressed => clipboard::write(app.poll.clone()),
56+
Message::StagingToggled(value) => {
57+
app.staging = value;
58+
app.refresh_seed();
59+
Task::none()
60+
}
61+
}
62+
}
63+
64+
pub fn view(app: &App) -> Element<'_, Message> {
65+
let text = text(app.poll.to_string());
66+
let refresh_button = button("Refresh")
67+
.style(button::secondary)
68+
.on_press(Message::RefreshPressed);
69+
let copy_button = button("Copy")
70+
.style(button::primary)
71+
.on_press(Message::CopyPressed);
72+
let staging_check = checkbox(app.staging)
73+
.label("Staging Maps")
74+
.on_toggle(Message::StagingToggled);
75+
76+
// To turn on debug grid, wrap the container (before the .into()) with the following:
77+
// iced::Element::new(your_widget).explain(iced::Color::BLACK)
78+
container(
79+
column![
80+
container(scrollable(
81+
text.size(16).height(Length::Fill).width(Length::Fill)
82+
))
83+
.style(container::bordered_box)
84+
.padding(10)
85+
.height(Length::Fill)
86+
.width(Length::Fill),
87+
row![
88+
tooltip(
89+
staging_check,
90+
container("Check this box to enable staging maps.")
91+
.padding(10)
92+
.style(container::rounded_box)
93+
.style(container::warning),
94+
tooltip::Position::Top,
95+
)
96+
.delay(Duration::from_secs(1)),
97+
space().width(Length::Fill),
98+
tooltip(
99+
refresh_button,
100+
container("Get new random seeds for the 4 maps.")
101+
.padding(10)
102+
.style(container::rounded_box)
103+
.style(container::warning),
104+
tooltip::Position::Top,
105+
)
106+
.delay(Duration::from_secs(1)),
107+
tooltip(
108+
copy_button,
109+
container("Copy the /poll text onto your clipboard.")
110+
.padding(10)
111+
.style(container::rounded_box)
112+
.style(container::warning),
113+
tooltip::Position::Top,
114+
)
115+
.delay(Duration::from_secs(1)),
116+
]
117+
.spacing(18)
118+
.align_y(Alignment::Center),
119+
]
120+
.align_x(Alignment::End)
121+
.spacing(20),
122+
)
123+
.padding(20)
124+
.height(Length::Fill)
125+
.width(Length::Fill)
126+
.center_x(Length::Fill)
127+
.center_y(Length::Fill)
128+
.into()
129+
}
130+
}

src/main.rs

Lines changed: 5 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,11 @@
1-
use std::time::Duration;
1+
mod application;
22

3-
use iced::widget::{button, checkbox, column, container, row, scrollable, space, text, tooltip};
4-
use iced::{clipboard, window, Task};
5-
use iced::{Alignment, Element, Length, Size};
6-
7-
#[derive(Debug, Clone)]
8-
pub enum Message {
9-
RefreshPressed,
10-
CopyPressed,
11-
StagingToggled(bool),
12-
}
13-
14-
#[derive(Default)]
15-
pub struct App {
16-
poll: String,
17-
staging: bool,
18-
}
19-
20-
impl App {
21-
pub fn new() -> Self {
22-
let mut app = Self::default();
23-
app.refresh_seed();
24-
app.staging = false;
25-
app
26-
}
27-
28-
fn refresh_seed(&mut self) {
29-
let mut temp = String::from("/poll topic::world_map: Next map vote! :world_map:");
30-
for (i, size) in [3500, 3750, 4000, 4250].into_iter().enumerate() {
31-
temp.push_str(
32-
format!(
33-
"\noption{index}:Map {size}: https://rustmaps.com/map/{size}_{seed}",
34-
index = i + 1,
35-
seed = fastrand::u32(..2147483645)
36-
)
37-
.as_str(),
38-
);
39-
if self.staging {
40-
temp.push_str("/staging");
41-
}
42-
}
43-
self.poll = temp;
44-
}
45-
}
3+
use application::App;
4+
use iced::window;
5+
use iced::Size;
466

477
fn main() -> iced::Result {
48-
iced::application(App::new, update, view)
8+
iced::application(App::new, App::update, App::view)
499
.title("Rust Map Poll for Discord")
5010
// .theme(Theme::Nord)
5111
.window(window::Settings {
@@ -58,85 +18,3 @@ fn main() -> iced::Result {
5818
})
5919
.run()
6020
}
61-
62-
fn update(app: &mut App, message: Message) -> Task<Message> {
63-
match message {
64-
Message::RefreshPressed => {
65-
app.refresh_seed();
66-
Task::none()
67-
}
68-
Message::CopyPressed => clipboard::write(app.poll.clone()),
69-
Message::StagingToggled(value) => {
70-
app.staging = value;
71-
app.refresh_seed();
72-
Task::none()
73-
}
74-
}
75-
}
76-
77-
fn view(app: &App) -> Element<'_, Message> {
78-
let text = text(app.poll.to_string());
79-
let refresh_button = button("Refresh")
80-
.style(button::secondary)
81-
.on_press(Message::RefreshPressed);
82-
let copy_button = button("Copy")
83-
.style(button::primary)
84-
.on_press(Message::CopyPressed);
85-
let staging_check = checkbox(app.staging)
86-
.label("Staging Maps")
87-
.on_toggle(Message::StagingToggled);
88-
89-
// To turn on debug grid, wrap the container (before the .into()) with the following:
90-
// iced::Element::new(your_widget).explain(iced::Color::BLACK)
91-
container(
92-
column![
93-
container(scrollable(
94-
text.size(16).height(Length::Fill).width(Length::Fill)
95-
))
96-
.style(container::bordered_box)
97-
.padding(10)
98-
.height(Length::Fill)
99-
.width(Length::Fill),
100-
row![
101-
tooltip(
102-
staging_check,
103-
container("Check this box to enable staging maps.")
104-
.padding(10)
105-
.style(container::rounded_box)
106-
.style(container::warning),
107-
tooltip::Position::Top,
108-
)
109-
.delay(Duration::from_secs(1)),
110-
space().width(Length::Fill),
111-
tooltip(
112-
refresh_button,
113-
container("Get new random seeds for the 4 maps.")
114-
.padding(10)
115-
.style(container::rounded_box)
116-
.style(container::warning),
117-
tooltip::Position::Top,
118-
)
119-
.delay(Duration::from_secs(1)),
120-
tooltip(
121-
copy_button,
122-
container("Copy the /poll text onto your clipboard.")
123-
.padding(10)
124-
.style(container::rounded_box)
125-
.style(container::warning),
126-
tooltip::Position::Top,
127-
)
128-
.delay(Duration::from_secs(1)),
129-
]
130-
.spacing(18)
131-
.align_y(Alignment::Center),
132-
]
133-
.align_x(Alignment::End)
134-
.spacing(20),
135-
)
136-
.padding(20)
137-
.height(Length::Fill)
138-
.width(Length::Fill)
139-
.center_x(Length::Fill)
140-
.center_y(Length::Fill)
141-
.into()
142-
}

0 commit comments

Comments
 (0)