Blame docs/tree-column-sizing.txt

Packit 98cdb6
The way that the GtkTreeView calculates sizing is pretty confusing.
Packit 98cdb6
This is written down to help keep track of it in my head, and thus help
Packit 98cdb6
anyone who hopes to work with the code in the future.
Packit 98cdb6
-jrb
Packit 98cdb6
Packit 98cdb6
HOW THE GTKTREEVIEW CALCULATES SIZE:
Packit 98cdb6
====================================
Packit 98cdb6
 When the view is given a new model, the first thing it does is walk
Packit 98cdb6
through the model at the top level, creating an GtkRBNode for each
Packit 98cdb6
element of the model.  Each node has a height of 0.  The RBTree is kept
Packit 98cdb6
updated as the models structure changes.  Additionally, the user can
Packit 98cdb6
expand, collapse, and select rows at this stage.  The RBTree is accurate
Packit 98cdb6
-- it just has a height of zero for every row.
Packit 98cdb6
Packit 98cdb6
When the widget is realized, it calls install_presize_handler, to setup
Packit 98cdb6
the first-run function.  This is run before the expose event.
Packit 98cdb6
Packit 98cdb6
HOW THE GTKTREEVIEWCOLUMN STORES SIZE:
Packit 98cdb6
======================================
Packit 98cdb6
Packit 98cdb6
There are a number of size related fields in the GtkTreeViewColumn
Packit 98cdb6
structure.  These are all valid after realization:
Packit 98cdb6
Packit 98cdb6
  column_type	    The sizing method to use when calculating the size
Packit 98cdb6
		    of the column.  Can be GROW_ONLY, AUTO, and FIXED.
Packit 98cdb6
Packit 98cdb6
  button_request    The width as requested by the button.
Packit 98cdb6
Packit 98cdb6
  requested_width   The width of the column as requested by the column.
Packit 98cdb6
		    It is the max requested width of the bcells in the
Packit 98cdb6
		    column.  If the column_type is AUTO, then it is
Packit 98cdb6
		    recalculated when a column changes.  Otherwise, it
Packit 98cdb6
		    only grows.
Packit 98cdb6
Packit 98cdb6
  resized_width     The width after the user has resized the column.
Packit 98cdb6
Packit 98cdb6
  width             The actual width of the column as displayed.
Packit 98cdb6
Packit 98cdb6
  fixed_width       The requested fixed width for the column iff it's
Packit 98cdb6
		    sizing type is set to GTK_TREE_VIEW_COLUMN_FIXED.
Packit 98cdb6
		    Used instead of requested_width in that case.
Packit 98cdb6
Packit 98cdb6
  min_width	    The minimum width the column can be.  If set to -1,
Packit 98cdb6
		    this field is considered unset.
Packit 98cdb6
Packit 98cdb6
  max_width	    The maximum width the column can be.  This can be
Packit 98cdb6
		    overridden for the last column, if the tree_view is
Packit 98cdb6
		    actually wider than the sum of all of the columns
Packit 98cdb6
		    requested_widths.  If set to -1, this field is
Packit 98cdb6
		    considered unset.
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
  use_resized_width Use resized_width to determine the size.
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
--
Packit 98cdb6
tree_view->priv->width  = the width the widget wants to be, including headers.
Packit 98cdb6
tree_view->priv->height = the height the widget requests.  It's the sum
Packit 98cdb6
			  of the width of all visible columns.
Packit 98cdb6
Packit 98cdb6
Both of these are calculated in _gtk_tree_view_update_size
Packit 98cdb6
Packit 98cdb6
--
Packit 98cdb6
Packit 98cdb6
The following invariants are true:
Packit 98cdb6
Packit 98cdb6
min_width is less than or equal to width
Packit 98cdb6
Packit 98cdb6
max_width is greater than or equal to width
Packit 98cdb6
Packit 98cdb6
min_width <= max_width
Packit 98cdb6
Packit 98cdb6
(sizing == GTK_TREE_VIEW_COLUMN_FIXED) => (requested_width == fixed_width)
Packit 98cdb6
Packit 98cdb6
(column != last visible column) => width == CLAMP (requested_width, min_width, max_width)
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
HOW THE VERTICAL OFFSET IS CALCULATED
Packit 98cdb6
(This has nothing to do with columns)
Packit 98cdb6
=====================================
Packit 98cdb6
Packit 98cdb6
The current offset of the tree is determined by:
Packit 98cdb6
Packit 98cdb6
tree_view->priv->dy
Packit 98cdb6
Packit 98cdb6
All motion/button/expose events take this as the offset when trying to
Packit 98cdb6
draw the tree.  There are also two other related members:
Packit 98cdb6
Packit 98cdb6
tree_view->priv->top_row
Packit 98cdb6
tree_view->priv->top_row_dy
Packit 98cdb6
Packit 98cdb6
In general _gtk_rbtree_node_find_offset (tree_view->priv->top_row) +
Packit 98cdb6
tree_view->priv->top_row_dy is the same as tree_view->priv->dy.
Packit 98cdb6
We have the alternate method so we can update dy when the tree changes.
Packit 98cdb6
There are two functions:
Packit 98cdb6
Packit 98cdb6
gtk_tree_view_dy_to_top_row
Packit 98cdb6
   and
Packit 98cdb6
gtk_tree_view_top_row_to_dy
Packit 98cdb6
Packit 98cdb6
They are called when the tree's confirmation changes, in order to sync
Packit 98cdb6
the value appropriately.  Note that these two functions sometimes call
Packit 98cdb6
each other to negotiate a correct value if needed.