update to borders adding varying widths
This commit is contained in:
@@ -439,11 +439,22 @@ function Element.new(props)
|
||||
-- Check if any border side is truthy
|
||||
local hasAnyBorder = props.border.top or props.border.right or props.border.bottom or props.border.left
|
||||
if hasAnyBorder then
|
||||
-- Normalize border values: boolean true → 1, number → value, false/nil → false
|
||||
local function normalizeBorderValue(value)
|
||||
if value == true then
|
||||
return 1
|
||||
elseif type(value) == "number" then
|
||||
return value
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
self.border = {
|
||||
top = props.border.top or false,
|
||||
right = props.border.right or false,
|
||||
bottom = props.border.bottom or false,
|
||||
left = props.border.left or false,
|
||||
top = normalizeBorderValue(props.border.top),
|
||||
right = normalizeBorderValue(props.border.right),
|
||||
bottom = normalizeBorderValue(props.border.bottom),
|
||||
left = normalizeBorderValue(props.border.left),
|
||||
}
|
||||
else
|
||||
self.border = nil
|
||||
|
||||
@@ -342,33 +342,51 @@ function Renderer:_drawBorders(x, y, borderBoxWidth, borderBoxHeight)
|
||||
if type(self.border) == "number" then
|
||||
local borderColorWithOpacity = self._Color.new(self.borderColor.r, self.borderColor.g, self.borderColor.b, self.borderColor.a * self.opacity)
|
||||
love.graphics.setColor(borderColorWithOpacity:toRGBA())
|
||||
love.graphics.setLineWidth(self.border)
|
||||
self._RoundedRect.draw("line", x, y, borderBoxWidth, borderBoxHeight, self.cornerRadius)
|
||||
love.graphics.setLineWidth(1) -- Reset to default
|
||||
return
|
||||
end
|
||||
|
||||
local borderColorWithOpacity = self._Color.new(self.borderColor.r, self.borderColor.g, self.borderColor.b, self.borderColor.a * self.opacity)
|
||||
love.graphics.setColor(borderColorWithOpacity:toRGBA())
|
||||
|
||||
-- Check if all borders are enabled
|
||||
-- Check if all borders are enabled with same width
|
||||
local allBorders = self.border.top and self.border.bottom and self.border.left and self.border.right
|
||||
local uniformWidth = allBorders and
|
||||
type(self.border.top) == "number" and
|
||||
self.border.top == self.border.right and
|
||||
self.border.top == self.border.bottom and
|
||||
self.border.top == self.border.left
|
||||
|
||||
if allBorders then
|
||||
-- Draw complete rounded rectangle border
|
||||
if uniformWidth then
|
||||
-- Draw complete rounded rectangle border with uniform width
|
||||
love.graphics.setLineWidth(self.border.top)
|
||||
self._RoundedRect.draw("line", x, y, borderBoxWidth, borderBoxHeight, self.cornerRadius)
|
||||
love.graphics.setLineWidth(1) -- Reset to default
|
||||
else
|
||||
-- Draw individual borders (without rounded corners for partial borders)
|
||||
-- Draw individual borders with varying widths (without rounded corners for partial/varying borders)
|
||||
if self.border.top then
|
||||
local width = type(self.border.top) == "number" and self.border.top or 1
|
||||
love.graphics.setLineWidth(width)
|
||||
love.graphics.line(x, y, x + borderBoxWidth, y)
|
||||
end
|
||||
if self.border.bottom then
|
||||
local width = type(self.border.bottom) == "number" and self.border.bottom or 1
|
||||
love.graphics.setLineWidth(width)
|
||||
love.graphics.line(x, y + borderBoxHeight, x + borderBoxWidth, y + borderBoxHeight)
|
||||
end
|
||||
if self.border.left then
|
||||
local width = type(self.border.left) == "number" and self.border.left or 1
|
||||
love.graphics.setLineWidth(width)
|
||||
love.graphics.line(x, y, x, y + borderBoxHeight)
|
||||
end
|
||||
if self.border.right then
|
||||
local width = type(self.border.right) == "number" and self.border.right or 1
|
||||
love.graphics.setLineWidth(width)
|
||||
love.graphics.line(x + borderBoxWidth, y, x + borderBoxWidth, y + borderBoxHeight)
|
||||
end
|
||||
love.graphics.setLineWidth(1) -- Reset to default
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -142,10 +142,10 @@ local AnimationProps = {}
|
||||
local ElementProps = {}
|
||||
|
||||
---@class Border
|
||||
---@field top boolean
|
||||
---@field right boolean
|
||||
---@field bottom boolean
|
||||
---@field left boolean
|
||||
---@field top boolean|number -- true sets width to 1px, number sets width to specified pixels (default: 0)
|
||||
---@field right boolean|number -- true sets width to 1px, number sets width to specified pixels (default: 0)
|
||||
---@field bottom boolean|number -- true sets width to 1px, number sets width to specified pixels (default: 0)
|
||||
---@field left boolean|number -- true sets width to 1px, number sets width to specified pixels (default: 0)
|
||||
local Border = {}
|
||||
|
||||
---@class TransformProps
|
||||
|
||||
Reference in New Issue
Block a user