Draw a line
parent
e2b0b6b0f6
commit
3cf028fe16
56
src/app.rs
56
src/app.rs
|
@ -1,11 +1,13 @@
|
|||
pub mod components;
|
||||
pub mod draw;
|
||||
mod structure;
|
||||
use serde_lexpr::{from_str, print, to_string_custom};
|
||||
|
||||
use chrono::prelude::Utc;
|
||||
use chrono_humanize::HumanTime;
|
||||
use egui::{emath, Color32};
|
||||
use egui::{pos2, Painter, Pos2, Rect, Shape};
|
||||
use fake::{Fake, Faker};
|
||||
use serde_lexpr::{from_str, print, to_string_custom};
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use uuid::Uuid;
|
||||
|
@ -219,7 +221,7 @@ impl eframe::App for PlannerApp {
|
|||
description: Faker.fake::<String>(),
|
||||
c_type: components::ComponentType::Door,
|
||||
material: components::Material::Metal,
|
||||
shapes: vec![],
|
||||
items: vec![],
|
||||
},
|
||||
)]),
|
||||
};
|
||||
|
@ -262,14 +264,21 @@ impl eframe::App for PlannerApp {
|
|||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
// The central panel the region left after adding TopPanel's and SidePanel's
|
||||
let painter = Painter::new(
|
||||
ui.ctx().clone(),
|
||||
ui.layer_id(),
|
||||
ui.available_rect_before_wrap(),
|
||||
);
|
||||
self.paint(&painter);
|
||||
ui.expand_to_include_rect(painter.clip_rect());
|
||||
|
||||
ui.heading("eframe template");
|
||||
ui.hyperlink("https://github.com/emilk/eframe_template");
|
||||
ui.add(egui::github_link_file!(
|
||||
"https://github.com/emilk/eframe_template/blob/master/",
|
||||
"Source code."
|
||||
));
|
||||
egui::warn_if_debug_build(ui);
|
||||
// ui.heading("eframe template");
|
||||
// ui.hyperlink("https://github.com/emilk/eframe_template");
|
||||
// ui.add(egui::github_link_file!(
|
||||
// "https://github.com/emilk/eframe_template/blob/master/",
|
||||
// "Source code."
|
||||
// ));
|
||||
// egui::warn_if_debug_build(ui);
|
||||
});
|
||||
|
||||
if false {
|
||||
|
@ -282,3 +291,32 @@ impl eframe::App for PlannerApp {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PlannerApp {
|
||||
fn paint(&mut self, painter: &Painter) {
|
||||
let mut shapes: Vec<Shape> = Vec::new();
|
||||
|
||||
let rect = painter.clip_rect();
|
||||
let to_screen = emath::RectTransform::from_to(
|
||||
Rect::from_center_size(Pos2::ZERO, rect.square_proportions()),
|
||||
rect,
|
||||
);
|
||||
|
||||
let mut paint_line = |points: [Pos2; 2], color: Color32, width: f32| {
|
||||
let line = [to_screen * points[0], to_screen * points[1]];
|
||||
|
||||
// culling
|
||||
if rect.intersects(Rect::from_two_pos(line[0], line[1])) {
|
||||
shapes.push(Shape::line_segment(line, (width, color)));
|
||||
}
|
||||
};
|
||||
|
||||
paint_line(
|
||||
[pos2(0.0, 0.0), pos2(10.0, 10.0)],
|
||||
Color32::from_additive_luminance(255),
|
||||
20.0,
|
||||
);
|
||||
|
||||
painter.extend(shapes);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::draw::Shape;
|
||||
use super::draw::DrawItem;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize, PartialEq)]
|
||||
|
@ -37,7 +37,7 @@ pub struct Component {
|
|||
pub description: String,
|
||||
pub c_type: ComponentType,
|
||||
pub material: Material,
|
||||
pub shapes: Vec<Shape>,
|
||||
pub items: Vec<DrawItem>,
|
||||
}
|
||||
|
||||
impl Default for Component {
|
||||
|
@ -48,7 +48,7 @@ impl Default for Component {
|
|||
description: String::default(),
|
||||
c_type: ComponentType::Furniture,
|
||||
material: Material::Wood,
|
||||
shapes: vec![],
|
||||
items: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,15 @@
|
|||
(0
|
||||
(zindex . 0)
|
||||
(label . "Meow")
|
||||
(visible . #t)
|
||||
(visible . #f)
|
||||
(components
|
||||
("bbf8f70a-60c1-4859-924b-c360b897dc6c"
|
||||
(id . "73e48d43-2ec4-4397-8289-54ddc87f9886")
|
||||
(label . "sWzh9LGiSKrlQsRWoK") (description . "Bq59shWXHCKhTH1")
|
||||
(label . "sWzh9LGiSKrlQsRWoK")
|
||||
(description . "Bq59shWXHCKhTH1")
|
||||
(c_type . Door)
|
||||
(material . Metal)
|
||||
(shapes)
|
||||
(items)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -30,7 +31,7 @@
|
|||
(description . "7tCDffx2dFFzIrT")
|
||||
(c_type . Door)
|
||||
(material . Metal)
|
||||
(shapes)
|
||||
(items)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -45,7 +46,7 @@
|
|||
(description . "hi9js3X8dWaWZ")
|
||||
(c_type . Door)
|
||||
(material . Metal)
|
||||
(shapes)
|
||||
(items)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue