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
Make Rectangle a readonly struct. #21178
Conversation
2434e52
to
b0f2a97
Compare
OpenRA.Game/Widgets/Widget.cs
Outdated
Height = height; | ||
} | ||
|
||
public static explicit operator Rectangle(WidgetBounds src) |
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.
Eww. I'd rather expose any helpers we needed, IntersectsWith
, Contains
, etc directly for ergonomic use and convert to a Rectangle internally if we're interested in reusing the logic.
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.
The issue is that Game.Renderer.EnableScissor
requires a Rectangle
and can't (IMO) cleanly be changed otherwise - and it seems a bit redundant to add those methods if we still need to convert to a Rectangle
afterwards anyway.
I can replace this with to a .ToRectangle()
method if that would be preferrable.
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.
Fair. Yes I'd take a ToRectangle
.
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.
Game.Renderer.EnableScissor
is only used by the widget code right? Why can't the signature be changed?
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.
its a core engine function that doesn't have visibility of the mod-defined WidgetBounds
type.
b0f2a97
to
479993b
Compare
Updated. |
479993b
to
2f366c2
Compare
2f366c2
to
0be6e59
Compare
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.
A wise man once told me "immutable things good" 👍
This PR completes a long-standing TODO from #15973.
The ability to directly manipulate widget bounds is important for WidgetLogic usability, so a thin
WidgetBounds
struct is created to keep this ability. In the future we could (with a bit of FieldLoader magic to route the IntegerExpressions to different fields) move the four integers ontoWidget
directly.