-
Notifications
You must be signed in to change notification settings - Fork 0
Radial Buttons
JJSax edited this page Apr 22, 2021
·
1 revision
Example radial menu code.
diallib, arcButton = require("ui.dial")()
p = require("nprint")
function love.load()
-- first set the dial. This provides a central way to reposition buttons on a dial.
dial = diallib.new(400, 400, 300)
local last = 0
for i = 1, 6 do -- loop to make 6 equally sized arc buttons
arcButton.new(dial, last, last + math.pi/3)
local t = dial.buttons[#dial.buttons] -- dial.buttons is set within the library
t:setText(string.rep(i, 4), true) -- fast way to set text. See main wiki for more info.
function t:onRelease() -- how to set a released mouse custom function
print(t.text)
end
function t:onEnter() -- Callback when the cursor enters the bounding box of button
t:setColor({math.random(), math.random(), math.random(), 1}, true)
end
last = last + math.pi/3
end
end
-- the rest are standard Love2d functions. See uisets to learn more about how to bundle multiple buttons together.
function love.update(dt)
dial:update(dt)
end
function love.draw()
dial:draw()
end
function love.mousepressed(x, y, button, istouch, presses)
dial:mousepressed(x, y, button)
end
function love.mousereleased(x, y, button)
dial:mousereleased(x, y, button)
end