Skip to content

Make Rectangle a readonly struct. - #21178

Merged
penev92 merged 2 commits into
OpenRA:bleedfrom
pchote:readonly-rectangle
Nov 14, 2023
Merged

Make Rectangle a readonly struct.#21178
penev92 merged 2 commits into
OpenRA:bleedfrom
pchote:readonly-rectangle

Conversation

@pchote

@pchote pchote commented Oct 31, 2023

Copy link
Copy Markdown
Member

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 onto Widget directly.

@pchote
pchote force-pushed the readonly-rectangle branch from 2434e52 to b0f2a97 Compare October 31, 2023 17:18
Comment thread OpenRA.Game/Widgets/Widget.cs Outdated
Height = height;
}

public static explicit operator Rectangle(WidgetBounds src)

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.

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.

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.

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.

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.

Fair. Yes I'd take a ToRectangle.

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.

Game.Renderer.EnableScissor is only used by the widget code right? Why can't the signature be changed?

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.

its a core engine function that doesn't have visibility of the mod-defined WidgetBounds type.

@pchote

pchote commented Nov 6, 2023

Copy link
Copy Markdown
Member Author

Updated.

@pchote
pchote force-pushed the readonly-rectangle branch from 479993b to 2f366c2 Compare November 6, 2023 21:51
@pchote
pchote force-pushed the readonly-rectangle branch from 2f366c2 to 0be6e59 Compare November 6, 2023 21:55

@penev92 penev92 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.

A wise man once told me "immutable things good" 👍

@penev92
penev92 merged commit 73be364 into OpenRA:bleed Nov 14, 2023
@penev92

penev92 commented Nov 14, 2023

Copy link
Copy Markdown
Member

Changelog

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.

6 participants