tweaks + Anavrins disk usage system module

This commit is contained in:
kepler155c@gmail.com
2019-07-02 10:19:08 -04:00
parent aec5ac0121
commit 1dcb6d67b7
7 changed files with 200 additions and 54 deletions

View File

@@ -10,13 +10,7 @@ local modifiers = Util.transpose {
keys.leftAlt, keys.rightAlt,
}
local input = {
state = { },
}
if not keyboard then
keyboard = { state = input.state }
end
local input = { }
function input:modifierPressed()
return keyboard.state[keys.leftCtrl] or
@@ -64,7 +58,6 @@ end
function input:reset()
self.state = { }
self.fired = nil
self.timer = nil
self.mch = nil
@@ -81,7 +74,6 @@ function input:translate(event, code, p1, p2)
if event == 'key' then
if p1 then -- key is held down
if not modifiers[code] then
self.fired = true
local ch = input:toCode(keys.getName(code), code)
if #ch == 1 then
return {
@@ -92,37 +84,19 @@ function input:translate(event, code, p1, p2)
return { code = ch }
end
elseif code then
--self.fired = true
local ch = input:toCode(keys.getName(code), code)
if #ch ~= 1 then
return { code = ch }
end
-- self.state[code] = true
local ch = input:toCode(keys.getName(code), code)
if #ch ~= 1 then
return { code = ch }
end
end
elseif event == 'char' then
local combo = isCombo()
--if not self.fired then
if combo or not (keyboard.state[keys.leftCtrl] or keyboard.state[keys.rightCtrl]) then
self.fired = not combo
return { code = event, ch = code }
--end
-- return { code = event, ch = input:toCode(code) }
if combo or not (keyboard.state[keys.leftCtrl] or keyboard.state[keys.rightCtrl]) then
return { code = event, ch = code }
end
elseif event == 'key_upx' then
if not self.fired then
--if self.state[code] then
self.fired = true
local ch = input:toCode(keys.getName(code), code)
self.state[code] = nil
return { code = ch }
--end
end
self.state[code] = nil
elseif event == 'paste' then
self.fired = true
if keyboard.state[keys.leftShift] or keyboard.state[keys.rightShift] then
return { code = 'shift-paste', text = code }
else
@@ -142,7 +116,6 @@ function input:translate(event, code, p1, p2)
elseif event == 'mouse_drag' then
self.mfired = true
self.fired = true
return {
code = input:toCode('mouse_drag', 255),
button = code,
@@ -169,7 +142,6 @@ function input:translate(event, code, p1, p2)
self.mch = 'mouse_up'
self.mfired = input:toCode(self.mch, 255)
end
self.fired = true
return {
code = self.mfired,
button = code,
@@ -182,7 +154,6 @@ function input:translate(event, code, p1, p2)
[ -1 ] = 'scroll_up',
[ 1 ] = 'scroll_down'
}
self.fired = true
return {
code = input:toCode(directions[code], 255),
x = p1,

View File

@@ -457,7 +457,6 @@ function UI.Window:initChildren()
if not child.parent then
child.parent = self
child:setParent()
-- child:reposition() -- maybe
if self.enabled then
child:enable()
end
@@ -468,6 +467,24 @@ function UI.Window:initChildren()
end
function UI.Window:layout()
local function calc(p, max)
p = tonumber(p:match('(%d+)%%'))
return p and math.floor(max * p / 100) or 1
end
if type(self.x) == 'string' then
self.x = calc(self.x, self.parent.width)
end
if type(self.ex) == 'string' then
self.ex = calc(self.ex, self.parent.width)
end
if type(self.y) == 'string' then
self.y = calc(self.y, self.parent.height)
end
if type(self.ey) == 'string' then
self.ey = calc(self.ey, self.parent.height)
end
if self.x < 0 then
self.x = self.parent.width + self.x + 1
end

View File

@@ -4,7 +4,6 @@ local UI = require('opus.ui')
UI.NftImage = class(UI.Window)
UI.NftImage.defaults = {
UIElement = 'NftImage',
event = 'button_press',
}
function UI.NftImage:setParent()
if self.image then

View File

@@ -6,13 +6,23 @@ local colors = _G.colors
UI.ProgressBar = class(UI.Window)
UI.ProgressBar.defaults = {
UIElement = 'ProgressBar',
progressColor = colors.lime,
backgroundColor = colors.gray,
height = 1,
progressColor = colors.lime,
progressChar = UI.extChars and '\153' or ' ',
fillChar = ' ',
fillColor = colors.gray,
textColor = colors.green,
value = 0,
}
function UI.ProgressBar:draw()
self:clear()
local width = math.ceil(self.value / 100 * self.width)
self:clearArea(1, 1, width, self.height, self.progressColor)
local filler = string.rep(self.fillChar, self.width)
local progress = string.rep(self.progressChar, width)
for i = 1, self.height do
self:write(1, i, filler, nil, self.fillColor)
self:write(1, i, progress, self.progressColor)
end
end