factoriolib / flib

A set of high-quality, commonly-used utilities for creating Factorio mods.
https://mods.factorio.com/mod/flib
MIT License
61 stars 15 forks source link

gui-beta and conditions #25

Closed hahoyer closed 3 years ago

hahoyer commented 3 years ago

I can't find any conditions in the new gui-beta. Have they been removed completely?

raiguard commented 3 years ago

Yes, they have been removed. You can accomplish the same thing with a simple if statement in a builder function, a ternary, or an inline function (though the syntax for the latter is a bit ugly).

Example using a ternary:

children = {
  {type = "label", style ="ltnm_bold_black_label"},
  (something > otherthing
    and
      {type = "flow", children = {
        {type = "label", style = "ltnm_semibold_black_label", caption = {"ltnm-gui.trains-label"}},
        {type = "label", style = "ltnm_black_label"}
      }}
    or nil
  ),
  {type = "flow", children = {
    {type = "label", style = "ltnm_semibold_black_label", caption = {"ltnm-gui.status-label"}},
    {type = "flow"}
  }},
  {type = "flow", children = {
    {type = "label", style = "ltnm_semibold_black_label", caption = {"ltnm-gui.network-id-label"}},
    {type = "label", style = "ltnm_black_label"}
  }
}