Skip to content

Text Object (Cobalt UI)

ebernerd edited this page Aug 14, 2016 · 4 revisions

Text Object

The text object is what displays text on the screen. It wraps to the width of its parent, or its margins. You can use the wrap attribute to tell the object how it should align (left, center, or right).

To add a text object to an object (i.e., Panel), you use the function Panel:add( "text", {} ), where {} is your data table.

Attributes

  • x - x position relative to the parent
  • y - y position relative to the parent
  • text - text to display
  • foreColour - colour that the text should display
  • backColour - colour that the text should display in front of (i.e., a highlight)
  • wrap - determines how the the text should wrap (left, right, or center)
  • marginleft - the left margin, relative to the parent
  • margintop - the top margin, relative to the parent
  • state - determines if the object should draw, depending on cobalt.state. Useful for multi-screen apps. Default is its parent's state.

Methods

  • :setMargins( top, left ) - sets the margins
  • :resize() - though called internally, this function adjusts the margins and sizes based on the parent's size

Example

local cobalt = dofile( "cobalt" )
cobalt.ui = dofile( "cobalt-ui/init.lua" )

local Panel = cobalt.ui.new({ w = "50%", marginleft="25%", h = "50%", margintop = "25%" })
local Text = Panel:add( "text", { text="I'm a text object!", wrap="center", margintop="50%" } )

function cobalt.draw()
  cobalt.ui.draw()
end

cobalt.initLoop()

Result: result