Widgets within an OptionContainer are too large if a window is shown prior to the container being assigned to the window
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 827
- Avg merge
- 9h 45m
- Merged PRs (30d)
- 58
Description
### Describe the bug
On Windows, a behavior that was introduced in Toga 0.5.0 in which (at least) Label and Button elements within an OptionContainer are too large if the OptionContainer is assigned to a Window after the Window has already been shown.
Here is code to reproduce:
```
import toga
class TogaApp(toga.App):
def startup(self) -> None:
self.main_window = toga.MainWindow()
self.main_window.show()
container_box = toga.Box()
container_box.add(toga.Label("TEST Label", background_color="lightblue"))
container_box.add(toga.Button("TEST Button"))
home_tab = toga.OptionItem(text="Home", content=container_box,)
option_container = toga.OptionContainer(content=[home_tab])
# self.main_window.hide()
self.main_window.content = option_container
# self.main_window.show()
def main():
return TogaApp("Toga App", 'org.beeware.togaapp')
if __name__ == "__main__":
main().main_loop()
```
Here is an example of a window produced by the foregoing code:
And here is an example if you uncomment the hide and show commands:
### Steps to reproduce
1. Run the povided code on Windows and with Toga 0.5.0
2. The rendered Label and Button elements are too large.
### Expected behavior
The window produced by this code should be the same regardless of when the window is actually shown.
### Screenshots
_No response_
### Environment
- Operating System: Windows 11
- Python version: 3.12.7
- Software versions:
- Toga: 0.5.0
### Logs
```
```
### Additional context
I ran into this when reassigning the MainWindow's content. E.g., from an initial "loading" box to its final post-loading content.
Contributor guide
Research direction
Begin by running the provided reproduction on Windows with Toga 0.5.0, comparing the layout when the window is shown before assigning the OptionContainer with the hide-and-show variant. Trace the Windows widget sizing and layout lifecycle for Label and Button elements; done means both sequences produce the same-sized widgets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100