use super::state::PopupState;
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 PopupState,
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);
if is_own {
state.body_chevron_step(direction);
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_popup(state: &PopupState) -> Option<crate::layout::DragOutcome> {
if state.scroll.is_dragging {
return Some(crate::layout::DragOutcome::PopupBodyScroll);
}
if state.resize_drag.is_some() {
return Some(crate::layout::DragOutcome::PopupResize);
}
None
}