mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -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?
|
/// 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 {
|
pub fn could_any_button_be_click(&self) -> bool {
|
||||||
if !self.any_down() {
|
if !self.any_down() {
|
||||||
return false;
|
return false;
|
||||||
@@ -913,6 +914,22 @@ impl PointerState {
|
|||||||
true
|
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?
|
/// Is the primary button currently down?
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn primary_down(&self) -> bool {
|
pub fn primary_down(&self) -> bool {
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ use std::collections::HashMap;
|
|||||||
use egui::{vec2, Rect};
|
use egui::{vec2, Rect};
|
||||||
|
|
||||||
use crate::dock::{
|
use crate::dock::{
|
||||||
is_being_dragged, is_possible_drag, Behavior, DropContext, InsertionPoint, LayoutInsertion,
|
is_being_dragged, Behavior, DropContext, InsertionPoint, LayoutInsertion, NodeId, Nodes,
|
||||||
NodeId, Nodes,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
|
#[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);
|
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")
|
// When dragged, don't show it (it is "being held")
|
||||||
let is_active_being_dragged =
|
let is_active_being_dragged = is_being_dragged(ui.ctx(), self.active);
|
||||||
ui.memory(|mem| mem.is_being_dragged(self.active.id())) && is_possible_drag(ui.ctx());
|
|
||||||
if !is_active_being_dragged {
|
if !is_active_being_dragged {
|
||||||
nodes.node_ui(behavior, drop_context, ui, self.active);
|
nodes.node_ui(behavior, drop_context, ui, self.active);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,11 +165,7 @@ enum SimplifyAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_possible_drag(ctx: &egui::Context) -> bool {
|
fn is_possible_drag(ctx: &egui::Context) -> bool {
|
||||||
ctx.input(|input| {
|
ctx.input(|input| input.pointer.is_decidedly_dragging())
|
||||||
!input.pointer.any_pressed()
|
|
||||||
&& !input.pointer.could_any_button_be_click()
|
|
||||||
&& !input.pointer.any_click()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_being_dragged(ctx: &egui::Context, node_id: NodeId) -> bool {
|
fn is_being_dragged(ctx: &egui::Context, node_id: NodeId) -> bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user