added a progressbar as a immutable widget
progressbar is a stripped down version of slider.lua.
This commit is contained in:
parent
64f848c9d0
commit
6286203075
3 changed files with 43 additions and 0 deletions
1
core.lua
1
core.lua
|
@ -22,6 +22,7 @@ function suit.new(theme)
|
|||
Checkbox = require(BASE.."checkbox"),
|
||||
Input = require(BASE.."input"),
|
||||
Slider = require(BASE.."slider"),
|
||||
ProgressBar = require(BASE.."progressbar"),
|
||||
|
||||
layout = require(BASE.."layout").new(),
|
||||
}, suit)
|
||||
|
|
26
progressbar.lua
Normal file
26
progressbar.lua
Normal file
|
@ -0,0 +1,26 @@
|
|||
-- This file is part of SUIT, copyright (c) 2016 Matthias Richter
|
||||
|
||||
local BASE = (...):match('(.-)[^%.]+$')
|
||||
local min, max = math.min, math.max;
|
||||
|
||||
return function(core, info, ...)
|
||||
local opt, x,y,w,h = core.getOptionsAndSize(...)
|
||||
|
||||
opt.id = opt.id or info
|
||||
|
||||
info.min = info.min or min(info.value, 0)
|
||||
info.max = info.max or max(info.value, 1)
|
||||
info.step = info.step or (info.max - info.min) / 10
|
||||
local fraction = (info.value - info.min) / (info.max - info.min)
|
||||
|
||||
opt.state = core:registerHitbox(opt.id, x,y,w,h)
|
||||
|
||||
core:registerDraw(opt.draw or core.theme.ProgressBar, fraction, opt, x,y,w,h)
|
||||
|
||||
return {
|
||||
id = opt.id,
|
||||
hovered = core:isHovered(opt.id),
|
||||
entered = core:isHovered(opt.id) and not core:wasHovered(opt.id),
|
||||
left = not core:isHovered(opt.id) and core:wasHovered(opt.id)
|
||||
}
|
||||
end
|
16
theme.lua
16
theme.lua
|
@ -105,6 +105,22 @@ function theme.Slider(fraction, opt, x,y,w,h)
|
|||
end
|
||||
end
|
||||
|
||||
function theme.ProgressBar(fraction, opt, x,y,w,h)
|
||||
local xb, yb, wb, hb -- size of the progress bar
|
||||
local r = math.min(w,h) / 2.1
|
||||
if opt.vertical then
|
||||
x, w = x + w*.25, w*.5
|
||||
xb, yb, wb, hb = x, y+h*(1-fraction), w, h*fraction
|
||||
else
|
||||
y, h = y + h*.25, h*.5
|
||||
xb, yb, wb, hb = x,y, w*fraction, h
|
||||
end
|
||||
|
||||
local c = opt.color and opt.color.normal or theme.color.normal
|
||||
theme.drawBox(x,y,w,h, c, opt.cornerRadius)
|
||||
theme.drawBox(xb,yb,wb,hb, {bg=c.fg}, opt.cornerRadius)
|
||||
end
|
||||
|
||||
function theme.Input(input, opt, x,y,w,h)
|
||||
local utf8 = require 'utf8'
|
||||
theme.drawBox(x,y,w,h, (opt.color and opt.color.normal) or theme.color.normal, opt.cornerRadius)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue