@@ -5,6 +5,7 @@ pub mod render_context;
55
66use camera:: Camera ;
77use context:: StageContext ;
8+ use egui:: { Vec2 , vec2} ;
89
910use crate :: stage:: {
1011 elements:: { Element , ElementTrait , entities:: EntityTrait } ,
@@ -16,13 +17,15 @@ use crate::stage::{
1617pub struct Stage {
1718 pub camera : Camera ,
1819 pub context : StageContext ,
20+ pub selection : Vec < String > ,
1921}
2022
2123impl Stage {
2224 pub fn new ( ) -> Self {
2325 Stage {
2426 camera : Camera :: new ( ) ,
2527 context : StageContext :: random ( ) ,
28+ selection : Vec :: new ( ) ,
2629 }
2730 }
2831
@@ -46,20 +49,49 @@ impl Stage {
4649
4750 visible_count += 1 ;
4851
52+ let selected = self . selection . contains ( & entity. id ( ) . to_string ( ) ) ;
53+
4954 let screen_pos = self
5055 . camera
51- . world_to_screen ( entity. position ( ) , screen_center) ;
56+ . world_to_screen ( entity. position ( ) , screen_center)
57+ - if selected {
58+ vec2 ( 4.0 , 4.0 ) * self . camera . zoom ( )
59+ } else {
60+ Vec2 :: ZERO
61+ } ;
5262
5363 egui:: Area :: new ( ui. make_persistent_id ( entity. id ( ) ) )
5464 . order ( egui:: Order :: Foreground )
5565 . fixed_pos ( screen_pos)
5666 . show ( ui. ctx ( ) , |ui| {
57- entity. ui (
58- ui,
59- & RenderContext {
60- zoom : self . camera . zoom ( ) ,
61- } ,
62- ) ;
67+ let response = egui:: Frame :: new ( )
68+ . inner_margin ( 4.0 * self . camera . zoom ( ) )
69+ . corner_radius ( 24.0 * self . camera . zoom ( ) )
70+ . stroke ( if selected {
71+ egui:: Stroke :: new (
72+ 4.0 * self . camera . zoom ( ) ,
73+ egui:: Color32 :: LIGHT_BLUE ,
74+ )
75+ } else {
76+ egui:: Stroke :: NONE
77+ } )
78+ . show ( ui, |ui| {
79+ entity. ui (
80+ ui,
81+ & mut RenderContext {
82+ zoom : self . camera . zoom ( ) ,
83+ selected : selected,
84+ } ,
85+ ) ;
86+ } )
87+ . response
88+ . interact ( egui:: Sense :: click ( ) ) ;
89+
90+ if response. clicked ( ) {
91+ log:: info!( "Entity {} clicked" , entity. id( ) ) ;
92+ self . selection . clear ( ) ;
93+ self . selection . push ( entity. id ( ) . to_string ( ) ) ;
94+ }
6395 } ) ;
6496 }
6597
0 commit comments