Skip to content
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

Add "on_resize" to MainWindow #2304

Open
hyuri opened this issue Dec 29, 2023 · 2 comments · May be fixed by #2364
Open

Add "on_resize" to MainWindow #2304

hyuri opened this issue Dec 29, 2023 · 2 comments · May be fixed by #2364
Labels
enhancement New features, or improvements to existing features.

Comments

@hyuri
Copy link

hyuri commented Dec 29, 2023

What is the problem or limitation you are having?

I currently don't know when the window is getting resized, so I can't make adaptive decisions about how the content is being displayed unless I keep a background task continually "manually" checking. Example:

async def update_background_image(self, app, **kwargs):
	while True:
		if self.main_window.size[0] != self.background_image.width:
			new_image_size = (self.main_window.size[0], self.background_image.height)
			scaled_image = self.background_image.resize(new_image_size)
			self.background_image_view.image = scaled_image

		await asyncio.sleep(1)

Describe the solution you'd like

An on_change method in MainWindow.

This way, I can specify a function to be called only when the window has changed.

Describe alternatives you've considered

  1. Keep doing it manually;
  2. For the exemplified use case, it would be better if I was able to tell the image to adopt the window's width (or its box's width), so I wouldn't have to do any resizing.

Additional context

No response

@hyuri hyuri added the enhancement New features, or improvements to existing features. label Dec 29, 2023
@freakboy3742
Copy link
Member

This wouldn't be an on_change signal - it would be an on_resize signal. A change signal would describe the fact that the content of the widget had changed.

However, I should caution that if you're using Toga as intended, an on_resize signal should generally not be needed. if you're hard-coding sizes, or responding specifically to window size changes, you're missing the point of Toga's style-based layout language. In the specific case you've described, the issue is that there's no style directive to resize the image to fill the box. That is the real underlying issue here.

That said - it wouldn't be too difficult to add an on_resize handler, as the signal is already being generated to manage window size changes. All we would be doing is adding a user callback once that size change had been applied. Since the implementation should be relatively straightforward, and could be useful for situations like mobile phones changing rotation (which may require a layout change), I guess adding an on_resize handler would make sense.

@freakboy3742 freakboy3742 changed the title Add "on_change" to MainWindow Add "on_resize" to MainWindow Dec 30, 2023
@proneon267
Copy link
Contributor

proneon267 commented Jan 21, 2024

I will implement this feature in #2096 as they are related, but after the completion of window states API #1884.

Done in #2364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants