diff options
Diffstat (limited to 'lua-bindings/diaphragm.lua')
-rw-r--r-- | lua-bindings/diaphragm.lua | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/lua-bindings/diaphragm.lua b/lua-bindings/diaphragm.lua index ad8aac6..57f065f 100644 --- a/lua-bindings/diaphragm.lua +++ b/lua-bindings/diaphragm.lua | |||
@@ -173,19 +173,9 @@ function M.rectangle.new(params) | |||
173 | end | 173 | end |
174 | 174 | ||
175 | function M.rectangle.surrounding(content, params) | 175 | function M.rectangle.surrounding(content, params) |
176 | params = params or {} | 176 | local result = M.rectangle.new(params) |
177 | local margin = params.margin or 0 | 177 | M.constraint.inset(content, result, params) |
178 | local margin_left = params.margin_left or margin | 178 | return result |
179 | local margin_right = params.margin_right or margin | ||
180 | local margin_top = params.margin_top or margin | ||
181 | local margin_bottom = params.margin_bottom or margin | ||
182 | |||
183 | return M.rectangle.new(M.util.tbl_extend({ | ||
184 | left = content.left - margin_left, | ||
185 | right = content.right + margin_right, | ||
186 | top = content.top - margin_top, | ||
187 | bottom = content.bottom + margin_bottom, | ||
188 | }, params)) | ||
189 | end | 179 | end |
190 | 180 | ||
191 | M.straight_path = {} | 181 | M.straight_path = {} |
@@ -270,6 +260,8 @@ end | |||
270 | 260 | ||
271 | -- TODO: factor with vstack | 261 | -- TODO: factor with vstack |
272 | -- TODO: also as just a set of constraints | 262 | -- TODO: also as just a set of constraints |
263 | -- TODO: add support for "growing" element height (or elements have same size) | ||
264 | -- TODO: add orientation (ltr or rtl) | ||
273 | function M.layout.hstack(params) | 265 | function M.layout.hstack(params) |
274 | local result = M.shape(params) | 266 | local result = M.shape(params) |
275 | 267 | ||
@@ -398,6 +390,21 @@ function M.constraint.same_width(elems) | |||
398 | end | 390 | end |
399 | end | 391 | end |
400 | 392 | ||
393 | -- TODO: factor with rectangle surrounding | ||
394 | function M.constraint.inset(child, parent, params) | ||
395 | params = params or {} | ||
396 | local margin = params.margin or 0 | ||
397 | local margin_left = params.margin_left or margin | ||
398 | local margin_right = params.margin_right or margin | ||
399 | local margin_top = params.margin_top or margin | ||
400 | local margin_bottom = params.margin_bottom or margin | ||
401 | |||
402 | M.constrain(parent.left:eq(child.left - margin_left)) | ||
403 | M.constrain(parent.right:eq(child.right + margin_right)) | ||
404 | M.constrain(parent.top:eq(child.top - margin_top)) | ||
405 | M.constrain(parent.bottom:eq(child.bottom + margin_bottom)) | ||
406 | end | ||
407 | |||
401 | M.constrain = M.core.constrain | 408 | M.constrain = M.core.constrain |
402 | M.draw = function(params) | 409 | M.draw = function(params) |
403 | M.core.draw(M.util.tbl_extend(params, { | 410 | M.core.draw(M.util.tbl_extend(params, { |