Skip to content

Fix #18059: Width and height of custom window not changeable via script#18061

Merged
rik-smeets merged 3 commits into
OpenRCT2:developfrom
Sadret:window_fix
Sep 24, 2022
Merged

Fix #18059: Width and height of custom window not changeable via script#18061
rik-smeets merged 3 commits into
OpenRCT2:developfrom
Sadret:window_fix

Conversation

@Sadret

@Sadret Sadret commented Sep 19, 2022

Copy link
Copy Markdown
Contributor

No description provided.

@Sadret Sadret force-pushed the window_fix branch 2 times, most recently from 58fe1cf to 114bafe Compare September 19, 2022 20:44
Comment thread distribution/changelog.txt
Comment thread distribution/changelog.txt Outdated
- Fix: [#18051] Visual glitch with Mine Ride's large unbanked turn.
- Fix: [#18032] All non-interactive widgets (labels, groupboxes) produce sound when clicked.
- Fix: [#18051] Visual glitch with Mine Ride's large unbanked turn.
- Fix: [#18059] Width and height of custom window not changeable via script.

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.

Suggested change
- Fix: [#18059] Width and height of custom window not changeable via script.
- Fix: [#18059] [Plugin] Width and height of custom window not changeable via script.

@IntelOrca

Copy link
Copy Markdown
Contributor

I am not sure why this would be a bug. I think internal code has the same restriction. The code should set the min/max if it wants to change it.

@Sadret

Sadret commented Sep 20, 2022

Copy link
Copy Markdown
Contributor Author

I am not sure why this would be a bug. I think internal code has the same restriction. The code should set the min/max if it wants to change it.

From the viewpoint of a plugin developer that does not know how the implementation: They create a window, specifying width and height, but not minWidth/maxWidth and minHeight/maxHeight. Width/height seems to be writable, so they try to resize the window, which does not work. There is no hint at all that the min/max values are the reason for that.

@Sadret

Sadret commented Sep 20, 2022

Copy link
Copy Markdown
Contributor Author

In particular, the min/max values are optional when creating a window, but are still internally set to the width/height value. This is not transparent at all.

@IntelOrca

IntelOrca commented Sep 20, 2022

Copy link
Copy Markdown
Contributor

@Sadret would better documentation help? Technically the width and height are getting set, it's just that the next game tick will update it back based on min and max. This is perhaps useful if you want to increase it on a resizable window - but keep the constraints of the min/max size. Internal windows would have to do exactly the same thing.

@Broxzier

Copy link
Copy Markdown
Member

For plug-in developers this can be really confusing, since they don't set a minimal or maximum size anywhere. Wouldn't it be better to simply set the min to zero and max to 2^31-1 to get around this?

@Sadret

Sadret commented Sep 21, 2022

Copy link
Copy Markdown
Contributor Author

When I created the issue and the PR, I only thought about custom windows and did not realize that it would also effect vanilla windows. So I have to overthink.

The main problem I have with the current state is this: When I create a window using only width and height, I am expecting to be able to change width and height because they are marked in the documentation as mutable. But this is not the case (at least not without the min/max workaround). So, in the current state, everyone who wants to use this part of the API either has to ask or has to look into the implementation, and even then, a workaround should not be necessary.

This is why I submitted the issue and PR. I still think that behaviour-wise the changes provide the best solution for custom windows. Implementation-wise it might be considered unclean/hack though. For regular windows, I think that the behaviour is fine, I do not really see a problem with plugins being able to change the size of non-resizable windows. Is there an argument against it? It will probably never happen anyway, but if a plugin really wants to misuse it, there are already much better ways to provide bad user experience.

Also, keep in mind that the behaviour of resizable windows is not effected at all.

Otherwise, as @IntelOrca suggested, adding documentation is a valid option. Something like this:

  • width: When writing to this property, the value will be clamped to [minWidth,maxWidth]
  • minWidth, maxWidth: If unspecified during window creation, they default to width

Same for height, of course. This will work, but I personally think the current behaviour is a bit tedious for plugin devs, so I would rather change the behaviour than the documentation.

Summary of my (subjective) viewpoint:

  • If a dev wants to change the size of their (non-resizable) custom window, then window.width = value should do the trick.
  • It is not a problem if plugins can change the size of "non-resizable" windows.

What are your thoughts on this?

@Sadret

Sadret commented Sep 21, 2022

Copy link
Copy Markdown
Contributor Author

For plug-in developers this can be really confusing, since they don't set a minimal or maximum size anywhere. Wouldn't it be better to simply set the min to zero and max to 2^31-1 to get around this?

The problem with this approach is that a custom window is handled as resizable if the min and max values are different. So we would need to introduce a new boolean resizable and use that during window creation, which is definitely also possible wihtout much overhead.

@IntelOrca

Copy link
Copy Markdown
Contributor

Given this behaviour only affects windows that can't resize, I am happy with it. I think the documentation should still be updated to explain how it works.

@Sadret

Sadret commented Sep 22, 2022

Copy link
Copy Markdown
Contributor Author

I added documentation to Window and WindowDesc. Let me know what you think.
I also increased the api version.

@rik-smeets rik-smeets added this to the v0.4.2 milestone Sep 24, 2022
@rik-smeets rik-smeets changed the title Fix #18059: width and height of custom window not changeable via script Fix #18059: Width and height of custom window not changeable via script Sep 24, 2022
@rik-smeets rik-smeets merged commit 6be4189 into OpenRCT2:develop Sep 24, 2022
@Sadret Sadret deleted the window_fix branch September 24, 2022 07:43
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.

Plugin: width and height of custom window not changeable via script

4 participants