1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Add some helper functions to Response

This commit is contained in:
Emil Ernerfeldt
2021-03-06 10:48:39 +01:00
parent fb2db4940e
commit 9c8439d053
9 changed files with 67 additions and 40 deletions

View File

@@ -255,8 +255,12 @@ impl super::View for InputTest {
if response.double_clicked_by(button) {
new_info += &format!("Double-clicked by {:?}\n", button);
}
if response.dragged() && ui.input().pointer.button_down(button) {
new_info += &format!("Dragged by {:?}\n", button);
if response.dragged_by(button) {
new_info += &format!(
"Dragged by {:?}, delta: {:?}\n",
button,
response.drag_delta()
);
}
}
if !new_info.is_empty() {

View File

@@ -84,24 +84,22 @@ impl FrameHistory {
let color = ui.visuals().text_color();
let line_stroke = Stroke::new(1.0, color);
if let Some(pointer_pos) = ui.input().pointer.tooltip_pos() {
if rect.contains(pointer_pos) {
let y = pointer_pos.y;
shapes.push(Shape::line_segment(
[pos2(rect.left(), y), pos2(rect.right(), y)],
line_stroke,
));
let cpu_usage = to_screen.inverse().transform_pos(pointer_pos).y;
let text = format!("{:.1} ms", 1e3 * cpu_usage);
shapes.push(Shape::text(
ui.fonts(),
pos2(rect.left(), y),
egui::Align2::LEFT_BOTTOM,
text,
TextStyle::Monospace,
color,
));
}
if let Some(pointer_pos) = response.hover_pos() {
let y = pointer_pos.y;
shapes.push(Shape::line_segment(
[pos2(rect.left(), y), pos2(rect.right(), y)],
line_stroke,
));
let cpu_usage = to_screen.inverse().transform_pos(pointer_pos).y;
let text = format!("{:.1} ms", 1e3 * cpu_usage);
shapes.push(Shape::text(
ui.fonts(),
pos2(rect.left(), y),
egui::Align2::LEFT_BOTTOM,
text,
TextStyle::Monospace,
color,
));
}
let circle_color = color;