beeware / beeware/toga

SplitContainer does not honor content ratio

Open
#2,882 1 comment 0 reactions 0 assignees View on GitHub
bug gtk linux
Dominant language
Python
Stars
5.4k
Forks
827
Avg merge
15h 39m
Merged PRs (30d)
40

Description

### Describe the bug

I tried to implement a 1/3 - 2/3 UI with SplitContainer, by running this code inspired by the [Toga documentation](https://toga.readthedocs.io/en/stable/tutorial/tutorial-2.html):
```python
import toga
from toga.style.pack import COLUMN, Pack

class Tutorial2App(toga.App):

def startup(self):
data = [("root%s" % i, "value %s" % i) for i in range(1, 100)]

left_container = toga.Table(headings=["Hello", "World"], data=data)

right_content = toga.Box(style=Pack(direction=COLUMN, padding_top=50))

for b in range(0, 10):
right_content.add(
toga.Button(
"Hello world %s" % b,
style=Pack(width=200, padding=20),
)
)

right_container = toga.ScrollContainer(horizontal=False)

right_container.content = right_content

split = toga.SplitContainer()

# The content of the split container can be specified as a simple list:
# split.content = [left_container, right_container]
# but you can also specify "weight" with each content item, which will
# set an initial size of the columns to make a "heavy" column wider than
# a narrower one. In this example, the right container will be twice
# as wide as the left one.
split.content = [(left_container, 1), (right_container, 2)]

self.main_window = toga.MainWindow()
self.main_window.content = split
self.main_window.show()

def main():
return Tutorial2App("Tutorial 2", "org.beeware.toga.tutorial")

if __name__ == "__main__":
main().main_loop()
```

As a result, I get a 1/2 - 1/2 ratio (see screenshot)

### Steps to reproduce

Run the code above

### Expected behavior

Getting a 1/3 - 2/3 ratio

### Screenshots

![Capture d’écran du 2024-10-05 17-00-19](https://github.com/user-attachments/assets/5aa86738-902b-49af-ae13-8225774fb7d1)

### Environment

- Operating System: Ubuntu 24.04.1
- Python version: 3.12
- Toga version: 0.4.7

### Logs

```

```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue from the provided startup example using Toga 0.4.7, Python 3.12, and Ubuntu 24.04.1, then trace SplitContainer sizing from the `split.content = [(left_container, 1), (right_container, 2)]` entry point. Done means the example produces a 1/3–2/3 ratio rather than an even split.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.