result := false;
hash := get_site_hash(site, increment);
- animation_state := map.get(^animation_states, hash);
+ animation_state := get_animation(hash);
mx, my := get_mouse_position();
if is_active_item(hash) {
move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed);
- if animation_state.click_time > 0 || animation_state.hover_time > 0 {
- map.put(^animation_states, hash, animation_state);
- } else {
- map.delete(^animation_states, hash);
- }
-
return result;
}
result := false;
hash := get_site_hash(site, increment);
- animation_state := map.get(^animation_states, hash);
+ animation_state := get_animation(hash);
mx, my := get_mouse_position();
if is_active_item(hash) {
move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed);
- if animation_state.click_time > 0 || animation_state.hover_time > 0 {
- map.put(^animation_states, hash, animation_state);
- } else {
- map.delete(^animation_states, hash);
- }
-
return result;
-}
\ No newline at end of file
+}
result := false;
hash := get_site_hash(site, increment);
- animation_state := map.get(^animation_states, hash);
+ animation_state := get_animation(hash);
mx, my := get_mouse_position();
move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed);
- if animation_state.click_time > 0 || animation_state.hover_time > 0 {
- map.put(^animation_states, hash, animation_state);
- } else {
- map.delete(^animation_states, hash);
- }
-
return result;
-}
\ No newline at end of file
+}
result := false;
hash := get_site_hash(site, increment);
- animation_state := map.get(^animation_states, hash);
+ animation_state := get_animation(hash);
width, height := Rectangle.dimensions(r);
mx, my := get_mouse_position();
.{ box_width, height - box_border_width * 2 },
bar_color);
- if animation_state.click_time > 0 || animation_state.hover_time > 0 {
- map.put(^animation_states, hash, animation_state);
- } else {
- map.delete(^animation_states, hash);
- }
-
return result;
}
result := false;
hash := get_site_hash(site, increment);
- animation_state := map.get(^animation_states, hash);
+ animation_state := get_animation(hash);
mx, my := get_mouse_position();
border_width := theme.border_width;
move_towards(^animation_state.click_time, 0.0f, theme.click_decay_speed);
- if animation_state.click_time > 0 || animation_state.hover_time > 0 {
- map.put(^animation_states, hash, animation_state);
- } else {
- map.delete(^animation_states, hash);
- }
-
return result;
}
/* 227 */ #char "\0", #char "\0",
/* 228 */ #char "\0", #char "\0",
/* 229 */ #char "\0", #char "\0",
-];
\ No newline at end of file
+];
if *s == .Just_Down do *s = .Down;
if *s == .Just_Up do *s = .Up;
}
+
+ for ^state: animation_states.entries {
+ // If the animation isn't being used anymore, discard it. This makes the has_active_animation function
+ // correct, otherwise, there could be animations that didn't finish, but the element was removed, and is
+ // no longer being updated.
+ if !state.value.accessed_this_frame || (state.value.click_time == 0 && state.value.hover_time == 0) {
+ map.delete(^animation_states, state.key);
+ }
+ }
+
+ for ^state: animation_states.entries {
+ state.value.accessed_this_frame = false;
+ }
}
set_active_item :: (id: UI_Id) -> bool {
// Animation states are stored globally as there is not much to the state of a button.
// Forcing the end user to store a structure for each button that is just the animation
// state of the component feels very wrong.
-#private animation_states : Map(UI_Id, Animation_State);
+#private_file animation_states : Map(UI_Id, Animation_State);
Animation_State :: struct {
hover_time := 0.0f;
click_time := 0.0f;
+
+ accessed_this_frame := false;
+}
+
+get_animation :: (id: UI_Id) -> ^Animation_State {
+ retval := map.get_ptr(^animation_states, id);
+
+ if retval == null {
+ map.put(^animation_states, id, .{});
+ retval = map.get_ptr(^animation_states, id);
+ }
+
+ // printf("{*}\n", retval);
+ retval.accessed_this_frame = true;
+ return retval;
}
has_active_animation :: () -> bool {