mirror of
https://github.com/AR2000AR/openComputers_codes.git
synced 2025-09-09 07:01:14 +02:00
[yawl] add Border widget
it's basically a fat Linked Widget
This commit is contained in:
@@ -363,7 +363,7 @@
|
||||
["yawl"] = {
|
||||
["manifestVersion"] = "1.0",
|
||||
["package"] = "yawl",
|
||||
["version"] = "1.2.0",
|
||||
["version"] = "1.3.0",
|
||||
["name"] = "Yet Another Widget Library",
|
||||
["repo"] = "tree/master/yawl",
|
||||
["description"] = "New version of libgui, but using libclass2 and cleaner code and interface.",
|
||||
@@ -376,7 +376,7 @@
|
||||
["yawl_example"] = {
|
||||
["manifestVersion"] = "1.0",
|
||||
["package"] = "yawl_example",
|
||||
["version"] = "1.3.0",
|
||||
["version"] = "1.4.0",
|
||||
["name"] = "Yet Another Widget Library Example file",
|
||||
["repo"] = "tree/master/yawl",
|
||||
["description"] = "New version of libgui, but using libclass2 and cleaner code and interface.",
|
||||
|
Binary file not shown.
Binary file not shown.
@@ -375,7 +375,7 @@
|
||||
dependencies = {
|
||||
["libclass2"] = "/"
|
||||
},
|
||||
version = "1.2.0",
|
||||
version = "1.3.0",
|
||||
name = "Yet Another Widget Library",
|
||||
description = "New version of libgui, but using libclass2 and cleaner code and interface.";
|
||||
authors = "AR2000AR",
|
||||
@@ -388,7 +388,7 @@
|
||||
dependencies = {
|
||||
["yawl"] = "/"
|
||||
},
|
||||
version = "1.3.0",
|
||||
version = "1.4.0",
|
||||
name = "Yet Another Widget Library Example file",
|
||||
description = "New version of libgui, but using libclass2 and cleaner code and interface.";
|
||||
note = "This is only a example file",
|
||||
|
@@ -68,8 +68,13 @@ for i = 1, 5 do
|
||||
t:backgroundColor(bk)
|
||||
end
|
||||
|
||||
local b = yawl.widget.Border(root, 52, 2)
|
||||
local bText = yawl.widget.Text(b, 1, 1, "Bordered text", 0xffffff)
|
||||
bText:backgroundColor(0)
|
||||
b:backgroundColor(0xff0000)
|
||||
|
||||
local function animate() --animate the text widget. Add one char with each loop
|
||||
MSG = "123456789 123456789 123456789 123456789 abcdefghijklmnopqrstuvwxyz "
|
||||
local MSG = "123456789 123456789 123456789 123456789 abcdefghijklmnopqrstuvwxyz "
|
||||
root:draw()
|
||||
text:text(MSG:sub(1, #(text:text()) + 1))
|
||||
if (#(text:text()) == #MSG) then
|
||||
@@ -90,7 +95,6 @@ require("event").listen("interrupted", function()
|
||||
return false
|
||||
end)
|
||||
root:draw()
|
||||
---img:visible(false)
|
||||
while run do
|
||||
os.sleep(0.1)
|
||||
root:draw()
|
||||
|
65
yawl/lib/yawl/widget/Border.lua
Normal file
65
yawl/lib/yawl/widget/Border.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
local class = require("libClass2")
|
||||
local Frame = require("yawl.widget.Frame")
|
||||
|
||||
---@class Border:Frame
|
||||
---@field parent Frame
|
||||
---@operator call:Border
|
||||
---@overload fun(parent:Frame,x:number,y:number)
|
||||
local Border = class(Frame)
|
||||
|
||||
---Comment
|
||||
---@return Border
|
||||
---@param parent Frame
|
||||
---@param x number
|
||||
---@param y number
|
||||
function Border:new(parent, x, y)
|
||||
checkArg(1, parent, "table")
|
||||
local o = self.parent(parent, x, y)
|
||||
setmetatable(o, {__index = self})
|
||||
---@cast o Border
|
||||
return o
|
||||
end
|
||||
|
||||
---@return Widget
|
||||
function Border:master()
|
||||
return self._childs[1]
|
||||
end
|
||||
|
||||
---@param value? number
|
||||
---@return number
|
||||
function Border:width(value)
|
||||
checkArg(1, value, 'number', 'nil')
|
||||
local oldValue = self:master():width(value) + 2
|
||||
if (value ~= nil) then
|
||||
for _, w in pairs(self._childs) do
|
||||
w:width(math.min(1, self:master():width() - 2))
|
||||
end
|
||||
end
|
||||
return oldValue
|
||||
end
|
||||
|
||||
---@param value? number
|
||||
---@return number
|
||||
function Border:height(value)
|
||||
checkArg(1, value, 'number', 'nil')
|
||||
local oldValue = self:master():height(value) + 2
|
||||
if (value ~= nil) then
|
||||
for _, w in pairs(self._childs) do
|
||||
w:height(math.min(1, self:master():height() - 2))
|
||||
end
|
||||
end
|
||||
return oldValue
|
||||
end
|
||||
|
||||
function Border:draw()
|
||||
if (not self:visible()) then return end
|
||||
for _, w in pairs(self._childs) do
|
||||
if (w ~= self:master()) then
|
||||
w:size(self:master():size())
|
||||
end
|
||||
w:position(2, 2)
|
||||
end
|
||||
self.parent.draw(self)
|
||||
end
|
||||
|
||||
return Border
|
@@ -54,7 +54,9 @@ end
|
||||
function LinkedWidget:draw()
|
||||
if (not self:visible()) then return end
|
||||
for _, w in pairs(self._childs) do
|
||||
if (w ~= self:master()) then
|
||||
w:size(self:master():size())
|
||||
end
|
||||
w:position(1, 1)
|
||||
end
|
||||
self.parent.draw(self)
|
||||
|
@@ -8,6 +8,7 @@ local Frame = require("yawl.widget.Frame")
|
||||
local WidgetList = require('libClass2')(Frame)
|
||||
|
||||
function WidgetList:draw()
|
||||
if (self:visible() == false) then return end
|
||||
local y = 1
|
||||
for _, w in ipairs(self._childs) do
|
||||
if (y > self:height()) then
|
||||
|
@@ -6,7 +6,8 @@ local yaowbglWidget = {
|
||||
Image = require("yawl.widget.Image"),
|
||||
TextInput = require("yawl.widget.TextInput"),
|
||||
LinkedWidget = require("yawl.widget.LinkedWidget"),
|
||||
WidgetList = require("yawl.widget.WidgetList")
|
||||
WidgetList = require("yawl.widget.WidgetList"),
|
||||
Border = require("yawl.widget.Border")
|
||||
}
|
||||
|
||||
return yaowbglWidget
|
||||
|
Reference in New Issue
Block a user