Canvas layout system

From FlightGear wiki
Jump to navigation Jump to search


#
# Base class for all widgets/layouts
#
var LayoutItem = {
  getCanvas: func(),

  setCanvas: func(<Canvas>),

  getParent: func(),

  setParent: func(<LayoutItem>),

  sizeHint: func(),

  minimumSize: func(),

  maximumSize: func(),

  hasHeightForWidth: func(),

  heightForWidth: func(<int: width>),

  minimumHeightForWidth: func(<int: width>),

  setVisible: func(<bool: visible>),

  isVisible: func(),

  isExplicitlyHidden: func(),

  show: func(),

  hide: func(),

  setGeometry: func([<int: x>, <int: y>, <int: width>, <int: height>]),

  geometry: func()
};

#
# Base class for all layouts
#
var Layout = {
  parents: [LayoutItem],

  # Add an item.
  addItem: func(<LayoutItem>),

  # Set the spacing/padding between items.
  setSpacing: func(<int: space>),

  # Get the spacing/padding between items.
  spacing: func(),

  # Get the number of items (excluding nested items).
  count: func(),

  # Get the item at the given position.
  itemAt: func(<int: index>),

  # Remove and get the item at the given position.
  takeAt: func(<int: index>),

  # Remove the given item from the layout.
  removeItem: func(<LayoutItem>),

  # Remove all items.
  clear: func()
};

#
# Vertical or horizontal box layout
#
var BoxLayout = {
  parents: [Layout],

  addItem: func(<LayoutItem>[, <int: stretch> = 0]),

  addStretch: func([<int: stretch> = 0]),

  addSpacing: func(<int: size>),

  insertItem: func(<int: index>, <LayoutItem>[, <int: stretch> = 0]),

  insertStretch: func(<int: index>[, <int: stretch> = 0]),

  insertSpacing: func(<int: index>, <int: size>),

  # Set the stretch factor of the item at the given position to <stretch>.
  setStretch: func(<int: index>, <int: stretch>),

  # Set the stretch factor of the given item to <stretch>
  # (if it exists in this layout).
  setStretchFactor: func(<LayoutItem>, <int: stretch>),

  # Get the stretch factor of the item at the given position.
  stretch: func(<int: index>)
};

#
# Horizontal box layout
#
var HBoxLayout = {
  parents: [BoxLayout],

  # Create a horizontal box layout
  new: func()
};

#
# Vertical box layout
#
var VBoxLayout = {
  parents: [BoxLayout],

  # Create a vertical box layout
  new: func()
};