feat: add min max boundary to width, hight resolver (#2002)

This commit is contained in:
Simon Hauser
2022-06-26 11:37:51 +02:00
committed by Simon Hauser
parent 25b1bc8f17
commit d1f3e12a35
3 changed files with 48 additions and 11 deletions

View File

@@ -127,9 +127,6 @@ end] = function(selector, val)
end
end
-- Tables TODO:
-- ... {70, max}
-- function:
-- Function must have same signature as get_window_layout
-- function(self, max_columns, max_lines): number
@@ -141,6 +138,26 @@ end] = function(_, val)
return val
end
_resolve_map[function(val)
return type(val) == "table" and val[1] >= 0 and val[1] < 1 and val["max"] ~= nil
end] =
function(selector, val)
return function(...)
local selected = select(selector, ...)
return math.min(math.floor(val[1] * selected), val["max"])
end
end
_resolve_map[function(val)
return type(val) == "table" and val[1] >= 0 and val[1] < 1 and val["min"] ~= nil
end] =
function(selector, val)
return function(...)
local selected = select(selector, ...)
return math.max(math.floor(val[1] * selected), val["min"])
end
end
-- Add padding option
_resolve_map[function(val)
return type(val) == "table" and val["padding"] ~= nil
@@ -162,7 +179,7 @@ end] = function(selector, val)
end
--- Converts input to a function that returns the height.
--- The input must take one of four forms:
--- The input must take one of five forms:
--- 1. 0 <= number < 1 <br>
--- This means total height as a percentage.
--- 2. 1 <= number <br>
@@ -170,7 +187,10 @@ end
--- 3. function <br>
--- Must have signature:
--- function(self, max_columns, max_lines): number
--- 4. table of the form: {padding = `foo`} <br>
--- 4. table of the form: { val, max = ..., min = ... } <br>
--- val has to be in the first form 0 <= val < 1 and only one is given,
--- `min` or `max` as fixed number
--- 5. table of the form: {padding = `foo`} <br>
--- where `foo` has one of the previous three forms. <br>
--- The height is then set to be the remaining space after padding.
--- For example, if the window has height 50, and the input is {padding = 5},
@@ -188,7 +208,7 @@ resolver.resolve_height = function(val)
end
--- Converts input to a function that returns the width.
--- The input must take one of four forms:
--- The input must take one of five forms:
--- 1. 0 <= number < 1 <br>
--- This means total width as a percentage.
--- 2. 1 <= number <br>
@@ -196,7 +216,10 @@ end
--- 3. function <br>
--- Must have signature:
--- function(self, max_columns, max_lines): number
--- 4. table of the form: {padding = `foo`} <br>
--- 4. table of the form: { val, max = ..., min = ... } <br>
--- val has to be in the first form 0 <= val < 1 and only one is given,
--- `min` or `max` as fixed number
--- 5. table of the form: {padding = `foo`} <br>
--- where `foo` has one of the previous three forms. <br>
--- The width is then set to be the remaining space after padding.
--- For example, if the window has width 100, and the input is {padding = 5},