Skip to content

How to set column widths on a grid? #570

Answered by nicoburns
avsaase asked this question in Q&A
Discussion options

You must be logged in to vote

Firstly, you probably want grid_template_columns rather than grid_auto_columns. grid_auto_columns is for determining the size of columns that are not declared up front as part of the "explicit grid" but created implicitly when a child is placed in row/column that is outside of the bounds of that grid. The easiest way to set each column's size is using the helper functions in the style_helpers module (https://docs.rs/taffy/latest/taffy/style_helpers/index.html). An example would be:

taffy.set_style(node, Style {
    grid_template_columns: vec![auto(), length(10.0), percent(10.0), fr()],
    ..
});

The different types of column size are:

  • length(f32) - a fixed pixel column size
  • percent(f32)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@avsaase
Comment options

@nicoburns
Comment options

Answer selected by avsaase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants