Skip to content

Add scroll_to operation#1796

Merged
hecrj merged 3 commits into
iced-rs:masterfrom
tarkah:feat/scrollable-scroll-to
Apr 20, 2023
Merged

Add scroll_to operation#1796
hecrj merged 3 commits into
iced-rs:masterfrom
tarkah:feat/scrollable-scroll-to

Conversation

@tarkah

@tarkah tarkah commented Apr 14, 2023

Copy link
Copy Markdown
Member

Supersedes #1795

Exposes a new scroll_to operation to allow scrolling a scrollable to a desired "absolute" offset.

@hecrj hecrj added this to the 0.10.0 milestone Apr 17, 2023
@hecrj hecrj added feature New feature or request widget labels Apr 17, 2023
Comment on lines +69 to +74
pub struct CurrentOffset {
/// The [`AbsoluteOffset`] of a [`Scrollable`]
pub absolute: AbsoluteOffset,
/// The [`RelativeOffset`] of a [`Scrollable`]
pub relative: RelativeOffset,
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some redundancy here.

I think it'd be better to have a Window or Viewport type with the already existing private Offset, the content bounds, and the scrollable bounds.

Then we can expose relative_offset and absolute_offset methods in this type that compute the actual values from a single source of truth.

@tarkah tarkah Apr 17, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion 6ad5e03

@tarkah tarkah requested a review from hecrj April 17, 2023 20:56

@hecrj hecrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

I have made a change to compare the absolute offsets as well in notify_on_scroll, since it's theoretically possible that the relative offset stays the same but the absolute offset doesn't (e.g. if the bounds of the Scrollable change while scrolling). See 8a71140.

I think we can merge! 🚢

@hecrj hecrj enabled auto-merge April 20, 2023 13:53
@hecrj hecrj merged commit 4052ccf into iced-rs:master Apr 20, 2023
@tarkah tarkah deleted the feat/scrollable-scroll-to branch April 20, 2023 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request widget

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants