mirror of
https://gitlab.com/luk3yx/minetest-flow.git
synced 2025-07-18 06:29:00 +02:00
Add visible = false (may be renamed in the future)
This commit is contained in:
parent
bb102c360f
commit
299ccfcddc
24
init.lua
24
init.lua
@ -384,9 +384,19 @@ local function expand(box)
|
||||
end
|
||||
end
|
||||
|
||||
-- Recursively expand
|
||||
for _, node in ipairs(box) do
|
||||
expand(node)
|
||||
-- Recursively expand and remove any invisible nodes
|
||||
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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1004,10 +1014,16 @@ end
|
||||
|
||||
function gui.Spacer(def)
|
||||
def.type = "container"
|
||||
assert(#def == 0)
|
||||
|
||||
-- Spacers default to expanding
|
||||
if def.expand == nil then
|
||||
def.expand = true
|
||||
end
|
||||
assert(#def == 0)
|
||||
|
||||
-- Prevent an empty container from being added to the resulting form
|
||||
def.visible = false
|
||||
|
||||
return def
|
||||
end
|
||||
|
||||
|
58
test.lua
58
test.lua
@ -170,4 +170,62 @@ describe("Flow", function()
|
||||
|
||||
assert.same(state.callbacks, {btn = func})
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user