Blame docs/tree-column-sizing.txt

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