Skip to content

Examples: Window

William Willing edited this page Jan 14, 2015 · 6 revisions

Creating a window

require "gui"

local window = gui.create_window()
window.title = "Window Demo"

gui.run()

Responding to window movement

require "gui"

local window = gui.create_window()
window.title = "Move Demo"

function window:on_move()
  window.title = window.x .. ", " .. window.y
end

gui.run()

Responding to window resizing

require "gui"

local window = gui.create_window()
window.title = "Resize Demo"

function window:on_resize()
  window.title = window.width .. ", " .. window.height
end

gui.run()

Preventing a window from closing v4

require 'gui'

local window = gui.create_window()
window.title = "Close Demo"

function window:on_closing()
  return false
end

gui.run()

Receiving keyboard events

require "gui"

local window = gui.create_window()
window.title = "Keyboard Event Demo"
    
local label = window:add_label()
    
function window:on_key_down(key)
  label.text = key .. " pressed"
end
    
function window:on_key_up(key)
  label.text = key .. " released"
end

gui.run()

Receiving mouse events

require "gui"

local window = gui.create_window()
window.title = "Mouse Event Demo"
    
local button_label = window:add_label()
local coordinates_label = window:add_label()
coordinates_label.y = button_label.height
    
function window:on_mouse_move(x, y)
  coordinates_label.text = x .. ", " .. y
end
    
function window:on_mouse_up(button)
  button_label.text = button .. " button released"
end
    
function window:on_mouse_down(button)
  button_label.text = button .. " button pressed"
end

gui.run()

Clone this wiki locally