Created
January 6, 2024 15:59
-
-
Save juancampa/1c3fc9f671a567057450f6ba9cc50e58 to your computer and use it in GitHub Desktop.
Render marks under pointer check for slow input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put this in your `update` to render marks under the cursor to tell if your input is slow | |
let input_pos = ui.ctx().input(|input| input.pointer.latest_pos()); | |
let marks = ui.memory_mut(|mem| { | |
let marks: &mut VecDeque<Pos2> = | |
mem.data.get_temp_mut_or_default(Id::new("dots")); | |
if let Some(pos) = input_pos { | |
if pos == marks.back().cloned().unwrap_or_default() { | |
// Add a small offset if position is repeated | |
marks.push_back(pos + vec2(3.0, 3.0)); | |
} else { | |
marks.push_back(pos); | |
} | |
} else { | |
marks.push_back(pos2(50.0, 50.0)); | |
} | |
if marks.len() > 200 { | |
marks.pop_front(); | |
} | |
marks.clone() | |
}); | |
for mark in marks { | |
painter.circle_filled(mark, 2.0, Color32::LIGHT_GREEN); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment