mirror of
https://github.com/S4mpsa/InfOS.git
synced 2025-08-05 10:56:05 -04:00
Merge pull request #7 from gordominossi/feature/gui-pages-navigation
Feature/gui pages navigation
This commit is contained in:
commit
37e25a85c9
@ -73,11 +73,46 @@ end
|
|||||||
local function drawPanelSection(index, title)
|
local function drawPanelSection(index, title)
|
||||||
local width = math.floor(0.6 * Constants.baseWidth)
|
local width = math.floor(0.6 * Constants.baseWidth)
|
||||||
local height = math.floor(0.6 * Constants.baseHeight)
|
local height = math.floor(0.6 * Constants.baseHeight)
|
||||||
local x = (Constants.baseWidth - width) / 2
|
local x = math.floor((Constants.baseWidth - width) / 2)
|
||||||
local y = (index - 1) * Constants.baseHeight + math.floor((Constants.baseHeight - height) / 2)
|
local y = (index - 1) * Constants.baseHeight + math.floor((Constants.baseHeight - height) / 2)
|
||||||
Widget.drawBaseWidget(x, y, width, height, title)
|
Widget.drawBaseWidget(x, y, width, height, title)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function drawNavigationButton(self, index)
|
||||||
|
local width = math.floor(0.3 * Constants.baseWidth)
|
||||||
|
local height = math.floor(0.6 * Constants.baseHeight)
|
||||||
|
local x = math.floor((2.4 + 0.4 * index) * Constants.baseWidth) + math.floor((Constants.baseWidth - width) / 2)
|
||||||
|
local y = 4 * Constants.baseHeight + math.floor((Constants.baseHeight - height) / 2)
|
||||||
|
if self.active then
|
||||||
|
Widget.drawBaseWidget(x, y, width, height, self.title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function clickNavigationButton(self)
|
||||||
|
if not self.active then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if self.title == "◀" then
|
||||||
|
elements.machineWidgets.active.index = elements.machineWidgets.active.index - 1
|
||||||
|
else
|
||||||
|
elements.machineWidgets.active.index = elements.machineWidgets.active.index + 1
|
||||||
|
end
|
||||||
|
for i = 1, 9 do
|
||||||
|
elements.machineWidgets.active[i] = elements.machineWidgets[9 * (elements.machineWidgets.active.index - 1) + i]
|
||||||
|
end
|
||||||
|
|
||||||
|
elements[6] = elements.machineWidgets.active[1]
|
||||||
|
elements[7] = elements.machineWidgets.active[2]
|
||||||
|
elements[8] = elements.machineWidgets.active[3]
|
||||||
|
elements[10] = elements.machineWidgets.active[4]
|
||||||
|
elements[11] = elements.machineWidgets.active[5]
|
||||||
|
elements[12] = elements.machineWidgets.active[6]
|
||||||
|
elements[14] = elements.machineWidgets.active[7]
|
||||||
|
elements[15] = elements.machineWidgets.active[8]
|
||||||
|
elements[16] = elements.machineWidgets.active[9]
|
||||||
|
Widget.clear()
|
||||||
|
end
|
||||||
|
|
||||||
function page.create(element)
|
function page.create(element)
|
||||||
drawTitle(element.title)
|
drawTitle(element.title)
|
||||||
|
|
||||||
@ -95,21 +130,45 @@ function page.create(element)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elements.machineWidgets.active = {}
|
||||||
|
elements.machineWidgets.active.index = 1
|
||||||
|
for i = 1, 9 do
|
||||||
|
elements.machineWidgets.active[i] = elements.machineWidgets[9 * (elements.machineWidgets.active.index - 1) + i]
|
||||||
|
end
|
||||||
|
elements.navigationButtons[1] = {
|
||||||
|
title = "◀",
|
||||||
|
active = true,
|
||||||
|
update = function(self)
|
||||||
|
self.active = elements.machineWidgets[elements.machineWidgets.active.index * 9 - 10] ~= nil
|
||||||
|
end,
|
||||||
|
onClick = clickNavigationButton,
|
||||||
|
draw = drawNavigationButton
|
||||||
|
}
|
||||||
|
elements.navigationButtons[2] = {
|
||||||
|
title = "▶",
|
||||||
|
active = true,
|
||||||
|
update = function(self)
|
||||||
|
self.active = elements.machineWidgets[elements.machineWidgets.active.index * 9 + 1] ~= nil
|
||||||
|
end,
|
||||||
|
onClick = clickNavigationButton,
|
||||||
|
draw = drawNavigationButton
|
||||||
|
}
|
||||||
|
|
||||||
elements[4.5] = {
|
elements[4.5] = {
|
||||||
onClick = function()
|
onClick = function()
|
||||||
Computer.shutdown(true)
|
Computer.shutdown(true)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
elements[6] = elements.machineWidgets[1]
|
elements[6] = elements.machineWidgets.active[1]
|
||||||
elements[7] = elements.machineWidgets[2]
|
elements[7] = elements.machineWidgets.active[2]
|
||||||
elements[8] = elements.machineWidgets[3]
|
elements[8] = elements.machineWidgets.active[3]
|
||||||
elements[10] = elements.machineWidgets[4]
|
elements[10] = elements.machineWidgets.active[4]
|
||||||
elements[11] = elements.machineWidgets[5]
|
elements[11] = elements.machineWidgets.active[5]
|
||||||
elements[12] = elements.machineWidgets[6]
|
elements[12] = elements.machineWidgets.active[6]
|
||||||
elements[14] = elements.machineWidgets[7]
|
elements[14] = elements.machineWidgets.active[7]
|
||||||
elements[15] = elements.machineWidgets[8]
|
elements[15] = elements.machineWidgets.active[8]
|
||||||
elements[16] = elements.machineWidgets[9]
|
elements[16] = elements.machineWidgets.active[9]
|
||||||
|
|
||||||
elements[18] = elements.powerWidgets[1]
|
elements[18] = elements.powerWidgets[1]
|
||||||
elements[19] = elements.powerWidgets[1]
|
elements[19] = elements.powerWidgets[1]
|
||||||
@ -131,14 +190,21 @@ function page.fake()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function page.update()
|
function page.update()
|
||||||
for index, machineWidget in ipairs(elements.machineWidgets) do
|
for _, machineWidget in ipairs(elements.machineWidgets) do
|
||||||
machineWidget:update()
|
machineWidget:update()
|
||||||
machineWidget:draw(index)
|
end
|
||||||
|
for index, activeMachineWidget in ipairs(elements.machineWidgets.active) do
|
||||||
|
activeMachineWidget.draw(activeMachineWidget, index)
|
||||||
end
|
end
|
||||||
for index, powerWidget in ipairs(elements.powerWidgets) do
|
for index, powerWidget in ipairs(elements.powerWidgets) do
|
||||||
powerWidget:update()
|
powerWidget:update()
|
||||||
powerWidget:draw(index)
|
powerWidget:draw(index)
|
||||||
end
|
end
|
||||||
|
for index, navigationButton in ipairs(elements.navigationButtons) do
|
||||||
|
navigationButton:update()
|
||||||
|
navigationButton:draw(index)
|
||||||
|
end
|
||||||
|
|
||||||
DoubleBuffer.drawChanges()
|
DoubleBuffer.drawChanges()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -94,6 +94,18 @@ local function draw(self, index)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function widget.clear()
|
||||||
|
DoubleBuffer.drawRectangle(
|
||||||
|
Constants.baseWidth,
|
||||||
|
Constants.baseHeight,
|
||||||
|
3 * Constants.baseWidth,
|
||||||
|
4 * Constants.baseHeight,
|
||||||
|
Colors.background,
|
||||||
|
Colors.background,
|
||||||
|
"█"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
local fake = {}
|
local fake = {}
|
||||||
|
|
||||||
fake.names = {
|
fake.names = {
|
||||||
@ -208,7 +220,7 @@ end
|
|||||||
function widget.fakeWidgets()
|
function widget.fakeWidgets()
|
||||||
local fakeWidgets = {}
|
local fakeWidgets = {}
|
||||||
|
|
||||||
for _ = 1, 9 do
|
for _ = 1, math.random(30) do
|
||||||
table.insert(fakeWidgets, fake.machineWidget.create())
|
table.insert(fakeWidgets, fake.machineWidget.create())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user