Opened 6 years ago

Closed 2 years ago

#13904 closed enhancement (fixed)

Implement autoresizing columns in wxDataViewCtrl

Reported by: RedCAT Owned by:
Priority: normal Milestone:
Component: GUI-all Version:
Keywords: wxDataViewCtrl autoresizing columns Cc:
Blocked By: Blocking:
Patch: no


Implement proportionally resizing wxDataViewCtrl columns to fit when his size changes, like columnAutoresizingStyle in NSTableView in Cocoa framework.

Change History (9)

comment:1 Changed 6 years ago by vadz

  • Status changed from new to infoneeded_new

This is a big vague, I don't know Apple documentation by heart. What exactly do you mean i.e. how should they resize?

Personally I think that we should use the same scheme as for the status bar fields for consistency, even if it's not the clearest one (positive values specify the width in pixels, negative ones -- the part of the non-fixed width allocated to the column).

comment:2 Changed 6 years ago by RedCAT

  • Status changed from infoneeded_new to new

For example, columns at which style wxDV_COL_AUTOSIZE is specified, should autoresizes to fit wxDataViewCtrl width. Just as controls placed in horizontal wxBoxSizer autoresizes, if for them the flag wxGROW has been set. Also it is implemented in NSTableView (Cocoa):

comment:3 Changed 6 years ago by vadz

  • Status changed from new to confirmed

What happens if 2 columns have this style? Do they resize in the same proportion or do they always have the same size (this is not quite the same...)?

Anyhow, I definitely agree that it would be useful to handle at least the most common case of one column expanding to fill all the available space. And at least this should be possible in both GTK and OS X native versions (in the generic version everything is possible, of course). I don't know if more complicated approach can be implemented under both platforms.

comment:4 Changed 6 years ago by RedCAT

Two and more columns with style wxDV_COL_AUTOSIZE should proportionally resizes, as it is implemented in OS X. I don't know as it works in GTK, but most likely as well as in OS X.

comment:5 Changed 6 years ago by vadz

I read Apple documentation (for NSTableViewColumnAutoresizingStyle and not for the deprecated method linked above) and I see that it doesn't actually allow you to set the proportions of the columns anyhow. For us I think only NSTableViewNoColumnAutoresizing and NSTableViewLastColumnOnlyAutoresizingStyle actually make sense as NSTableViewUniformColumnAutoresizingStyle is useless (I've never seen a situation when I wanted all columns to have the same style) and NSTableViewSequentialColumnAutoresizingStyle and its Reverse counterpart don't exist in GTK AFAICS.

In fact I think in GTK you can't prevent the last column from resizing to fill all the available space anyhow. So for now the least we could do would be to implement the same behaviour for the other versions (generic and OS X).

Later we could add support for min/max column widths.

comment:6 Changed 6 years ago by RedCAT

Most likely, in NSTableView, proportions are the initial sizes of columns. In this case, the new sizes of columns can be calculated:

int fixedPart; // Size of the all fixed columns (without style wxDV_COL_AUTORESIZING)

/* Сalculate a proportion of a column */
column->widthRatio = column->GetWidth() / (oldControlWidth - fixedPart);

/* Calculate a new column width */
int newColumnWidth = ( newControlWidth - fixedPart ) * column->widthRatio;
column->SetWidth( wxMax(column->GetMinWidth(), wxMin(column->GetMaxWidth(), newColumnWidth) ) );

comment:7 Changed 6 years ago by RedCAT

Besides, in NSTableView autoresizes only those columns for which the has been set appropriate flag:

comment:8 Changed 4 years ago by VS

(In [75347]) Auto grow the last wxDataViewCtrl column on all platforms.

The GTK+ implementation always did this and it doesn't make much sense
to let the space be wasted, so do as GTK+ does: expand the last column
to cover the remaining unused space in the OS X and generic
implementations too. Don't do anything if the space is insufficient.
Respect the last column's minimal width.

See #13904.

comment:9 Changed 2 years ago by vadz

  • Resolution set to fixed
  • Status changed from confirmed to closed

I think the commit enough is really all we can, and should, do here, so closing this one.

Note: See TracTickets for help on using tickets.