Skip to content

Core Elements Tutorial

Benedict Allen edited this page Nov 17, 2015 · 1 revision

Core Elements Tutorial

The core elements are the ones that Sheets provides by default, and are the basic things you'll need to make a fully functional application.

They are listed (and documented) over here.

Some commonly used objects

A button is about as basic as it gets. It is clickable, and has word wrapped text inside it. It can be any size, and be anywhere on (or off) the screen. If you want to allow the user to click something, this is a great choice.

An example usage of this could be where the user clicks to toggle the redstone output of some sides of the computer.

-- The sides that should be displayed:
local sides = { "left", "right", "back" }

-- Create the application
local application = Application()

-- Create a label at the top, centre of the screen
local label = application.screen + Text( math.floor( application.screen.width / 2 - 11 ), 1, 22, 1, "Toggle redstone output" )

-- Calculate the width of the button, assuming a space of 1 between buttons and the edges of the screen
local buttonWidth = math.floor( ( application.screen.width - #sides - 1 ) / #sides )

-- Go through all the sides, creating a button for each
for i = 1, #sides do
	-- Calculate its position
	local buttonX = ( i - 1 ) * ( buttonWidth + 1 ) + 1
	-- Create the button, added to the application screen
	local button = application.screen + Button( buttonX, 3, buttonWidth, 3, sides[i] )

	-- Create a callback to be called when the button is clicked
	function button:onClick()
		-- ... which toggles the redstone output on that side
		rs.setOutput( sides[i], not rs.getOutput( sides[i] ) )
	end
end

-- Run the application
application:run()

A checkbox is a very simple box that can be toggled on or off. It's good for situations where the user has to choose a simple yes or no to some question.

A container is great for laying things out. You can use containers to collect a bunch of components, then move or remove the container to do the same to all the children, rather than moving or removing each child individually.

A scroll container allows you to place components that don't quite fit where they're supposed to where you want by adding scrollbars that let you move around the components it contains. You can make long lists of things, or show images that are 50x bigger than the screen without losing any content.

A text object is useful for when you just want to show some text without having it interact in any way, like in a dialogue box. It's very simple to set up and just works.

A text input is a box that lets the user enter text. It's pretty easy to use (for the user), with features like selection, scrolling, and keyboard shortcuts. They're great for username or password boxes, or even response fields.

Clone this wiki locally