Repository navigation
Conversation
Tried to keep it more minimal this time. Also threw in a debug assert to scream at content when it screws up.
I noticed that we have a bunch of Controls that want to take nullable values, but the old version on master just wouldn't take a nullable object at build time. BUT, due to the C# compiler screaming, I now have a bunch of object? types lying around, which now means you can pass it into .Prop. To handle actually being able to pass nullable values in and the fact we've already been wanting to read nullable values, I now check if it's nullable on top of checking if it can be cast
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
About the PR
The way that StyleProperties are currently set/read is based purely on string keys mapped to arbitrary objects. This means that there's no way to really confirm that the value being set in the
E().Prop("Key", 10)is correct at compile-time when the Control is trying to readTryGetStyleProperty<Color>("Key", out _).This helps ensure that stylesheets being written are more accurate.
(Big diff is mostly formatting/fixing up tests + fixing obsolete usages. Fildrance asked me revive up my old attempt and finally get that merged.)
Technical details
A new
StyleProp<T>record struct that's just a wrapper around a string Name. The type is then used as a key for all of theStyleProperty-related functions.Note I do not provide a new manual constructor for
new StyleProperty(StyleProp<T>, object?)as it is functionally obsolete when we haveMutableSelectors, and it would try to unnecessarily box values.Generics are fun and the
Ttype is possibly null, which necessitated a fix to how null values were read from style properties. There were already Controls attempting to read nullable values (such as the manyShaderInstance?properties), but they couldn't actually read them as the code would try doval is Tand it be treated as missing and the Try would skip saving it. This meant that a null value used to essentially mean "ignore" (so it could hide lesser-matching rules), but is problematic for caching and stylesheet updates.Release Notes
StyleProp<T>struct that is a type-safe wrapper around style property keys.TryGetStylePropertyandStylePropertyDefaultthrow in DEBUG if there there is an incompatible value stored at the key.TryGetStylePropertyreturn true for a successful lookup with a null value, even for non-nullable reference types given it was set to null in the stylesheet.StylePropertyDefaultreturn null for a successful lookup rather than thedefaultValue, even for non-nullable reference types given it was set to null in the stylesheet.Migrations
All of the Controls are now using
StyleProp{T}. This should be source-compatible and require no changes if you were using one of the old constantStyleProperty*keys and weren't storing the wrong types.To handle most of the Obsoletions with the old string-based API, check the Control and use the specific
StyleProp{T}for the property you are trying to set.It's possible to now get
DEBUGcrashes if you're storing a type for aStyleProp{T}.Namethat is being read by a different-typedStyleProp{T1}. We don't currently have much homogeneity around our key names and type associations, so we would generally recommend to instead scope your StyleProperties for your controls. (They may be coalesced together at some point in the future).Usage of the
new StyleProperty(string, object?)constructor is now obsolete. Please use theStylesheetHelpersMutableSelectors instead to build your stylesheet rules, which are able to provide type safety.