Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public methods to access clip path #622

Merged
merged 1 commit into from
Oct 3, 2024
Merged

Conversation

tomcur
Copy link
Member

@tomcur tomcur commented Oct 1, 2024

This adds public getters for clip path to non-LayoutCtx contexts, and also to WidgetState as it seems relevant for painting.

The motivation is to remove private field accesses from Widget::get_child_at_pos as mentioned in
#565 (comment).

This leaves one private field access, namely WidgetState::is_stashed. As per the docs of WidgetState ("widgets will generally not interact with it directly"), that field perhaps should not be publicly accessible from WidgetState, but then it should be accessible from WidgetRef.

This adds public getters for clip path to non-`LayoutCtx` contexts, and
also to `WidgetState` as it seems relevant for painting.

The motivation is to remove private field accesses from
`Widget::get_child_at_pos` as mentioned in
linebender#565 (comment).

This leaves one private field access, namely `WidgetState::is_stashed`.
As per the docs of `WidgetState` ("widgets will generally not interact
with it directly"), that field perhaps should not be publicly accessible
from `WidgetState`, but then it should be accessible from `WidgetRef`.
@tomcur
Copy link
Member Author

tomcur commented Oct 1, 2024

Private WidgetState::is_stashed is accessed here

if !child.state().is_stashed

child is a WidgetRef. Perhaps WidgetRef can allow access to the underlying QueryCtx, and we add the stashed getter on QueryCtx.

Copy link
Contributor

@Philipp-M Philipp-M left a comment

Choose a reason for hiding this comment

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

Yeah probably doesn't hurt to expose this, LGTM.
I expect though that this is very much in flux, a clip path just being Rect seems... limited.

@tomcur tomcur added this pull request to the merge queue Oct 3, 2024
@tomcur
Copy link
Member Author

tomcur commented Oct 3, 2024

I'll leave the question of how to expose stashed state for a later PR.

I expect though that this is very much in flux, a clip path just being Rect seems... limited.

Right, iirc clip is intended to become generalized to arbitrary shapes, but it requires an efficient way in Kurbo to do so (maybe just an enum for the most common shapes?).

Edit, for reference:

// TODO - Use general Shape
// Currently Kurbo doesn't really provide a type that lets us
// efficiently hold an arbitrary shape.
pub(crate) clip: Option<Rect>,

Merged via the queue into linebender:main with commit 5dbafd6 Oct 3, 2024
17 checks passed
@tomcur tomcur deleted the pub-methods branch October 3, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants