mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
refactor: group mouse input into own struct
This commit is contained in:
@@ -165,8 +165,8 @@ impl Area {
|
||||
|
||||
let input = ctx.input();
|
||||
if move_interact.active {
|
||||
state.pos += input.mouse_move;
|
||||
state.vel = input.mouse_velocity;
|
||||
state.pos += input.mouse.delta;
|
||||
state.vel = input.mouse.velocity;
|
||||
} else {
|
||||
let stop_speed = 20.0; // Pixels per second.
|
||||
let friction_coeff = 1000.0; // Pixels per second squared.
|
||||
@@ -208,8 +208,8 @@ impl Area {
|
||||
}
|
||||
|
||||
fn mouse_pressed_on_area(ctx: &Context, layer: Layer) -> bool {
|
||||
if let Some(mouse_pos) = ctx.input().mouse_pos {
|
||||
ctx.input().mouse_pressed && ctx.memory().layer_at(mouse_pos) == Some(layer)
|
||||
if let Some(mouse_pos) = ctx.input().mouse.pos {
|
||||
ctx.input().mouse.pressed && ctx.memory().layer_at(mouse_pos) == Some(layer)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ fn menu_impl<'c>(
|
||||
})
|
||||
});
|
||||
|
||||
if menu_interact.hovered && ui.input().mouse_released {
|
||||
if menu_interact.hovered && ui.input().mouse.released {
|
||||
bar_state.open_menu = None;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ fn interact_with_menu_button(
|
||||
menu_id: Id,
|
||||
button_interact: &GuiResponse,
|
||||
) {
|
||||
if button_interact.hovered && input.mouse_pressed {
|
||||
if button_interact.hovered && input.mouse.pressed {
|
||||
if bar_state.open_menu.is_some() {
|
||||
bar_state.open_menu = None;
|
||||
} else {
|
||||
@@ -122,7 +122,7 @@ fn interact_with_menu_button(
|
||||
}
|
||||
}
|
||||
|
||||
if button_interact.hovered && input.mouse_released && bar_state.open_menu.is_some() {
|
||||
if button_interact.hovered && input.mouse.released && bar_state.open_menu.is_some() {
|
||||
let time_since_open = input.time - bar_state.open_time;
|
||||
if time_since_open < 0.4 {
|
||||
// A quick click
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use crate::*;
|
||||
|
||||
pub fn show_tooltip(ctx: &Arc<Context>, add_contents: impl FnOnce(&mut Ui)) {
|
||||
if let Some(mouse_pos) = ctx.input().mouse_pos {
|
||||
if let Some(mouse_pos) = ctx.input().mouse.pos {
|
||||
// TODO: default size
|
||||
let id = Id::tooltip();
|
||||
let window_pos = mouse_pos + vec2(16.0, 16.0);
|
||||
|
||||
@@ -212,7 +212,7 @@ impl Resize {
|
||||
let corner_interact = ui.interact_rect(corner_rect, id.with("corner"));
|
||||
|
||||
if corner_interact.active {
|
||||
if let Some(mouse_pos) = ui.input().mouse_pos {
|
||||
if let Some(mouse_pos) = ui.input().mouse.pos {
|
||||
// This is the desired size. We may not be able to achieve it.
|
||||
|
||||
state.size = mouse_pos - position + 0.5 * corner_interact.rect.size()
|
||||
|
||||
@@ -147,7 +147,7 @@ impl ScrollArea {
|
||||
// Dragg contents to scroll (for touch screens mostly):
|
||||
let content_interact = ui.interact_rect(inner_rect, id.with("area"));
|
||||
if content_interact.active {
|
||||
state.offset.y -= ui.input().mouse_move.y;
|
||||
state.offset.y -= ui.input().mouse.delta.y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,11 +181,11 @@ impl ScrollArea {
|
||||
let interact_id = id.with("vertical");
|
||||
let handle_interact = ui.interact_rect(handle_rect, interact_id);
|
||||
|
||||
if let Some(mouse_pos) = ui.input().mouse_pos {
|
||||
if let Some(mouse_pos) = ui.input().mouse.pos {
|
||||
if handle_interact.active {
|
||||
if inner_rect.top() <= mouse_pos.y && mouse_pos.y <= inner_rect.bottom() {
|
||||
state.offset.y +=
|
||||
ui.input().mouse_move.y * content_size.y / inner_rect.height();
|
||||
ui.input().mouse.delta.y * content_size.y / inner_rect.height();
|
||||
}
|
||||
} else {
|
||||
// Check for mouse down outside handle:
|
||||
|
||||
@@ -303,7 +303,7 @@ fn resize_window(
|
||||
) -> Option<Rect> {
|
||||
if let Some(window_interaction) = window_interaction(ctx, possible, area_layer, id, rect) {
|
||||
window_interaction.set_cursor(ctx);
|
||||
if let Some(mouse_pos) = ctx.input().mouse_pos {
|
||||
if let Some(mouse_pos) = ctx.input().mouse.pos {
|
||||
let mut rect = window_interaction.start_rect; // prevent drift
|
||||
|
||||
if window_interaction.is_resize() {
|
||||
@@ -350,7 +350,7 @@ fn window_interaction(
|
||||
if window_interaction.is_none() {
|
||||
if let Some(hover_window_interaction) = resize_hover(ctx, possible, area_layer, rect) {
|
||||
hover_window_interaction.set_cursor(ctx);
|
||||
if ctx.input().mouse_pressed {
|
||||
if ctx.input().mouse.pressed {
|
||||
ctx.memory().active_id = Some(id);
|
||||
window_interaction = Some(hover_window_interaction);
|
||||
ctx.memory().window_interaction = window_interaction;
|
||||
@@ -375,7 +375,7 @@ fn resize_hover(
|
||||
area_layer: Layer,
|
||||
rect: Rect,
|
||||
) -> Option<WindowInteraction> {
|
||||
if let Some(mouse_pos) = ctx.input().mouse_pos {
|
||||
if let Some(mouse_pos) = ctx.input().mouse.pos {
|
||||
if let Some(top_layer) = ctx.memory().layer_at(mouse_pos) {
|
||||
if top_layer != area_layer && top_layer.order != Order::Background {
|
||||
return None; // Another window is on top here
|
||||
|
||||
Reference in New Issue
Block a user