Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions lib/gears/shape.lua
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,65 @@ function module.partially_rounded_rect(cr, width, height, tl, tr, br, bl, rad)
cr:close_path()
end

--- A rounded rect with individually defined corner radii.
--
-- @DOC_gears_shape_individually_rounded_rect_EXAMPLE@
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems example is not being imported correctly: https://app.codecov.io/github/awesomeWM/awesome/commit/007e444a525ff9a90b015341a9ea0fe216ae5dd4

can you see it in generated docs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had the same feeling. #4043 should fix the coverage!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @Aire-One ! now the coverage report shows it correctly which more tests @aidinio would need to add

--
-- @param cr A cairo context
-- @tparam number width The shape width
-- @tparam number height The shape height
-- @tparam number tl The top left corner's radius
-- @tparam number tr The top right corner's radius
-- @tparam number br The bottom right corner's radius
-- @tparam number bl The bottom left corner's radius
-- @noreturn
-- @staticfct gears.shape.individually_rounded_rect
function module.individually_rounded_rect(cr, width, height, tl, tr, br, bl)
local corners = {tl = tl, tr = tr, br = br, bl = bl}
for key, val in pairs(corners) do
if width / 2 < val then
corners[key] = width / 2
end
if height / 2 < val then
corners[key] = height / 2
end
end

-- In case there is already some other path on the cairo context:
-- Make sure the close_path() below goes to the right position.
cr:new_sub_path()

-- Top left
if tl then
cr:arc( corners.tl, corners.tl, corners.tl, math.pi, 3*(math.pi/2))
else
cr:move_to(0,0)
end

-- Top right
if tr then
cr:arc( width-corners.tr, corners.tr, corners.tr, 3*(math.pi/2), math.pi*2)
else
cr:line_to(width, 0)
end

-- Bottom right
if br then
cr:arc( width-corners.br, height-corners.br, corners.br, math.pi*2 , math.pi/2)
else
cr:line_to(width, height)
end

-- Bottom left
if bl then
cr:arc( corners.bl, height-corners.bl, corners.bl, math.pi/2, math.pi)
else
cr:line_to(0, height)
end

cr:close_path()
end

--- A rounded rectangle with a triangle at the top.
--
-- @DOC_gears_shape_infobubble_EXAMPLE@
Expand Down
13 changes: 13 additions & 0 deletions tests/examples/gears/shape/individually_rounded_rect.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--DOC_GEN_IMAGE --DOC_HIDE
local shape,cr,show = ... --DOC_HIDE

shape.individually_rounded_rect(cr, 70, 70, 0, 10, 20, 30)
show(cr) --DOC_HIDE

shape.individually_rounded_rect(cr, 70, 70, 10, 0, 35, 5)
show(cr) --DOC_HIDE

shape.individually_rounded_rect(cr, 70, 70, 30, 20, 10, 1)
show(cr) --DOC_HIDE

--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
Loading