nicopap / cuicui_layout

The dumbest and simplest layouting algorithm for bevy
40 stars 2 forks source link

chirp templates: `for` statement #94

Open nicopap opened 1 year ago

nicopap commented 1 year ago

We need a way to insert several entities from a list. But one of the issues is that statements are supposed to correspond to exactly one entity.

One option is for for loops to expand to a single entity, but spawn several entities within that entity. But I'm not quite sure how to express that in term of syntax. See:

BoxContent(column rules(1.*, 1.2*)) {
    BoxSelectedText(style(OptionBoxChoice) text(default_choice_text))
    for [size, content] in options_sizes in BoxTicks(row rules(1.3*, 1*)) {
        Tick(rules(size, 3px) option_tick(content))
    }
}
RArrow(style(OptionBoxRArrow) height(25px))

Maybe it's worthwhile to make an exception for for loops on the one entity rule? If so, this becomes a bit more sensible:

BoxContent(column rules(1.*, 1.2*)) {
    BoxSelectedText(style(OptionBoxChoice) text(default_choice_text))
    BoxTicks(row rules(1.3*, 1*)) {
      for [size, content] in options_sizes {
          Tick(rules(size, 3px) option_tick(content))
      }
    }
}
RArrow(style(OptionBoxRArrow) height(25px))

Other options

So what we really want is:

  1. Define a Query (using a dynamic query)
  2. Define a binding so that we can use the query return values
  3. Define a single statement
// rust-like syntax
// We could use <> instead of () in this particular instance
for (foo, bar) in Query((Foo, Bar), With(Baz)) {
    FooBarItem(method(foo))
}

// haskell-like syntax
let (foo, bar) = Query<(Foo, Bar), With<Baz>> in FooBarItem(method(foo))

I'll probably go with the rust-like syntax.