Skip to content

Widgets

Loewe_111 edited this page Nov 14, 2023 · 6 revisions

Widget functions

About widgets

Widgets are objects that can be added to a screen object. They are used to display text, buttons, images, etc. on the screen. Calling a widget function with also add the widget to the screen. All widgets get called with a args table, which contains values that are used to draw the widget.

Widgets have a unique ID, which is normally assigned automatically, but can be manually assigned by passing an id value to the args table.

Functions:

screenObject:text(args)

Description: creates and adds a text widget to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • text - the text to display
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:textarea(args)

Description: creates and adds a textarea widget to the screen, which wraps text in the given width

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • width - the width of the widget
  • height - the height of the widget
  • text - the text to display
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:button(args)

Description: creates and adds a button widget to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • text - the text to display
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • callback - the function to call when the button is clicked (parameters: x, y, button)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:checkbox(args)

Description: creates and adds a checkbox widget to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • text - the text to display
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • checked - whether the checkbox is checked or not (optional, default: false)
  • callback - the function to call when the checkbox is clicked (parameters: x, y, button, checked)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:radio(args)

Description: creates and adds a radio widget to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • options - a table containing the options to display
  • selected - the selected option (optional, default: 1)
  • callback - the function to call when the radio is changed (optional, parameters: selected)

screenObject:switch(args)

Description: creates and adds a switch widget to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • text - the text to display
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • state - whether the switch is checked or not (optional, default: false)
  • callback - the function to call when the switch is clicked (parameters: x, y, button, state)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:input(args)

Description: creates and adds an input widget to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • width - the width of the widget (optional, default: length of the placeholder text)
  • placeholder - the placeholder text to display
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • placeholderColor - the color of the placeholder text (optional, default: colors.gray)
  • callback - the function to call when the input is changed (parameters: text)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:inputArea(args)

Description: creates and adds an input Area widget to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • width - the width of the widget
  • height - the height of the widget
  • placeholder - the placeholder text to display
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • placeholderColor - the color of the placeholder text (optional, default: colors.gray)
  • callback - the function to call when the input is changed (parameters: text)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:tabSwitch(args)

Description: creates and adds a tab switch widget to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • color - the color of the text (optional, default: colors.white)
  • background - the background color of the text (optional, default: colors.black)
  • selectedColor - color of the text of the selected tab (optional, default: colors.white)
  • selectedBackground - color of the background of the selected tab (optional, default colors.red)
  • callback - the function to call when the input is changed (parameters: text)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:progressBar(args)

Description: creates and adds a Progress Bar to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • width - the width of the widget
  • color - the color of the finished progress (optional, default: colors.white)
  • background - the background color of the progress bar (optional, default: colors.black)
  • progress - the shown progress of the progressbar (0 to 1)
  • id - manually assign an ID to the widget

Returns: the widget object

screenObject:slider(args)

Description: creates and adds a Slider to the screen

grafik

Parameters: args - a table containing the following values:

  • x - the x position of the widget
  • y - the y position of the widget
  • width - the width of the widget
  • min - minimum value of the slider
  • max - maximum value of the slider
  • color - the color of the slider thumb (optional, default: colors.white)
  • background - the background color of the slider (optional, default: colors.black)
  • value - the default value of the slider
  • callback - the function to call when the value is changed (parameters: text)
  • id - manually assign an ID to the widget

Returns: the widget object