-
Notifications
You must be signed in to change notification settings - Fork 624
Add a rect shape with corners having different radii #3991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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@ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I had the same feeling. #4043 should fix the coverage!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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@ | ||
|
|
||
| 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 |
Uh oh!
There was an error while loading. Please reload this page.