use std::sync::Arc;
use web_time::Instant;
use crate::callback::Callback;
use crate::core::element::Key;
use crate::core::node::NodeId;
use crate::style::Rect;
use crate::widgets::{
DragCancelEvent, DragPayload, DragPreview, DragReorderMode, DraggableTabReorderEvent,
DraggableTabTransferEvent,
};
#[derive(Clone, Copy, Debug)]
pub(crate) struct ProgressDrag {
pub id: NodeId,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct SliderDrag {
pub id: NodeId,
}
#[derive(Clone)]
pub(crate) struct DraggableTabBarDrag {
pub source_id: NodeId,
pub source_bar_id: Option<Arc<str>>,
pub source_index: usize,
pub id: NodeId,
pub bar_id: Option<Arc<str>>,
pub current_index: usize,
pub pending_id: NodeId,
pub pending_bar_id: Option<Arc<str>>,
pub pending_index: usize,
pub drag_group: Option<Arc<str>>,
pub on_transfer: Option<Callback<DraggableTabTransferEvent>>,
pub reorder_mode: DragReorderMode,
pub threshold: u16,
pub start_x: u16,
pub started: bool,
pub preview_label: Option<Arc<str>>,
pub preview_snapshot_anchor: Option<crate::style::Rect>,
}
impl std::fmt::Debug for DraggableTabBarDrag {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DraggableTabBarDrag")
.field("source_id", &self.source_id)
.field("source_bar_id", &self.source_bar_id)
.field("source_index", &self.source_index)
.field("id", &self.id)
.field("bar_id", &self.bar_id)
.field("current_index", &self.current_index)
.field("pending_id", &self.pending_id)
.field("pending_bar_id", &self.pending_bar_id)
.field("pending_index", &self.pending_index)
.field("drag_group", &self.drag_group)
.field("reorder_mode", &self.reorder_mode)
.field("threshold", &self.threshold)
.field("start_x", &self.start_x)
.field("started", &self.started)
.field("preview_label", &self.preview_label)
.finish()
}
}
#[derive(Clone)]
pub(crate) struct DragDropDrag {
pub payload: Arc<dyn DragPayload>,
pub source_id: NodeId,
pub drag_group: Option<Arc<str>>,
pub preview: DragPreview,
pub on_cancel: Option<Callback<DragCancelEvent>>,
pub hovered_target: Option<NodeId>,
pub scroll_view_id: Option<NodeId>,
pub start_x: u16,
pub start_y: u16,
pub threshold: u16,
pub started: bool,
pub preview_snapshot_anchor: Option<crate::style::Rect>,
}
impl std::fmt::Debug for DragDropDrag {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DragDropDrag")
.field("payload", &self.payload)
.field("source_id", &self.source_id)
.field("drag_group", &self.drag_group)
.field("preview", &self.preview)
.field("hovered_target", &self.hovered_target)
.field("scroll_view_id", &self.scroll_view_id)
.field("start_x", &self.start_x)
.field("start_y", &self.start_y)
.field("threshold", &self.threshold)
.field("started", &self.started)
.field("preview_snapshot_anchor", &self.preview_snapshot_anchor)
.finish()
}
}
pub(crate) enum DraggableTabDragEvent {
Reorder(DraggableTabReorderEvent),
Transfer(DraggableTabTransferEvent),
}
#[derive(Clone, Debug)]
pub(crate) struct SplitterDrag {
pub id: NodeId,
pub handle: usize,
pub start_pos: i16,
pub start_sizes: Vec<u16>,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct TextAreaDrag {
pub id: NodeId,
pub anchor: usize,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct InputDrag {
pub id: NodeId,
pub anchor: usize,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct HexAreaDrag {
pub id: NodeId,
pub anchor: usize,
}
#[derive(Clone, Debug)]
pub(crate) struct DocumentViewDrag {
pub id: NodeId,
pub anchor: DocumentViewDragAnchor,
pub shared_selection_id: Option<Arc<str>>,
pub scroll_view_id: Option<NodeId>,
pub shared_drag_anchor: Option<SharedDocumentDragAnchor>,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub(crate) struct SharedDocumentDragAnchor {
pub virtual_child_index: usize,
pub doc_slot: usize,
pub local_byte: usize,
}
#[derive(Clone, Copy, Debug)]
pub(crate) enum DocumentViewDragAnchor {
Linear(usize),
TableCell {
table_id: usize,
row_index: usize,
col_index: usize,
row_line_index: usize,
cell_line_anchor_byte: usize,
},
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct DocumentTableCellHit {
pub table_id: usize,
pub row_index: usize,
pub col_index: usize,
pub row_line_index: usize,
pub cell_line_anchor_byte: usize,
pub cell_text_start_byte: usize,
pub cell_text_end_byte: usize,
pub x_clamped: bool,
pub y_clamped: bool,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct DocumentViewSelectionUpdate {
pub id: NodeId,
pub cursor: usize,
pub anchor: Option<usize>,
}
#[derive(Clone, Debug)]
pub(crate) struct DocumentViewSharedLinearDragResult {
pub updates: Vec<DocumentViewSelectionUpdate>,
pub offscreen_patches: Vec<OffscreenSharedSelectionPatch>,
pub selected_text: Arc<str>,
}
#[derive(Clone, Debug)]
pub(crate) struct OffscreenSharedSelectionPatch {
pub child_key: Key,
pub doc_slot: usize,
pub selection_cursor: usize,
pub selection_anchor: Option<usize>,
}
#[derive(Clone, Debug)]
pub(crate) struct DocumentViewSharedSelectionText {
pub scroll_view_id: NodeId,
pub shared_selection_id: Arc<str>,
pub selected_text: Arc<str>,
}
#[cfg(feature = "diff-view")]
#[derive(Clone, Debug)]
pub(crate) struct DiffSplitSelectionText {
pub left_id: NodeId,
pub right_id: NodeId,
pub selected_text: Arc<str>,
}
#[cfg(feature = "diff-view")]
#[derive(Clone, Debug)]
pub(crate) struct DiffSplitSelectionResult {
pub updates: Vec<DocumentViewSelectionUpdate>,
}
#[cfg(feature = "diff-view")]
#[derive(Clone, Copy, Debug)]
pub(super) struct DiffSplitDocumentPair {
left: NodeId,
right: NodeId,
}
#[derive(Clone, Debug)]
pub(crate) struct DocumentViewSharedLinearItem {
node_id: Option<NodeId>,
virtual_child_index: usize,
child_key: Key,
doc_slot: usize,
global_start: usize,
global_end: usize,
text_len: usize,
rect: Rect,
phantom_flat_text: Option<Arc<str>>,
}
#[cfg(feature = "terminal")]
#[derive(Clone, Copy, Debug)]
pub(crate) struct TerminalDrag {
pub id: NodeId,
pub anchor: crate::utils::GridPos,
}
#[derive(Clone, Copy)]
pub(crate) struct ClickState {
pub x: u16,
pub y: u16,
pub time: Instant,
pub count: u8,
}
mod diff;
mod document;
mod scroll_view;
mod table;
mod widgets;
pub(crate) use document::*;
pub(crate) use scroll_view::*;
pub(crate) use table::*;
pub(crate) use widgets::*;
#[cfg(feature = "diff-view")]
pub(crate) use diff::*;
#[cfg(test)]
#[allow(clippy::items_after_test_module)]
mod tests;