first good start

This commit is contained in:
2025-05-25 18:16:46 +02:00
parent 7d5c9d7805
commit eda740b054
3 changed files with 4290 additions and 2 deletions

4193
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,3 +4,5 @@ version = "0.1.0"
edition = "2024"
[dependencies]
iced = { version = "0.13.1", features = ["canvas"] }
svg = "0.18.0"

View File

@@ -1,3 +1,96 @@
fn main() {
println!("Hello, world!");
use iced::mouse;
use iced::widget::canvas;
use iced::widget::canvas::Stroke;
use iced::widget::canvas::Style;
use iced::widget::{button, column, row, text};
use iced::{Color, Rectangle, Renderer, Theme};
fn main() -> iced::Result {
iced::run("My App", MyApp::update, MyApp::view)
}
#[derive(Debug, Clone)]
enum Message {
ButtonPressedIncrement,
ButtonPressedDecrement,
}
#[derive(Default)]
struct MyApp {
counter: f32,
}
impl MyApp {
fn update(&mut self, message: Message) {
match message {
Message::ButtonPressedIncrement => self.counter += 32.0,
Message::ButtonPressedDecrement => {
if self.counter > 0.0 {
self.counter -= 32.0
}
}
}
}
fn view(&self) -> iced::Element<Message> {
column![
text(self.counter),
row![
button("Increment").on_press(Message::ButtonPressedIncrement),
button("Decrement").on_press(Message::ButtonPressedDecrement),
],
canvas(Circle {
radius: self.counter
})
.height(500)
.width(500),
]
.into()
}
}
struct Circle {
radius: f32,
}
impl<Message> canvas::Program<Message> for Circle {
// No internal state
type State = ();
fn draw(
&self,
_state: &(),
renderer: &Renderer,
_theme: &Theme,
bounds: Rectangle,
_cursor: mouse::Cursor,
) -> Vec<canvas::Geometry> {
// We prepare a new `Frame`
//println!("w:{}, h:{}", bounds.size().width, bounds.size().height);
let mut frame = canvas::Frame::new(renderer, bounds.size());
// We create a `Path` representing a simple circle
let circle = canvas::Path::circle(frame.center(), self.radius);
let line = canvas::Path::line(frame.center(), iced::Point { x: 0.0, y: 0.0 });
frame.stroke(
&line,
Stroke {
width: 5.0,
..Stroke::default()
},
);
// And fill it with some color
frame.stroke(
&circle,
Stroke {
width: 5.0,
style: Style::Solid(Color::from_rgba(0.0, 0.0, 0.0, 1.0)),
..Stroke::default()
},
);
// Then, we produce the geometry
vec![frame.into_geometry()]
}
}