-
Notifications
You must be signed in to change notification settings - Fork 175
masonry: Refactor local transform as Property
#1374
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
Open
Philipp-M
wants to merge
1
commit into
linebender:main
Choose a base branch
from
Philipp-M:transform-as-property
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,10 @@ use std::collections::HashMap; | |||||
| use std::default::Default; | ||||||
|
|
||||||
| use crate::core::Widget; | ||||||
| use crate::util::AnyMap; | ||||||
| use crate::util::{AnyMap, TypeSet}; | ||||||
|
|
||||||
| mod transform; | ||||||
| pub use transform::Transform; | ||||||
|
|
||||||
| /// A marker trait that indicates that a type is intended to be used as a widget's property. | ||||||
| /// | ||||||
|
|
@@ -33,6 +36,9 @@ pub trait Property: Default + Send + Sync + 'static { | |||||
| fn static_default() -> &'static Self; | ||||||
| } | ||||||
|
|
||||||
| /// A marker trait for properties that can be used on *any* [`Widget`] | ||||||
| pub trait GlobalProperty: Property {} | ||||||
|
|
||||||
| // TODO - Implement Debug. | ||||||
| /// A collection of [properties](Property) that a widget can be created with. | ||||||
| #[derive(Default)] | ||||||
|
|
@@ -76,6 +82,8 @@ pub struct DefaultProperties { | |||||
| /// This is not used directly by Masonry Core, but is instead provided for the convenience of external crates. | ||||||
| pub trait HasProperty<P: Property> {} | ||||||
|
|
||||||
| impl<P: GlobalProperty, W: Widget> HasProperty<P> for W {} | ||||||
|
|
||||||
| impl Properties { | ||||||
| /// Create an empty collection of properties. | ||||||
| pub fn new() -> Self { | ||||||
|
|
@@ -111,6 +119,34 @@ impl Properties { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// When properties of a widget were modified this should also be reflected by [`ChangedProperties::mark_as_changed`] | ||||||
| #[derive(Default, Debug)] | ||||||
| pub struct ChangedProperties { | ||||||
| set: TypeSet, | ||||||
| } | ||||||
|
|
||||||
| impl ChangedProperties { | ||||||
| /// Mark that the property `P` has changed | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
etc. |
||||||
| pub fn mark_as_changed<P: Property>(&mut self) { | ||||||
| self.set.insert(TypeId::of::<P>()); | ||||||
| } | ||||||
|
|
||||||
| /// Whether the property `P` has changed | ||||||
| pub fn has_changed<P: Property>(&self) -> bool { | ||||||
| self.set.contains(&TypeId::of::<P>()) | ||||||
| } | ||||||
|
|
||||||
| /// Clears all marked as changed properties | ||||||
| pub fn clear(&mut self) { | ||||||
| self.set.clear(); | ||||||
| } | ||||||
|
|
||||||
| /// Clears all marked as changed properties | ||||||
| pub fn clear_property<P: Property>(&mut self) { | ||||||
| self.set.remove(&TypeId::of::<P>()); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| macro_rules! impl_props_from_tuple { | ||||||
| ( | ||||||
| $( | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||
| // Copyright 2025 the Xilem Authors | ||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||
|
|
||||||
| use vello::kurbo::Affine; | ||||||
|
|
||||||
| use crate::core::{GlobalProperty, Property}; | ||||||
|
|
||||||
| /// The local transform of a widget | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| #[derive(Clone, Copy, Default, Debug, PartialEq)] | ||||||
| pub struct Transform { | ||||||
| /// Local transform of the widget | ||||||
| pub transform: Affine, | ||||||
| } | ||||||
|
|
||||||
| impl Property for Transform { | ||||||
| fn static_default() -> &'static Self { | ||||||
| static DEFAULT: Transform = Transform { | ||||||
| transform: Affine::IDENTITY, | ||||||
| }; | ||||||
| &DEFAULT | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl GlobalProperty for Transform {} | ||||||
|
|
||||||
| impl From<Affine> for Transform { | ||||||
| fn from(transform: Affine) -> Self { | ||||||
| Self { transform } | ||||||
| } | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.