mirror of
https://gitlab.com/luk3yx/minetest-flow.git
synced 2025-08-09 01:05:53 +02:00
Add visible = false (may be renamed in the future)
This commit is contained in:
parent
bb102c360f
commit
299ccfcddc
22
init.lua
22
init.lua
@ -384,11 +384,21 @@ local function expand(box)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Recursively expand
|
-- Recursively expand and remove any invisible nodes
|
||||||
for _, node in ipairs(box) do
|
for i = #box, 1, -1 do
|
||||||
|
local node = box[i]
|
||||||
|
-- node.visible ~= nil and not node.visible
|
||||||
|
-- WARNING: I'm not sure whether this should be called `visible`, I may
|
||||||
|
-- end up renaming it in the future. Use with caution.
|
||||||
|
if node.visible == false then
|
||||||
|
-- There's no need to try and expand anything inside invisible
|
||||||
|
-- nodes since it won't affect the overall size.
|
||||||
|
table.remove(box, i)
|
||||||
|
else
|
||||||
expand(node)
|
expand(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Renders the GUI into hopefully valid AST
|
-- Renders the GUI into hopefully valid AST
|
||||||
-- This won't fill in names
|
-- This won't fill in names
|
||||||
@ -1004,10 +1014,16 @@ end
|
|||||||
|
|
||||||
function gui.Spacer(def)
|
function gui.Spacer(def)
|
||||||
def.type = "container"
|
def.type = "container"
|
||||||
|
assert(#def == 0)
|
||||||
|
|
||||||
|
-- Spacers default to expanding
|
||||||
if def.expand == nil then
|
if def.expand == nil then
|
||||||
def.expand = true
|
def.expand = true
|
||||||
end
|
end
|
||||||
assert(#def == 0)
|
|
||||||
|
-- Prevent an empty container from being added to the resulting form
|
||||||
|
def.visible = false
|
||||||
|
|
||||||
return def
|
return def
|
||||||
end
|
end
|
||||||
|
|
||||||
|
58
test.lua
58
test.lua
@ -170,4 +170,62 @@ describe("Flow", function()
|
|||||||
|
|
||||||
assert.same(state.callbacks, {btn = func})
|
assert.same(state.callbacks, {btn = func})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("handles visible = false", function()
|
||||||
|
test_render(gui.VBox{
|
||||||
|
min_w = 10, min_h = 10,
|
||||||
|
|
||||||
|
gui.HBox{
|
||||||
|
spacing = 0.5,
|
||||||
|
gui.Box{w = 1, h = 1, color = "red"},
|
||||||
|
gui.Box{w = 1, h = 1, color = "green", visible = false},
|
||||||
|
gui.Box{w = 1, h = 1, color = "blue"},
|
||||||
|
},
|
||||||
|
|
||||||
|
gui.HBox{
|
||||||
|
gui.Box{w = 1, h = 1, color = "red"},
|
||||||
|
gui.Box{w = 1, h = 1, color = "green", visible = false,
|
||||||
|
expand = true},
|
||||||
|
gui.Box{w = 1, h = 1, color = "blue"},
|
||||||
|
},
|
||||||
|
|
||||||
|
gui.HBox{
|
||||||
|
gui.Box{w = 1, h = 1, color = "grey"},
|
||||||
|
gui.Spacer{},
|
||||||
|
gui.Box{w = 1, h = 1, color = "grey"},
|
||||||
|
},
|
||||||
|
|
||||||
|
gui.HBox{
|
||||||
|
gui.Box{w = 1, h = 1, color = "red", expand = true},
|
||||||
|
gui.Box{w = 1, h = 1, color = "green", visible = false},
|
||||||
|
gui.Box{w = 1, h = 1, color = "blue"},
|
||||||
|
},
|
||||||
|
|
||||||
|
gui.Box{w = 1, h = 1, expand = true},
|
||||||
|
}, [[
|
||||||
|
size[10.6,10.6]
|
||||||
|
|
||||||
|
container[0.3,0.3]
|
||||||
|
box[0,0;1,1;red]
|
||||||
|
box[3,0;1,1;blue]
|
||||||
|
container_end[]
|
||||||
|
|
||||||
|
container[0.3,1.5]
|
||||||
|
box[0,0;1,1;red]
|
||||||
|
box[9,0;1,1;blue]
|
||||||
|
container_end[]
|
||||||
|
|
||||||
|
container[0.3,2.7]
|
||||||
|
box[0,0;1,1;grey]
|
||||||
|
box[9,0;1,1;grey]
|
||||||
|
container_end[]
|
||||||
|
|
||||||
|
container[0.3,3.9]
|
||||||
|
box[0,0;7.6,1;red]
|
||||||
|
box[9,0;1,1;blue]
|
||||||
|
container_end[]
|
||||||
|
|
||||||
|
box[0.3,5.1;10,5.2;]
|
||||||
|
]])
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user