@@ -81,14 +81,14 @@ fn generate_id() u32 {
8181pub fn add_asset (id_or_zero : u32 , points : [4 ]Types.PointUV , texture_id : u32 ) void {
8282 const id = if (id_or_zero == 0 ) generate_id () else id_or_zero ;
8383 state .assets .put (id , Texture .new (id , points , texture_id )) catch unreachable ;
84- notify_about_assets_update ( );
84+ check_assets_update ( true );
8585}
8686
8787pub fn remove_asset () void {
8888 _ = state .assets .remove (state .active_asset_id );
8989 state .active_asset_id = 0 ;
9090 on_asset_select_cb (state .active_asset_id );
91- notify_about_assets_update ( );
91+ check_assets_update ( true );
9292}
9393
9494pub fn on_update_pick (id : u32 ) void {
@@ -111,7 +111,7 @@ pub fn on_pointer_down(x: f32, y: f32) void {
111111
112112// const std.heap.page_allocator.alloc(AssetZig, state.assets.count())
113113var last_assets_update : []const AssetZig = &.{};
114- fn notify_about_assets_update ( ) void {
114+ fn check_assets_update ( should_notify : bool ) void {
115115 const cb = on_asset_update_cb orelse return ;
116116
117117 var new_assets_update = std .heap .page_allocator .alloc (AssetZig , state .assets .count ()) catch unreachable ;
@@ -140,10 +140,12 @@ fn notify_about_assets_update() void {
140140 std .heap .page_allocator .free (last_assets_update );
141141 last_assets_update = new_assets_update ;
142142
143- if (new_assets_update .len > 0 ) {
144- cb (new_assets_update ); // would throw error if results.len == 0
145- } else {
146- cb (&.{});
143+ if (should_notify ) {
144+ if (new_assets_update .len > 0 ) {
145+ cb (new_assets_update ); // would throw error if results.len == 0
146+ } else {
147+ cb (&.{});
148+ }
147149 }
148150}
149151
@@ -153,7 +155,7 @@ pub fn on_pointer_up() void {
153155 on_asset_select_cb (state .active_asset_id );
154156 } else {
155157 state .ongoing_action = .none ;
156- notify_about_assets_update ( );
158+ check_assets_update ( true );
157159 }
158160}
159161
@@ -192,7 +194,7 @@ pub fn on_pointer_move(x: f32, y: f32) void {
192194pub fn on_pointer_leave () void {
193195 state .ongoing_action = .none ;
194196 state .hovered_asset_id = 0 ;
195- notify_about_assets_update ( );
197+ check_assets_update ( true );
196198}
197199
198200fn get_border () struct { []f32 , []f32 } { // { triangle vertex, msdf vertex }
@@ -332,9 +334,7 @@ pub fn reset_assets(new_assets: []const AssetZig, with_snapshot: bool) void {
332334
333335 on_asset_update_cb = real_callback_pointer ;
334336
335- if (with_snapshot ) {
336- notify_about_assets_update ();
337- }
337+ check_assets_update (with_snapshot );
338338}
339339
340340pub fn destroy_state () void {
0 commit comments