Show selected entity
This commit is contained in:
parent
73bc64a625
commit
dafebdabee
@ -16,6 +16,10 @@ impl<T> Default for EntityId<T> {
|
|||||||
impl<T> nohash_hasher::IsEnabled for EntityId<T> {}
|
impl<T> nohash_hasher::IsEnabled for EntityId<T> {}
|
||||||
|
|
||||||
impl<T> EntityId<T> {
|
impl<T> EntityId<T> {
|
||||||
|
pub fn id(&self) -> u32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
fn take_next(&mut self) -> Self {
|
fn take_next(&mut self) -> Self {
|
||||||
let id = *self;
|
let id = *self;
|
||||||
self.0 += 1;
|
self.0 += 1;
|
||||||
|
43
src/main.rs
43
src/main.rs
@ -3,7 +3,7 @@ use eframe::{
|
|||||||
emath::{Pos2, Rect, RectTransform, Vec2},
|
emath::{Pos2, Rect, RectTransform, Vec2},
|
||||||
epaint::{color::Hsva, Color32, Stroke},
|
epaint::{color::Hsva, Color32, Stroke},
|
||||||
};
|
};
|
||||||
use geometry::{LineEntity, PointId, PointPos, SketchEntities};
|
use geometry::{LineEntity, LineId, PointId, PointPos, SketchEntities};
|
||||||
|
|
||||||
mod geometry;
|
mod geometry;
|
||||||
mod optimization;
|
mod optimization;
|
||||||
@ -37,6 +37,8 @@ struct ViewState {
|
|||||||
tool: Tool,
|
tool: Tool,
|
||||||
hover_point: Option<PointId>,
|
hover_point: Option<PointId>,
|
||||||
select_point: Option<PointId>,
|
select_point: Option<PointId>,
|
||||||
|
hover_line: Option<LineId>,
|
||||||
|
select_line: Option<LineId>,
|
||||||
drag_delta: Vec2,
|
drag_delta: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,9 +104,8 @@ impl MyApp {
|
|||||||
|
|
||||||
let transform_pos = |pos: &PointPos| to_screen * Pos2::new(pos.x as f32, pos.y as f32);
|
let transform_pos = |pos: &PointPos| to_screen * Pos2::new(pos.x as f32, pos.y as f32);
|
||||||
|
|
||||||
let mut hover_line = None;
|
|
||||||
|
|
||||||
state.hover_point = None;
|
state.hover_point = None;
|
||||||
|
state.hover_line = None;
|
||||||
|
|
||||||
if let Some(hover_pos) = response.hover_pos() {
|
if let Some(hover_pos) = response.hover_pos() {
|
||||||
for (id, point) in self
|
for (id, point) in self
|
||||||
@ -133,7 +134,7 @@ impl MyApp {
|
|||||||
let hovered = ((0.)..=(1.)).contains(&p) && perp.length() < 5.0;
|
let hovered = ((0.)..=(1.)).contains(&p) && perp.length() < 5.0;
|
||||||
|
|
||||||
if hovered {
|
if hovered {
|
||||||
hover_line = Some(id);
|
state.hover_line = Some(id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,7 +169,13 @@ impl MyApp {
|
|||||||
match state.tool {
|
match state.tool {
|
||||||
Tool::Select => {
|
Tool::Select => {
|
||||||
if response.clicked() {
|
if response.clicked() {
|
||||||
|
state.select_point = None;
|
||||||
|
state.select_line = None;
|
||||||
|
if state.hover_point.is_some() {
|
||||||
state.select_point = state.hover_point;
|
state.select_point = state.hover_point;
|
||||||
|
} else if state.hover_line.is_some() {
|
||||||
|
state.select_line = state.hover_line;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tool::Move => {
|
Tool::Move => {
|
||||||
@ -240,7 +247,7 @@ impl MyApp {
|
|||||||
color.v -= 0.6;
|
color.v -= 0.6;
|
||||||
if state.hover_point.is_none()
|
if state.hover_point.is_none()
|
||||||
&& (state.select_point.is_none() || state.tool != Tool::Move)
|
&& (state.select_point.is_none() || state.tool != Tool::Move)
|
||||||
&& Some(id) == hover_line
|
&& (Some(id) == state.hover_line || Some(id) == state.select_line)
|
||||||
{
|
{
|
||||||
color.s -= 0.8;
|
color.s -= 0.8;
|
||||||
}
|
}
|
||||||
@ -266,6 +273,23 @@ impl MyApp {
|
|||||||
painter.circle(center, POINT_RADIUS, color, stroke);
|
painter.circle(center, POINT_RADIUS, color, stroke);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn show_side_panel(&mut self, ui: &mut Ui) {
|
||||||
|
ui.vertical(|ui| match self.state.tool {
|
||||||
|
Tool::Select => {
|
||||||
|
if let Some(point_id) = self.state.select_point {
|
||||||
|
ui.label(format!("Selected point {}", point_id.id()));
|
||||||
|
} else if let Some(line_id) = self.state.select_line {
|
||||||
|
ui.label(format!("Selected line {}", line_id.id()));
|
||||||
|
} else {
|
||||||
|
ui.label("No selection");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
ui.label(":)");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl eframe::App for MyApp {
|
impl eframe::App for MyApp {
|
||||||
@ -285,14 +309,7 @@ impl eframe::App for MyApp {
|
|||||||
.resizable(true)
|
.resizable(true)
|
||||||
.default_width(150.0)
|
.default_width(150.0)
|
||||||
.width_range(80.0..=200.0)
|
.width_range(80.0..=200.0)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| self.show_side_panel(ui));
|
||||||
ui.vertical_centered(|ui| {
|
|
||||||
ui.heading("Left Panel");
|
|
||||||
});
|
|
||||||
// egui::ScrollArea::vertical().show(ui, |ui| {
|
|
||||||
// lorem_ipsum(ui);
|
|
||||||
// });
|
|
||||||
});
|
|
||||||
|
|
||||||
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user