1 Commits

Author SHA1 Message Date
ascpial
6fca8da1c1 Fix size attribute for flexbox children 2024-08-25 21:51:47 +02:00
7 changed files with 33 additions and 60 deletions

View File

@@ -78,7 +78,7 @@ local getObject = function(objectName)
return getObjects()[objectName]
end
local createObject = function(objectName, id)
local createObject = function(basalt, objectName, id)
return getObject(objectName)(id, basalt)
end
@@ -515,9 +515,6 @@ basalt = {
stop = stop,
stopUpdate = stop,
getTerm = function()
return baseTerm
end,
isKeyDown = function(key)
if(activeKey[key]==nil)then return false end

View File

@@ -419,7 +419,7 @@ return function(name, basalt)
for objectName, _ in pairs(basalt.getObjects()) do
container["add" .. objectName] = function(self, id)
return self:addChild(basalt.createObject(objectName, id))
return self:addChild(basalt:createObject(objectName, id))
end
end

View File

@@ -34,16 +34,20 @@ local function flexObjectPlugin(base, basalt)
return self
end,
getSize = function(self)
return baseWidth, baseHeight
getSize = function(self, internalCall)
if internalCall then
return baseWidth, baseHeight
else
return base:getSize()
end
end,
getWidth = function(self)
return baseWidth
getWidth = function(self, internalCall)
return internalCall and baseWidth or base:getWidth()
end,
getHeight = function(self)
return baseHeight
getHeight = function(self, internalCall)
return internalCall and baseHeight or base:getHeight()
end,
setSize = function(self, width, height, rel, internalCall)
@@ -91,7 +95,7 @@ return function(name, basalt)
for _,v in pairs(children)do
if(sortedChildren[index]==nil)then sortedChildren[index]={offset=1} end
local childHeight = direction == "row" and v:getHeight() or v:getWidth()
local childHeight = direction == "row" and v:getHeight(true) or v:getWidth(true)
if childHeight > lineSize then
lineSize = childHeight
end
@@ -123,19 +127,19 @@ return function(name, basalt)
index = index + 1
sortedChildren[index] = {offset=lineOffset}
else
local objSize = direction == "row" and v:getWidth() or v:getHeight()
local objSize = direction == "row" and v:getWidth(true) or v:getHeight(true)
if(objSize+usedSize<=maxSize) then
table.insert(sortedChildren[index], v)
usedSize = usedSize + objSize + spacing
else
lineOffset = lineOffset + lineSize + spacing
lineSize = direction == "row" and v:getHeight() or v:getWidth()
lineSize = direction == "row" and v:getHeight(true) or v:getWidth(true)
index = index + 1
usedSize = objSize + spacing
sortedChildren[index] = {offset=lineOffset, v}
end
local childHeight = direction == "row" and v:getHeight() or v:getWidth()
local childHeight = direction == "row" and v:getHeight(true) or v:getWidth(true)
if childHeight > lineSize then
lineSize = childHeight
end
@@ -178,7 +182,7 @@ return function(name, basalt)
end
child:setPosition(currentX, children.offset or 1)
child:setSize(childWidth, child:getHeight(), false, true)
child:setSize(childWidth, child:getHeight(true), false, true)
currentX = currentX + childWidth + spacing
end
end
@@ -255,7 +259,7 @@ return function(name, basalt)
local flexGrow = child:getFlexGrow()
local flexShrink = child:getFlexShrink()
local baseHeight = child:getFlexBasis() ~= 0 and child:getFlexBasis() or child:getHeight()
local baseHeight = child:getFlexBasis() ~= 0 and child:getFlexBasis() or child:getHeight(true)
if totalFlexGrow > 0 then
childHeight = baseHeight + flexGrow / totalFlexGrow * remainingSpace
else
@@ -306,7 +310,7 @@ return function(name, basalt)
local numSpaces = #children + 1
local totalChildHeight = 0
for _, child in ipairs(children) do
totalChildHeight = totalChildHeight + child:getHeight()
totalChildHeight = totalChildHeight + child:getHeight(true)
end
local totalSpace = containerHeight - totalChildHeight
local offset = math.floor(totalSpace / numSpaces)
@@ -316,7 +320,7 @@ return function(name, basalt)
for _, child in ipairs(children) do
local x, y = child:getPosition()
child:setPosition(x, currentY)
currentY = currentY + child:getHeight() + offset + (remaining > 0 and 1 or 0)
currentY = currentY + child:getHeight(true) + offset + (remaining > 0 and 1 or 0)
remaining = remaining > 0 and remaining - 1 or 0
end
end

View File

@@ -100,7 +100,7 @@ end
return {
basalt = function(basalt)
local function createObjectsFromXMLNode(node, env)
local createObjectsFromXMLNode = function(node, env)
local layout = env[node.tag]
if (layout ~= nil) then
local props = {}
@@ -109,20 +109,12 @@ return {
end
return basalt.createObjectsFromLayout(layout, props)
end
local objectName = node.tag:gsub("^%l", string.upper)
local object = basalt.createObject(objectName, node.attributes["id"])
local object = basalt:createObject(objectName, node.attributes["id"])
for attribute, expression in pairs(node.attributes) do
if (attribute:sub(1, 2) == "on") then
object[attribute](object, function(...)
local basaltCallback = basalt.getVariable(expression:gsub("\"", ""):gsub("\'", ""))
if(basaltCallback ~= nil) then
basaltCallback()
elseif(env[expression] ~= nil) then
env[expression]()
else
registerFunctionEvent(object, object[attribute], expression .. "()", env)
end
end)
registerFunctionEvent(object, object[attribute], expression .. "()", env)
else
local update = function()
local value = load("return " .. expression, nil, "t", env)()
@@ -132,7 +124,7 @@ return {
end
end
for _, child in ipairs(node.children) do
local childObjects = createObjectsFromXMLNode(child, env)
local childObjects = basalt.createObjectsFromXMLNode(child, env)
for _, childObject in ipairs(childObjects) do
object:addChild(childObject)
end
@@ -167,9 +159,6 @@ return {
end
setmetatable(env.props, {
__index = function(_, k)
if(updateFns[k] == nil) then
error("Property " .. k .. " not found")
end
return updateFns[k]()
end
})
@@ -207,24 +196,6 @@ return {
self:addChild(object)
end
return self
end,
loadLayoutFromString = function(self, xmlContent, props)
local wrappedProps = {}
if (props == nil) then
props = {}
end
for prop, value in pairs(props) do
wrappedProps[prop] = function()
return value
end
end
local layout = Layout.fromXML(xmlContent)
local objects = basalt.createObjectsFromLayout(layout, wrappedProps)
for _, object in ipairs(objects) do
self:addChild(object)
end
return self
end
}
return object

View File

@@ -88,7 +88,7 @@ plugin[v] = function(base, name, basalt)
if(base.init(self))then
local parent = self:getParent() or self
self:setBackground(parent:getTheme(v.."BG"))
self:setForeground(parent:getTheme(v.."Text"))
self:setForeground(parent:getTheme(v.."Text"))
end
end
}

1
docs/CNAME Normal file
View File

@@ -0,0 +1 @@
basalt.madefor.cc

View File

@@ -6,11 +6,11 @@ The Release version provides a specific, stable version of Basalt. Use this vers
To download the Release version, use the following command:
`wget run https://raw.githubusercontent.com/Pyroxenium/Basalt/refs/heads/master/docs/install.lua release [remote_filename] [local_filename]`
`wget run https://basalt.madefor.cc/install.lua release [remote_filename] [local_filename]`
In most cases, you'll likely want to use:
`wget run https://raw.githubusercontent.com/Pyroxenium/Basalt/refs/heads/master/docs/install.lua release latest.lua`
`wget run https://basalt.madefor.cc/install.lua release latest.lua`
- `remote_filename`: The file name of the Basalt release you want to download (e.g., basalt-1.6.6.lua, latest.lua).
- `local_filename` (optional): The file name for the Basalt installation on your local system (e.g., basalt.lua).
@@ -23,7 +23,7 @@ The Minified/Packed version is a compressed version of the Basalt code directly
To download the Minified/Packed version, use the following command:
`wget run https://raw.githubusercontent.com/Pyroxenium/Basalt/refs/heads/master/docs/install.lua packed [filename] [branch]`
`wget run https://basalt.madefor.cc/install.lua packed [filename] [branch]`
- `filename` (optional): The file name for the Basalt installation (default: `basalt.lua`).
- `branch` (optional): Choose between `master` and `dev` branches (default: `master`).
@@ -34,7 +34,7 @@ The Source version, as the name suggests, contains the unmodified source code of
To download the Source version, use the following command:
`wget run https://raw.githubusercontent.com/Pyroxenium/Basalt/refs/heads/master/docs/install.lua source [foldername] [branch]`
`wget run https://basalt.madefor.cc/install.lua source [foldername] [branch]`
- `foldername` (optional): The folder name for the Basalt installation (default: `basalt`).
- `branch` (optional): Choose between `master` and `dev` branches (default: `master`).
@@ -45,9 +45,9 @@ The Web version is designed for minimal project size and fetches the required co
To download the Web version, use the following command:
`wget run https://raw.githubusercontent.com/Pyroxenium/Basalt/refs/heads/master/docs/install.lua web [version] [filename]`
`wget run https://basalt.madefor.cc/install.lua web [version] [filename]`
- `version` (optional): Specify the desired version of Basalt (default: latest version). [Click here](https://github.com/Pyroxenium/Basalt/tree/master/docs/versions) to see the available versions.
- `filename` (optional): The file name for the Basalt installation (default: `basaltWeb.lua`).
**Note**: If using the Web version, remember to change `local basalt = require("basalt")` to `local basalt = require("basaltWeb")` in your code.
**Note**: If using the Web version, remember to change `local basalt = require("basalt")` to `local basalt = require("basaltWeb")` in your code.