change color of polygon
This commit is contained in:
39
src/main.rs
39
src/main.rs
@@ -1,14 +1,13 @@
|
|||||||
mod polygon_draw;
|
mod polygon_draw;
|
||||||
|
|
||||||
use iced::{
|
use iced::{
|
||||||
Element, Task, Theme,
|
Color, Element, Task, Theme,
|
||||||
time::{self, Duration},
|
time::{self, Duration},
|
||||||
widget::{Column, button, canvas, column, pick_list, row, slider, text},
|
widget::{Column, button, canvas, column, pick_list, row, slider, text},
|
||||||
};
|
};
|
||||||
use polygon_draw::{Polygon, PolygonFrame};
|
use polygon_draw::{Polygon, PolygonFrame};
|
||||||
|
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::io::BufReader;
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use kira::{
|
use kira::{
|
||||||
@@ -30,6 +29,7 @@ enum Message {
|
|||||||
AddPolygon(String),
|
AddPolygon(String),
|
||||||
ChangeTeta(usize, f32),
|
ChangeTeta(usize, f32),
|
||||||
Remove(usize),
|
Remove(usize),
|
||||||
|
ChangeColor(usize, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MyApp {
|
struct MyApp {
|
||||||
@@ -73,17 +73,17 @@ impl MyApp {
|
|||||||
Message::AddPolygon(s) => {
|
Message::AddPolygon(s) => {
|
||||||
let mut poly: Polygon;
|
let mut poly: Polygon;
|
||||||
match s.as_str() {
|
match s.as_str() {
|
||||||
"segment" => {
|
"Segment" => {
|
||||||
poly = Polygon::segment(0.0, self.default_sound.clone());
|
poly = Polygon::segment(0.0, self.default_sound.clone());
|
||||||
poly.name = "segment".to_string()
|
poly.name = "Segment".to_string()
|
||||||
}
|
}
|
||||||
"triangle" => {
|
"Triangle" => {
|
||||||
poly = Polygon::triangle(0.0, self.default_sound.clone());
|
poly = Polygon::triangle(0.0, self.default_sound.clone());
|
||||||
poly.name = "triangle".to_string()
|
poly.name = "Triangle".to_string()
|
||||||
}
|
}
|
||||||
"square" => {
|
"Square" => {
|
||||||
poly = Polygon::square(0.0, self.default_sound.clone());
|
poly = Polygon::square(0.0, self.default_sound.clone());
|
||||||
poly.name = "square".to_string()
|
poly.name = "Square".to_string()
|
||||||
}
|
}
|
||||||
_ => poly = Polygon::n_gon(0.0, 0, self.default_sound.clone()),
|
_ => poly = Polygon::n_gon(0.0, 0, self.default_sound.clone()),
|
||||||
}
|
}
|
||||||
@@ -111,6 +111,18 @@ impl MyApp {
|
|||||||
self.poly_frame.polygons.remove(i - 1);
|
self.poly_frame.polygons.remove(i - 1);
|
||||||
}
|
}
|
||||||
Message::ChangeTeta(i, teta) => self.poly_frame.polygons[i].global_teta = teta,
|
Message::ChangeTeta(i, teta) => self.poly_frame.polygons[i].global_teta = teta,
|
||||||
|
Message::ChangeColor(i, s) => {
|
||||||
|
let c: Color;
|
||||||
|
match s.as_str() {
|
||||||
|
"Green" => c = Color::from_rgb(0.0, 1.0, 0.0),
|
||||||
|
"Blue" => c = Color::from_rgb(0.0, 0.0, 1.0),
|
||||||
|
"Cyan" => c = Color::from_rgb(0.0, 1.0, 1.0),
|
||||||
|
"Yellow" => c = Color::from_rgb(1.0, 1.0, 0.0),
|
||||||
|
"Pink" => c = Color::from_rgb(1.0, 0.0, 1.0),
|
||||||
|
_ => c = Color::BLACK,
|
||||||
|
}
|
||||||
|
self.poly_frame.polygons[i].color = c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +145,14 @@ impl MyApp {
|
|||||||
move |f| { Message::ChangeTeta(current_index, f) }
|
move |f| { Message::ChangeTeta(current_index, f) }
|
||||||
)
|
)
|
||||||
.step(2.0 * PI / 42f32),
|
.step(2.0 * PI / 42f32),
|
||||||
button("Remove").on_press(Message::Remove(i))
|
button("Remove").on_press(Message::Remove(i)),
|
||||||
|
pick_list(
|
||||||
|
["Black", "Blue", "Green", "Pink", "Yellow", "Cyan"]
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.to_vec(),
|
||||||
|
Some("Color".to_string()),
|
||||||
|
move |s| { Message::ChangeColor(current_index, s) }
|
||||||
|
),
|
||||||
]
|
]
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
@@ -152,7 +171,7 @@ impl MyApp {
|
|||||||
],
|
],
|
||||||
text("Polygon options"),
|
text("Polygon options"),
|
||||||
pick_list(
|
pick_list(
|
||||||
["segment", "triangle", "square"]
|
["Segment", "Triangle", "Square"]
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.to_vec(),
|
.to_vec(),
|
||||||
Some("Chose polygon".to_string()),
|
Some("Chose polygon".to_string()),
|
||||||
|
|||||||
Reference in New Issue
Block a user