232 lines
8.0 KiB
Rust
232 lines
8.0 KiB
Rust
use crate::message::Message;
|
|
|
|
use iced::alignment::{Horizontal, Vertical};
|
|
|
|
use iced::widget::{TextInput, column, text};
|
|
use iced::{Element, Theme};
|
|
use iced::{
|
|
Length, Padding,
|
|
widget::{Column, Container, button, canvas, container, pick_list, row, scrollable, slider},
|
|
};
|
|
use iced_aw::menu::{self, Item};
|
|
use iced_aw::menu_bar;
|
|
use iced_aw::widget::color_picker;
|
|
use iced_aw::widget::menu::Menu;
|
|
|
|
use std::f32::consts::PI;
|
|
|
|
use crate::Polymusic;
|
|
|
|
pub fn music_view(app: &Polymusic) -> iced::Element<'_, Message> {
|
|
let mut i = 0;
|
|
//Create all polygon options
|
|
let polygon_rows: Vec<Element<Message>> = app
|
|
.music
|
|
.current_frame(app.current_delta)
|
|
.polygons
|
|
.iter()
|
|
.map(|polygon| {
|
|
let current_index = i;
|
|
let but = button(text("").size(20).center()).on_press(Message::SubmitColor(i));
|
|
let c = column![
|
|
row![
|
|
text(&polygon.name).size(24),
|
|
button(text("").size(20)).on_press(Message::Remove(i)),
|
|
color_picker(
|
|
polygon.show_color_picker,
|
|
polygon.color,
|
|
but,
|
|
Message::CancelColor(i),
|
|
move |color| Message::ChooseColor(i, color)
|
|
),
|
|
button(text(
|
|
polygon
|
|
.sound_name
|
|
.rsplit(['/', '\\'])
|
|
.next()
|
|
.unwrap_or(&polygon.sound_name)
|
|
))
|
|
.on_press(Message::ChangeSound(current_index)),
|
|
]
|
|
.spacing(20),
|
|
row![
|
|
TextInput::new("90", &polygon.global_teta.to_degrees().floor().to_string())
|
|
.on_input(move |new_value| Message::ChangeDegree(current_index, new_value))
|
|
.width(Length::FillPortion(1)),
|
|
row![
|
|
slider(0.0..=2.0 * PI, polygon.global_teta, move |f| {
|
|
Message::ChangeTeta(current_index, f)
|
|
})
|
|
.step(2. * PI / 10_000.)
|
|
.width(Length::FillPortion(9))
|
|
]
|
|
.padding(Padding::from(16)),
|
|
]
|
|
.spacing(5),
|
|
]
|
|
.spacing(10)
|
|
.into();
|
|
i += 1;
|
|
c
|
|
})
|
|
.collect();
|
|
let ngon_options: Vec<String> = (5..=42).map(|sides| format!("Ngon{sides}")).collect();
|
|
let all_options: Vec<String> = [
|
|
"Segment",
|
|
"Triangle",
|
|
"Square",
|
|
"Nr6In30",
|
|
"Nr7In30",
|
|
"Nr8In30",
|
|
"Nr9In30",
|
|
"Nr8In42",
|
|
"Nr9In42",
|
|
"Nr10aIn42",
|
|
"Nr10bIn42",
|
|
]
|
|
.iter()
|
|
.map(|s| s.to_string())
|
|
.chain(ngon_options)
|
|
.collect();
|
|
|
|
let polygon_column = scrollable(Column::with_children(polygon_rows).spacing(24));
|
|
|
|
let menu_tpl_1 = |items| Menu::new(items).max_width(200.0).offset(15.0).spacing(5.0);
|
|
let save_menu = menu_tpl_1(vec![
|
|
Item::new(button("Save File").on_press(Message::Save)),
|
|
Item::new(button("Load Menu").on_press(Message::GoToLoadView).style(
|
|
|theme: &Theme, status| {
|
|
let palette = theme.extended_palette();
|
|
|
|
match status {
|
|
button::Status::Active => {
|
|
if !app.already_save {
|
|
button::Style::default().with_background(palette.danger.strong.color)
|
|
} else {
|
|
button::primary(theme, status)
|
|
}
|
|
}
|
|
_ => button::primary(theme, status),
|
|
}
|
|
},
|
|
)),
|
|
Item::new("CTRL+F for quit without save."),
|
|
]);
|
|
column![
|
|
menu_bar!((text("File").size(20), save_menu)(
|
|
text("Shortcuts").size(20),
|
|
menu_tpl_1(vec![
|
|
Item::new(" SPACE"),
|
|
Item::new(" CTRL+S"),
|
|
Item::new(" ARROW UP"),
|
|
Item::new(" CTRL+Z"),
|
|
Item::new(" CTRL+Y"),
|
|
])
|
|
))
|
|
.draw_path(menu::DrawPath::Backdrop)
|
|
.spacing(20),
|
|
text(&app.music.file_name)
|
|
.width(Length::FillPortion(1))
|
|
.size(32),
|
|
row![
|
|
container(
|
|
canvas(app.music.current_frame(app.current_delta))
|
|
.height(Length::FillPortion(1))
|
|
.width(Length::FillPortion(1))
|
|
),
|
|
column![
|
|
text("Polygon options").size(26),
|
|
pick_list(all_options, Some("Choose polygon".to_string()), |s| {
|
|
Message::AddPolygon(s)
|
|
})
|
|
.text_size(18),
|
|
polygon_column,
|
|
]
|
|
.spacing(10)
|
|
.height(Length::FillPortion(1))
|
|
.width(Length::FillPortion(2)),
|
|
]
|
|
.height(Length::FillPortion(2))
|
|
.spacing(20),
|
|
column![
|
|
row![
|
|
button(text(if app.paused { "" } else { "" }).size(28).center())
|
|
.on_press(if app.can_unpaused {
|
|
Message::TogglePaused
|
|
} else {
|
|
Message::None
|
|
})
|
|
.width(Length::FillPortion(1)),
|
|
row![
|
|
TextInput::new("MM:SS:CS", &app.str_time)
|
|
.on_input(|new_value| Message::ChangeDeltaString(new_value))
|
|
.size(28),
|
|
text("/").size(30),
|
|
TextInput::new("MM:SS:CS", &app.str_music_length)
|
|
.on_input(|new_value| Message::LengthChange(new_value))
|
|
.size(28),
|
|
]
|
|
.width(Length::FillPortion(10)),
|
|
TextInput::new("1.0", &format!("{:.1} sec/rev", &app.music.nb_sec_for_rev))
|
|
.on_input(|new_value| Message::ChangeNbPerSec(new_value))
|
|
.size(28)
|
|
.width(Length::FillPortion(2)),
|
|
button(text("").size(28).center())
|
|
.on_press(Message::SlidePointLeft)
|
|
.width(Length::FillPortion(1)),
|
|
button(text("").size(28).center())
|
|
.on_press(Message::AddPoint)
|
|
.width(Length::FillPortion(1)),
|
|
button(text("").size(28).center())
|
|
.on_press(Message::SlidePointRight)
|
|
.width(Length::FillPortion(1)),
|
|
button(text("").size(28).center())
|
|
.on_press(Message::RemovePoint)
|
|
.width(Length::FillPortion(1)),
|
|
]
|
|
.spacing(20),
|
|
column![
|
|
canvas(&app.music)
|
|
.height(Length::FillPortion(1))
|
|
.width(Length::FillPortion(1))
|
|
]
|
|
.spacing(0),
|
|
]
|
|
.spacing(20)
|
|
.height(Length::FillPortion(1))
|
|
.width(Length::FillPortion(1)),
|
|
]
|
|
.spacing(25)
|
|
.padding(25)
|
|
.into()
|
|
}
|
|
|
|
pub fn load_file_view() -> iced::Element<'static, Message> {
|
|
Container::new(
|
|
column![
|
|
text("Polymusic").size(42),
|
|
row![
|
|
column![button("Create File").on_press(Message::CreatFile),]
|
|
.spacing(10)
|
|
.width(200)
|
|
.height(200)
|
|
.align_x(Horizontal::Center),
|
|
column![button("Load File").on_press(Message::Load),]
|
|
.spacing(10)
|
|
.width(200)
|
|
.height(200)
|
|
.align_x(Horizontal::Center)
|
|
]
|
|
.spacing(32)
|
|
.align_y(Vertical::Center),
|
|
]
|
|
.spacing(64)
|
|
.align_x(Horizontal::Center),
|
|
)
|
|
.width(Length::Fill)
|
|
.height(Length::Fill)
|
|
.center_x(Length::Fill)
|
|
.center_y(Length::Fill)
|
|
.into()
|
|
}
|