ok
This commit is contained in:
66
tmp/test.lua
Normal file
66
tmp/test.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
local kiwi = require("kiwi")
|
||||
|
||||
local Var = kiwi.Var
|
||||
local Strength = kiwi.Strength
|
||||
|
||||
local Button_mt = {}
|
||||
|
||||
---@class Button
|
||||
---@field left kiwi.Var
|
||||
---@field width kiwi.Var
|
||||
---@overload fun(identifier: string): Button
|
||||
local Button = setmetatable({}, Button_mt)
|
||||
|
||||
function Button_mt.__call(_, identifier)
|
||||
return setmetatable({
|
||||
left = Var("left" .. identifier),
|
||||
width = Var("width" .. identifier),
|
||||
}, {
|
||||
__index = Button,
|
||||
__tostring = function(self)
|
||||
return "Button(" .. self.left:value() .. ", " .. self.width:value() .. ")"
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local b1 = Button("b1")
|
||||
local b2 = Button("b2")
|
||||
|
||||
local left_limit = kiwi.Var("left")
|
||||
local right_limit = kiwi.Var("width")
|
||||
|
||||
|
||||
-- stylua: ignore start
|
||||
local constraints = {
|
||||
left_limit :eq( 0 ),
|
||||
b1.width :eq( b2.width ),
|
||||
b1.left :eq( left_limit + 50),
|
||||
right_limit:eq( b2.left + b2.width + 50),
|
||||
b2.left :ge( b1.left + b1.width + 100),
|
||||
|
||||
b1.width :ge( 87 ),
|
||||
b1.width :eq( 87, Strength.STRONG),
|
||||
|
||||
b2.width :ge( 113 ),
|
||||
b2.width :eq( 113, Strength.STRONG),
|
||||
}
|
||||
-- stylua: ignore end
|
||||
|
||||
local s = kiwi.Solver()
|
||||
|
||||
for _, c in ipairs(constraints) do
|
||||
s:add_constraint(c)
|
||||
end
|
||||
|
||||
print(constraints[4]:expression())
|
||||
print(constraints[5]:expression())
|
||||
|
||||
kiwi.Constraint(b1.left + 1, "EQ")
|
||||
|
||||
s:update_vars()
|
||||
|
||||
print(b1)
|
||||
print(b2)
|
||||
print(left_limit:value())
|
||||
print(right_limit:value())
|
||||
print(s:dumps())
|
||||
Reference in New Issue
Block a user