function MakeRow {
  parameter p.
  return p:AddHLayout().
}

function MakeButton {
  parameter p.
  parameter l.
  parameter f is {}.
  local b is p:AddButton(l).
  set b:onClick to f.
  return b.
}

function MakeMenu {
  parameter stack. // the stack where menu stuff goes
  parameter btn. // the button that should show this menu
  parameter options.
  parameter execLabel.
  parameter callback.
  parameter preback is { parameter nil. }.

  local top is stack:AddVLayout().
  local sbox is top:AddScrollBox().

  local optionList is Lex().
  for option in options {
    local row is MakeRow(sbox).
    local name is option[0].
    local type is option[1].
    local field is 0.
    if type = "SCALAR" {
      row:AddLabel(name).
      set field to row:AddTextField(option[2]).
    } else if type = "BOOL" {
      set field to row:AddCheckBox(name, option[2]).
    } else if type = "RO" {
      row:AddLabel(name).
      set field to row:AddLabel(option[2]).
    } else {
      print "WARNING: Unsupported type passed to MakeMenu".
    }
    optionList:Add(name, field).
  }

  set btn:onClick to {
    preback(optionList).
    stack:ShowOnly(top).
  }.

  set top:AddButton(execLabel):onClick to callback:Bind(optionList).
}