- Reestructuració completa
This commit is contained in:
40
data/utils/ui.lua
Normal file
40
data/utils/ui.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
ui = {}
|
||||
|
||||
function ui.pushbutton(label,x,y,h,col1,col2,callback,selected)
|
||||
local size = (#label*4)-1+4
|
||||
local text_y = (h-5)//2
|
||||
local button_h=0
|
||||
local mx, my = mouse.pos()
|
||||
if mx>=x and mx<x+size and my>=y and my<y+h then
|
||||
button_h = mouse.down(mouse.LEFT) and -1 or 1
|
||||
if mouse.press(mouse.LEFT) then callback() end
|
||||
end
|
||||
draw.rrectf(x,y+1,size,h,1,col2)
|
||||
draw.rrectf(x,y-button_h,size,h,1,col1)
|
||||
draw.text(label,x+2,y+text_y-button_h,col2)
|
||||
if selected then
|
||||
draw.rrect(x-1,y-button_h-1,size+2,h+3+button_h,3,1)
|
||||
end
|
||||
end
|
||||
|
||||
function ui.togglebutton(label,x,y,h,col1,col2,dis1,dis2,state,callback,selected)
|
||||
local size = (#label*4)-1+4
|
||||
local text_y = (h-5)//2
|
||||
local bh=0
|
||||
local mx, my = mouse.pos()
|
||||
if mx>=x and mx<x+size and my>=y and my<y+h then
|
||||
bh = mouse.down(mouse.LEFT) and -1 or 1
|
||||
if mouse.press(mouse.LEFT) then callback() end
|
||||
end
|
||||
if not state then
|
||||
col1,col2 = dis1,dis2
|
||||
else
|
||||
if bh>-1 then bh=bh-1 end
|
||||
end
|
||||
draw.rrectf(x,y+1,size,h,1,col2)
|
||||
draw.rrectf(x,y-bh,size,h,1,col1)
|
||||
draw.text(label,x+2,y+text_y-bh,col2)
|
||||
if selected then
|
||||
draw.rrect(x-1,y-bh-1,size+2,h+3+bh,3,1)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user