mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 07:03:14 -04:00
Improve drag-code
This commit is contained in:
@@ -894,7 +894,8 @@ impl PointerState {
|
||||
}
|
||||
|
||||
/// If the pointer button is down, will it register as a click when released?
|
||||
#[inline(always)]
|
||||
///
|
||||
/// See also [`Self::is_decidedly_dragging`].
|
||||
pub fn could_any_button_be_click(&self) -> bool {
|
||||
if !self.any_down() {
|
||||
return false;
|
||||
@@ -913,6 +914,22 @@ impl PointerState {
|
||||
true
|
||||
}
|
||||
|
||||
/// Just because the mouse is down doesn't mean we are dragging.
|
||||
/// We could be at the start of a click.
|
||||
/// But if the mouse is down long enough, or has moved far enough,
|
||||
/// then we consider it a drag.
|
||||
///
|
||||
/// This function can return true on the same frame the drag is relased,
|
||||
/// but NOT on the first frame it was started.
|
||||
///
|
||||
/// See also [`Self::could_any_button_be_click`].
|
||||
pub fn is_decidedly_dragging(&self) -> bool {
|
||||
(self.any_down() || self.any_released())
|
||||
&& !self.any_pressed()
|
||||
&& !self.could_any_button_be_click()
|
||||
&& !self.any_click()
|
||||
}
|
||||
|
||||
/// Is the primary button currently down?
|
||||
#[inline(always)]
|
||||
pub fn primary_down(&self) -> bool {
|
||||
|
||||
@@ -3,8 +3,7 @@ use std::collections::HashMap;
|
||||
use egui::{vec2, Rect};
|
||||
|
||||
use crate::dock::{
|
||||
is_being_dragged, is_possible_drag, Behavior, DropContext, InsertionPoint, LayoutInsertion,
|
||||
NodeId, Nodes,
|
||||
is_being_dragged, Behavior, DropContext, InsertionPoint, LayoutInsertion, NodeId, Nodes,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||
@@ -58,8 +57,7 @@ impl Tabs {
|
||||
let next_active = self.tab_bar_ui(behavior, ui, rect, nodes, drop_context, node_id);
|
||||
|
||||
// When dragged, don't show it (it is "being held")
|
||||
let is_active_being_dragged =
|
||||
ui.memory(|mem| mem.is_being_dragged(self.active.id())) && is_possible_drag(ui.ctx());
|
||||
let is_active_being_dragged = is_being_dragged(ui.ctx(), self.active);
|
||||
if !is_active_being_dragged {
|
||||
nodes.node_ui(behavior, drop_context, ui, self.active);
|
||||
}
|
||||
|
||||
@@ -165,11 +165,7 @@ enum SimplifyAction {
|
||||
}
|
||||
|
||||
fn is_possible_drag(ctx: &egui::Context) -> bool {
|
||||
ctx.input(|input| {
|
||||
!input.pointer.any_pressed()
|
||||
&& !input.pointer.could_any_button_be_click()
|
||||
&& !input.pointer.any_click()
|
||||
})
|
||||
ctx.input(|input| input.pointer.is_decidedly_dragging())
|
||||
}
|
||||
|
||||
fn is_being_dragged(ctx: &egui::Context, node_id: NodeId) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user