toga icon indicating copy to clipboard operation
toga copied to clipboard

Winforms Table not expanding columns when table is inside a box

Open freakboy3742 opened this issue 1 year ago • 1 comments

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 avatar Nov 20 '24 00:11 freakboy3742

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.

freakboy3742 avatar Nov 20 '24 00:11 freakboy3742

Hi I am looking into the issue.

albuszheng avatar May 19 '25 13:05 albuszheng

Looks like this is no longer an issue, probably solved due to the recent changes on styling application, possibly #3273 Image

albuszheng avatar May 19 '25 14:05 albuszheng

Awesome - thanks for that triage!

freakboy3742 avatar May 19 '25 14:05 freakboy3742