ltk/input/pointer/
scroll.rsuse crate::app::App;
use crate::event_loop::AppData;
use crate::platform::Platform;
use super::super::event::{ Axis, AxisSource, PointerInput };
impl<A: App, P: Platform> AppData<A, P>
{
pub( super ) fn on_pointer_axis( &mut self, input: &PointerInput, horizontal: Axis, vertical: Axis, source: AxisSource )
{
let focus = input.focus;
let pos = self.surface( focus ).to_physical( input.position.0, input.position.1 );
let notches = vertical.notches;
if self.scroll_text_under( focus, pos, notches, vertical.distance as f32 ) { return; }
let scroll_hit =
{
let ss = self.surface( focus );
ss.frame.scroll_rects.iter()
.find( |( r, _, _ )| r.contains( pos ) )
.map( |( _, idx, ax )| ( *idx, *ax ) )
};
if let Some( ( scroll_idx, axis ) ) = scroll_hit
{
let multiplier = source.scroll_factor();
let step_x = horizontal.distance as f32 * multiplier;
let step_y = vertical.distance as f32 * multiplier;
let ss = self.surface_mut( focus );
let entry = ss.frame.scroll_offsets.entry( scroll_idx ).or_insert( ( 0.0, 0.0 ) );
match axis
{
crate::widget::scroll::ScrollAxis::Vertical =>
{
entry.1 = ( entry.1 + step_y ).max( 0.0 );
}
crate::widget::scroll::ScrollAxis::Horizontal =>
{
entry.0 = ( entry.0 + step_x + step_y ).max( 0.0 );
}
crate::widget::scroll::ScrollAxis::Both =>
{
entry.0 = ( entry.0 + step_x ).max( 0.0 );
entry.1 = ( entry.1 + step_y ).max( 0.0 );
}
}
ss.request_redraw();
} else {
let notches_x = horizontal.notches;
let consumed = ( notches != 0.0 || notches_x != 0.0 ) && self.app.on_pointer_wheel( pos.x, pos.y, notches_x, notches );
if !consumed
{
let multiplier = source.scroll_factor();
let dx = horizontal.distance as f32 * multiplier;
let dy = vertical.distance as f32 * multiplier;
self.app.on_pointer_axis( pos.x, pos.y, dx, dy );
}
self.dirty_caches();
self.surface_mut( focus ).request_redraw();
}
}
}