Add multidirectional scrolling capabilities to the existing Scrollable.

This commit is contained in:
Bingus 2022-11-19 10:29:37 -08:00 committed by bungoboingo
parent a6d0d5773f
commit d91f4f6aa7
12 changed files with 1148 additions and 576 deletions

View file

@ -10,8 +10,6 @@ use crate::{
Shell, Widget,
};
use std::u32;
/// A container that distributes its contents vertically.
#[allow(missing_debug_implementations)]
pub struct Column<'a, Message, Renderer> {

View file

@ -1,27 +1,22 @@
//! Operate on widgets that can be scrolled.
use crate::widget::{Id, Operation};
use iced_core::Vector;
/// The internal state of a widget that can be scrolled.
pub trait Scrollable {
/// Snaps the scroll of the widget to the given `percentage`.
fn snap_to(&mut self, percentage: f32);
fn snap_to(&mut self, percentage: Vector<f32>);
}
/// Produces an [`Operation`] that snaps the widget with the given [`Id`] to
/// the provided `percentage`.
pub fn snap_to<T>(target: Id, percentage: f32) -> impl Operation<T> {
pub fn snap_to<T>(target: Id, percentage: Vector<f32>) -> impl Operation<T> {
struct SnapTo {
target: Id,
percentage: f32,
percentage: Vector<f32>,
}
impl<T> Operation<T> for SnapTo {
fn scrollable(&mut self, state: &mut dyn Scrollable, id: Option<&Id>) {
if Some(&self.target) == id {
state.snap_to(self.percentage);
}
}
fn container(
&mut self,
_id: Option<&Id>,
@ -29,6 +24,12 @@ pub fn snap_to<T>(target: Id, percentage: f32) -> impl Operation<T> {
) {
operate_on_children(self)
}
fn scrollable(&mut self, state: &mut dyn Scrollable, id: Option<&Id>) {
if Some(&self.target) == id {
state.snap_to(self.percentage);
}
}
}
SnapTo { target, percentage }

File diff suppressed because it is too large Load diff