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

Winforms Table not expanding columns when table is inside a box #2974

Open
freakboy3742 opened this issue Nov 20, 2024 Discussed in #2973 · 1 comment
Open

Winforms Table not expanding columns when table is inside a box #2974

freakboy3742 opened this issue Nov 20, 2024 Discussed in #2973 · 1 comment
Labels
bug A crash or error in behavior. windows The issue relates to Microsoft Windows support.

Comments

@freakboy3742
Copy link
Member

Originally posted by tfcroft4 November 20, 2024, as #2973

If I place a table in a box and add the box to the main window the table columns are compressed.
If I add a table directly to the main window the table expands as expected.

main_box = toga.Box(style=Pack(direction=COLUMN))
data_box = toga.Box(style=Pack(direction=COLUMN, padding=5 , background_color=BLUE)) 
data_table = toga.Table(style=Pack(flex=1,padding=5),
    headings=["Name", "Age", "Planet"],
    data=[
        {"name": "Arthur Dent", "age": 42, "planet": "Earth"},
        {"name": "Ford Prefect", "age": 37, "planet": "Betelgeuse Five"},
        {"name": "Tricia McMillan", "age": 38, "planet": "Earth"},
    ]   
)
data_table_2 = toga.Table(style=Pack(flex=1,padding=5),
    headings=["Planet","Name", "Age",],
    data=[
        {"name": "Tricia McMillan", "age": 38, "planet": "Earth"},
        {"name": "Ford Prefect", "age": 37, "planet": "Betelgeuse Five"},
        {"name": "Arthur Dent", "age": 42, "planet": "Earth"},
    ]   
)
data_box.add(data_table)
main_box.add(data_box) #compressed table width
main_box.add(data_table_2) #full table width

Toga Table Test

@freakboy3742 freakboy3742 added bug A crash or error in behavior. windows The issue relates to Microsoft Windows support. labels Nov 20, 2024
@freakboy3742
Copy link
Member Author

Thanks for the report @tfcroft4.

My guess is that the code that as a result of being placed inside a box, the trigger to balance the initial column layout is being triggered earlier in the process than when the table is "bare".

For anyone looking to investigate - the column are resized using the method _resize_columns(), which is triggered when a column is added or removed, or when the layout tells the table that it has resized. My guess is that the pending_resize flag is the cause of the problem here; it exists as an optimisation so that the columns aren't continuously resized when the window is resized; but there might be a need for an additional check that the "candidate" size is actually big enough (it wouldn't surprise me if the first resize is being done with a table size of (0x0) on an initial layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior. windows The issue relates to Microsoft Windows support.
Projects
None yet
Development

No branches or pull requests

1 participant