@@ -67,9 +67,15 @@ pub fn init_state(width: u32, height: u32) void {
6767}
6868
6969var next_asset_id : u32 = ASSET_ID_TRESHOLD ;
70- pub fn add_texture (points : [4 ]Types.PointUV , texture_id : u32 ) void {
70+ pub fn add_asset (points : [4 ]Types.PointUV , texture_id : u32 ) void {
7171 state .assets .put (next_asset_id , Texture .new (next_asset_id , points , texture_id )) catch unreachable ;
7272 next_asset_id +%= 1 ;
73+ on_asset_update ();
74+ }
75+
76+ pub fn remove_asset () void {
77+ state .assets .remove (state .active_asset_id ) catch unreachable ;
78+ on_asset_update ();
7379}
7480
7581pub fn update_points (id : u32 , points : [4 ]Types.PointUV ) void {
@@ -95,13 +101,7 @@ pub fn on_pointer_down(x: f32, y: f32) void {
95101 }
96102}
97103
98- pub fn on_pointer_up () void {
99- if (state .ongoing_action == .none ) {
100- state .active_asset_id = state .hovered_asset_id ;
101- }
102-
103- state .ongoing_action = .none ;
104-
104+ fn on_asset_update () void {
105105 var result = std .heap .page_allocator .alloc (AssetZig , state .assets .count ()) catch unreachable ;
106106 var iterator = state .assets .iterator ();
107107 var i : usize = 0 ;
@@ -115,6 +115,16 @@ pub fn on_pointer_up() void {
115115 }
116116}
117117
118+ pub fn on_pointer_up () void {
119+ if (state .ongoing_action == .none ) {
120+ state .active_asset_id = state .hovered_asset_id ;
121+ }
122+
123+ state .ongoing_action = .none ;
124+
125+ on_asset_update ();
126+ }
127+
118128pub fn on_pointer_move (x : f32 , y : f32 ) void {
119129 switch (state .ongoing_action ) {
120130 .move = > {
0 commit comments