Skip to content

How to create fixed number of emlement from array? #4835

Answered by mitchgrout
ziyouwa asked this question in General
Discussion options

You must be logged in to vote

Hmm, I was thinking that something like this would be doable:

  private property<int>      columns: 3;
  private property<[string]> strings: ["a", "b", "c", "d", "e", "f", "g"];
  
  GridLayout {
    for row in ceil(strings.length / columns): Row {
      private property<int> offset: row * columns;

      for column in min(columns, strings.length - offset): Text {
        text: strings[offset + column];
      }
    }
  }

...but this triggers an error 'if' or 'for' expressions are not currently supported in grid layouts :(

One option would be to manually 'reshape' your array into that layout you want, e..g

private property<[[string]]> strings: [
  ["a", "b", "c"],
  ["d", "e", "f"],
  ["g", 

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@mitchgrout
Comment options

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