ComputerCraft Archive

SlideOut

computer utility kepler155c github

Description

ComputerCraft OS

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/modules/opus/ui/components/SlideOut.lua slideout
Archive:wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-modules-opus-ui-components-slideout slideout
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-modules-opus-ui-components-slideout SlideOut

Usage

Run: SlideOut

Tags

none

Source

View Original Source

Code Preview

local class = require('opus.class')
local UI    = require('opus.ui')

UI.SlideOut = class(UI.Window)
UI.SlideOut.defaults = {
	UIElement = 'SlideOut',
	transitionHint = 'expandUp',
	modal = true,
}
function UI.SlideOut:enable()
end

function UI.SlideOut:toggle()
	if self.enabled then
		self:hide()
	else
		self:show()
	end
end

function UI.SlideOut:show(...)
	UI.Window.enable(self, ...)
	self:draw()
	self:focusFirst()
end

function UI.SlideOut:hide()
	self:disable()
end

function UI.SlideOut:draw()
	if not self.noFill then
		self:fillArea(1, 1, self.width, self.height, string.rep('\127', self.width), 'black', 'gray')
	end
	self:drawChildren()
end

function UI.SlideOut:eventHandler(event)
	if event.type == 'slide_show' then
		self:show()
		return true

	elseif event.type == 'slide_hide' then
		self:hide()
		return true
	end
end

function UI.SlideOut.example()
	return UI.Window {
		y = 3,
		backgroundColor = 2048,
		button = UI.Button {
			x = 2, y = 5,
			text = 'show',
		},
		slideOut = UI.SlideOut {
			backgroundColor = 16,
			y = -7, height = 4, x = 3, ex = -3,
			titleBar = UI.TitleBar {
				title = 'test',
			},
			button = UI.Button {
				x = 2, y = 2,
				text = 'hide',
				--visualize = true,
			},
		},
		eventHandler = function (self, event)
			if event.type == 'button_press' then
				self.slideOut:toggle()
			end
		end,
	}
end