code cleanup
This commit is contained in:
+74
-76
@@ -1,82 +1,80 @@
|
||||
pub mod randomizer {
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::randomizer::randomizer::RandomizerMessage::{Back, Edit, Start};
|
||||
use crate::styling::{back_overlay, jl_button};
|
||||
use crate::RootMessage;
|
||||
use iced::widget::{button, text_editor};
|
||||
use iced::Task;
|
||||
use rand::prelude::SliceRandom;
|
||||
use crate::navigation::{NavigatedPage, Page};
|
||||
use crate::randomizer::RandomizerMessage::{Back, Edit, Start};
|
||||
use crate::styling::{back_overlay, jl_button};
|
||||
use crate::RootMessage;
|
||||
use iced::widget::{button, text_editor};
|
||||
use iced::Task;
|
||||
use rand::prelude::SliceRandom;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RandomizerState {
|
||||
text: text_editor::Content,
|
||||
list: Vec<String>,
|
||||
}
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RandomizerState {
|
||||
text: text_editor::Content,
|
||||
list: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RandomizerMessage {
|
||||
Back,
|
||||
Start,
|
||||
Edit(text_editor::Action),
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RandomizerMessage {
|
||||
Back,
|
||||
Start,
|
||||
Edit(text_editor::Action),
|
||||
}
|
||||
|
||||
impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
||||
fn navigate(&self, message: &RandomizerMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
return Some(Page::PreviousPage);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RandomizerState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl RandomizerState {
|
||||
pub fn new() -> RandomizerState {
|
||||
RandomizerState {
|
||||
text: Default::default(),
|
||||
list: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Edit(action) => {
|
||||
self.text.perform(action);
|
||||
self.list = self
|
||||
.text
|
||||
.text()
|
||||
.split("\n")
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
}
|
||||
Start => {
|
||||
self.list.shuffle(&mut rand::rng());
|
||||
self.text = text_editor::Content::with_text(self.list.join("\n").as_str());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, RandomizerMessage> {
|
||||
back_overlay(
|
||||
iced::widget::column![
|
||||
text_editor(&self.text)
|
||||
.on_action(Edit)
|
||||
.width(400)
|
||||
.height(400)
|
||||
.placeholder("Каждый элемент с новой строки"),
|
||||
button("Перемешать").style(jl_button).on_press(Start),
|
||||
]
|
||||
.spacing(5)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
impl NavigatedPage<RandomizerMessage> for RandomizerState {
|
||||
fn navigate(&self, message: &RandomizerMessage) -> Option<Page> {
|
||||
if let Back = message {
|
||||
return Some(Page::PreviousPage);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for RandomizerState {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl RandomizerState {
|
||||
pub fn new() -> RandomizerState {
|
||||
RandomizerState {
|
||||
text: Default::default(),
|
||||
list: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: RandomizerMessage) -> Task<RootMessage> {
|
||||
match message {
|
||||
Edit(action) => {
|
||||
self.text.perform(action);
|
||||
self.list = self
|
||||
.text
|
||||
.text()
|
||||
.split("\n")
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
}
|
||||
Start => {
|
||||
self.list.shuffle(&mut rand::rng());
|
||||
self.text = text_editor::Content::with_text(self.list.join("\n").as_str());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, RandomizerMessage> {
|
||||
back_overlay(
|
||||
iced::widget::column![
|
||||
text_editor(&self.text)
|
||||
.on_action(Edit)
|
||||
.width(400)
|
||||
.height(400)
|
||||
.placeholder("Каждый элемент с новой строки"),
|
||||
button("Перемешать").style(jl_button).on_press(Start),
|
||||
]
|
||||
.spacing(5)
|
||||
.into(),
|
||||
Back,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user