Skip to content

Add rounded edges to Rectangle #3121

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

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
82a227c
Updates after changes in gl render pipeline
renlite Jul 3, 2022
afbd6d0
fix antialiazing at shapes without stroke
renlite Jul 4, 2022
c24f9a6
Merge branch 'fyne-io:develop' into develop
renlite Jul 4, 2022
5fc42ae
Merge branch 'master' of https://github.com/renlite/fyne into develop
renlite Jul 4, 2022
6358c21
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Jul 4, 2022
2f3f887
Add example to cmd/fyne_demo/tutorials/canvas.go
renlite Jul 8, 2022
fd8e257
Merge branch 'fyne-io:develop' into develop
renlite Jul 9, 2022
b53c3de
Merge branch 'fyne-io:develop' into develop
renlite Jul 15, 2022
bb1a3ea
split method flexRectCoords (lint) and use GL ES
renlite Jul 19, 2022
342d608
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Jul 19, 2022
04f2281
Merge branch 'fyne-io:develop' into develop
renlite Jul 19, 2022
cb5336e
Merge branch 'fyne-io:develop' into develop
renlite Jul 25, 2022
70e55be
append GL_ES for Rectangle in goxjs
renlite Jul 25, 2022
fd8736d
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Jul 25, 2022
18c9a48
Partial Fix of p.ctx.DrawArrays for GL ES
renlite Jul 31, 2022
8de346f
For testing in develop, delete later
renlite Jul 31, 2022
9dbf064
Merge branch 'fyne-io:develop' into develop
renlite Jul 31, 2022
6cc9193
fix WebGL(GL ES) VertexAttribArray Index problem
renlite Aug 6, 2022
80e9194
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Aug 6, 2022
1b69005
Merge branch 'fyne-io:develop' into develop
renlite Aug 6, 2022
0b86315
fix goimports issues
renlite Aug 6, 2022
d775197
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Aug 6, 2022
d050eda
Merge branch 'fyne-io:develop' into develop
renlite Aug 6, 2022
bf861d6
Merge branch 'fyne-io:develop' into develop
renlite Aug 15, 2022
3a85e81
Merge branch 'fyne-io:develop' into develop
renlite Aug 20, 2022
11600fa
remove debug(println) and fix gl_gomobile
renlite Aug 28, 2022
bd8bb29
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Aug 28, 2022
8cae924
Merge branch 'fyne-io:develop' into develop
renlite Aug 28, 2022
e2602e0
Try to fix flickering on some graphic cards
renlite Sep 2, 2022
8a00fc1
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Sep 2, 2022
fb2e9a0
Merge branch 'fyne-io:develop' into develop
renlite Sep 2, 2022
4247a52
Merge branch 'fyne-io:develop' into develop
renlite Sep 5, 2022
032a3a8
Change init color a=255.0 in rectangle.frag
renlite Sep 5, 2022
95d49f2
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Sep 5, 2022
3963857
Replace shaderSource maps with switch statements
renlite Sep 5, 2022
d28b35f
Activate DisableVertexAttribArray() in gl_core.go
renlite Sep 7, 2022
2c1de3f
Merge branch 'fyne-io:develop' into develop
renlite Sep 7, 2022
07ef589
Disabled unused rect functions in texture.go
renlite Sep 7, 2022
59475d1
Merge branch 'develop' of https://github.com/renlite/fyne into develop
renlite Sep 7, 2022
8f598d8
Delete unused functions in texture.go
renlite Sep 8, 2022
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
7 changes: 4 additions & 3 deletions canvas/rectangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ var _ fyne.CanvasObject = (*Rectangle)(nil)
type Rectangle struct {
baseObject

FillColor color.Color // The rectangle fill color
StrokeColor color.Color // The rectangle stroke color
StrokeWidth float32 // The stroke width of the rectangle
FillColor color.Color // The rectangle fill color
StrokeColor color.Color // The rectangle stroke color
StrokeWidth float32 // The stroke width of the rectangle
Radius fyne.RectangleRadius // The radius of the rectangle corners
}

// Refresh causes this object to be redrawn in it's current state
Expand Down
18 changes: 18 additions & 0 deletions canvas/rectangle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"image/color"
"testing"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"

"github.com/stretchr/testify/assert"
Expand All @@ -23,3 +24,20 @@ func TestRectangle_FillColor(t *testing.T) {

assert.Equal(t, c, rect.FillColor)
}

func TestRectangle_StrokeColor(t *testing.T) {
orange := color.NRGBA{R: 255, G: 120, B: 0, A: 255}
red := color.NRGBA{R: 255, G: 0, B: 0, A: 255}
rect := canvas.Rectangle{
FillColor: orange,
StrokeColor: red,
Radius: fyne.RectangleRadius{
Left: 30.0,
Right: 30.0,
},
}
rect.Resize((fyne.NewSize(300, 150)))

assert.Equal(t, red, rect.StrokeColor)
assert.Equal(t, float32(30.0), rect.Radius.Left)
}
16 changes: 16 additions & 0 deletions cmd/fyne_demo/tutorials/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,23 @@ func canvasScreen(_ fyne.Window) fyne.CanvasObject {
&canvas.Rectangle{FillColor: color.NRGBA{0x80, 0, 0, 0xff},
StrokeColor: color.NRGBA{0xff, 0xff, 0xff, 0xff},
StrokeWidth: 1},
&canvas.Rectangle{
FillColor: color.NRGBA{R: 255, G: 200, B: 0, A: 180},
StrokeColor: color.NRGBA{R: 255, G: 120, B: 0, A: 255},
StrokeWidth: 5,
Radius: fyne.RectangleRadius{Left: 20.0, LeftSegments: 16, Right: 20.0, RightSegments: 16},
},
&canvas.Rectangle{
FillColor: color.NRGBA{R: 150, G: 0, B: 205, A: 200},
Radius: fyne.RectangleRadius{Left: 45.0, Right: 45.0, RightSegments: 1},
},
&canvas.Line{StrokeColor: color.NRGBA{0, 0, 0x80, 0xff}, StrokeWidth: 5},
&canvas.Rectangle{
FillColor: color.NRGBA{R: 255, G: 120, B: 0, A: 255},
StrokeColor: color.NRGBA{R: 255, G: 200, B: 0, A: 180},
StrokeWidth: 2,
Radius: fyne.RectangleRadius{Right: 45.0, RightSegments: 24},
},
&canvas.Circle{StrokeColor: color.NRGBA{0, 0, 0x80, 0xff},
FillColor: color.NRGBA{0x30, 0x30, 0x30, 0x60},
StrokeWidth: 2},
Expand Down
9 changes: 9 additions & 0 deletions geometry.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ func (s Size) Subtract(v Vector2) Size {
func (s Size) SubtractWidthHeight(width, height float32) Size {
return Size{s.Width - width, s.Height - height}
}

// RectangleRadius describes a radius of the 4 corners as Size
// Max Size <= the smaller Rectangle Size
type RectangleRadius struct {
Left float32
LeftSegments int32
Right float32
RightSegments int32
}
1 change: 1 addition & 0 deletions internal/painter/gl/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type context interface {
DrawArrays(mode uint32, first, count int)
Enable(capability uint32)
EnableVertexAttribArray(attribute Attribute)
DisableVertexAttribArray(attribute Attribute)
GetAttribLocation(program Program, name string) Attribute
GetError() uint32
GetProgrami(program Program, param uint32) int
Expand Down
Loading