this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

vxfw(Spinner): fix last frame handling

+10 -9
+10 -9
src/vxfw/Spinner.zig
··· 15 15 /// The frame index 16 16 frame: u4 = 0, 17 17 18 - /// If the last time we handled a tick we were spinning. This is used to draw one time after we stop 19 - /// spinning 20 - was_spinning: bool = false, 18 + /// Turns true when we start the spinner. Only turns false during a draw if the count == 0. This 19 + /// ensures we draw one more time past the spinner stopping to clear the state 20 + was_spinning: std.atomic.Value(bool) = .{ .raw = false }, 21 21 22 22 /// Start, or add one, to the spinner counter. Thread safe. 23 23 pub fn start(self: *Spinner) ?vxfw.Command { 24 + self.was_spinning.store(true, .unordered); 24 25 const count = self.count.fetchAdd(1, .monotonic); 25 26 if (count == 0) { 26 27 return vxfw.Tick.in(time_lapse, self.widget()); ··· 28 29 return null; 29 30 } 30 31 31 - pub fn isSpinning(self: *Spinner) bool { 32 - return self.count.load(.unordered) > 0; 33 - } 34 - 35 32 /// Reduce one from the spinner counter. The spinner will stop when it reaches 0. Thread safe 36 33 pub fn stop(self: *Spinner) void { 37 34 self.count.store(self.count.load(.unordered) -| 1, .unordered); 35 + } 36 + 37 + pub fn wasSpinning(self: *Spinner) bool { 38 + return self.was_spinning.load(.unordered); 38 39 } 39 40 40 41 pub fn widget(self: *Spinner) vxfw.Widget { ··· 56 57 const count = self.count.load(.unordered); 57 58 58 59 if (count == 0) { 59 - if (self.was_spinning) { 60 + if (self.wasSpinning()) { 60 61 ctx.redraw = true; 61 - self.was_spinning = false; 62 + self.was_spinning.store(false, .unordered); 62 63 } 63 64 return; 64 65 }