use super::state::ModalState;
use crate::layout::DispatchEvent;
use crate::types::{Rect, WidgetId};
pub struct ConsumeEventCtx {
pub cursor: (f64, f64),
pub frame_rect: Rect,
pub viewport: (f64, f64),
}
pub fn consume_event(
event: DispatchEvent,
state: &mut ModalState,
host_id: &WidgetId,
ctx: ConsumeEventCtx,
) -> Option<DispatchEvent> {
match event {
DispatchEvent::ChevronStepRequested {
ref chevron_id,
direction,
} => {
let is_own = chevron_id.0 == format!("{}:chevron_up", host_id.0)
|| chevron_id.0 == format!("{}:chevron_down", host_id.0)
|| chevron_id.0 == format!("{}:chevron_left", host_id.0)
|| chevron_id.0 == format!("{}:chevron_right", host_id.0);
if is_own {
state.body_chevron_step(direction);
None
} else {
Some(event)
}
}
DispatchEvent::ResizeHandleDragStarted {
host_id: ref hid,
edge,
} => {
if hid == host_id {
let min = (200.0_f64, 120.0_f64);
let cap = (f64::INFINITY, f64::INFINITY);
state.start_resize(edge, ctx.frame_rect, ctx.cursor, min, cap);
None
} else {
Some(event)
}
}
DispatchEvent::ScrollbarTrackClicked { ref track_id } => {
if track_id.0 == format!("{}:scrollbar_track", host_id.0) {
state.body_scroll_track_click(ctx.cursor.1);
None
} else {
Some(event)
}
}
DispatchEvent::ScrollbarThumbDragStarted { ref thumb_id } => {
if thumb_id.0 == format!("{}:scrollbar_handle", host_id.0) {
state.start_body_scroll_drag(ctx.cursor.1);
None
} else {
Some(event)
}
}
_ => Some(event),
}
}
pub fn drag_outcome_modal(state: &ModalState) -> Option<crate::layout::DragOutcome> {
if state.scroll.is_dragging {
return Some(crate::layout::DragOutcome::ModalBodyScroll);
}
if state.resize_drag.is_some() {
return Some(crate::layout::DragOutcome::ModalResize);
}
None
}