Skip to content
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

Introduce a new theme size name for rounded scrollbar corners #4839

Merged
merged 12 commits into from
Jun 22, 2024
4 changes: 2 additions & 2 deletions cmd/fyne_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ func makeNav(setTutorial func(tutorial tutorials.Tutorial), loadPrevious bool) f

themes := container.NewGridWithColumns(2,
widget.NewButton("Dark", func() {
a.Settings().SetTheme(&forcedVariant{Theme: theme.DefaultTheme(), variant: theme.VariantDark})
//a.Settings().SetTheme(&forcedVariant{Theme: theme.DefaultTheme(), variant: theme.VariantDark})
}),
widget.NewButton("Light", func() {
a.Settings().SetTheme(&forcedVariant{Theme: theme.DefaultTheme(), variant: theme.VariantLight})
//a.Settings().SetTheme(&forcedVariant{Theme: theme.DefaultTheme(), variant: theme.VariantLight})
}),
)

Expand Down
2 changes: 1 addition & 1 deletion container/testdata/doctabs/mobile/hover_none.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</widget>
<widget pos="0,30" size="110x6" type="*widget.scrollBarArea">
<widget pos="0,3" size="77x3" type="*widget.scrollBar">
<rectangle fillColor="scrollbar" size="77x3"/>
<rectangle fillColor="scrollbar" radius="3" size="77x3"/>
</widget>
</widget>
</widget>
Expand Down
2 changes: 2 additions & 0 deletions internal/widget/scroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (r *scrollBarRenderer) MinSize() fyne.Size {

func (r *scrollBarRenderer) Refresh() {
r.background.FillColor = theme.Color(theme.ColorNameScrollBar)
r.background.CornerRadius = theme.Size(theme.SizeNameScrollBarRadius)
r.background.Refresh()
}

Expand All @@ -68,6 +69,7 @@ type scrollBar struct {

func (b *scrollBar) CreateRenderer() fyne.WidgetRenderer {
background := canvas.NewRectangle(theme.Color(theme.ColorNameScrollBar))
background.CornerRadius = theme.Size(theme.SizeNameScrollBarRadius)
r := &scrollBarRenderer{
scrollBar: b,
background: background,
Expand Down
5 changes: 4 additions & 1 deletion test/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func NewTheme() fyne.Theme {
theme.SizeNameInputBorder: float32(5),
theme.SizeNameInputRadius: float32(2),
theme.SizeNameSelectionRadius: float32(6),
theme.SizeNameScrollBarRadius: float32(0),
},
}
}
Expand Down Expand Up @@ -140,6 +141,7 @@ func Theme() fyne.Theme {
theme.SizeNameInputBorder: float32(2),
theme.SizeNameInputRadius: float32(4),
theme.SizeNameSelectionRadius: float32(4),
theme.SizeNameScrollBarRadius: float32(0),
},
}
}
Expand Down Expand Up @@ -176,8 +178,9 @@ func (t *configurableTheme) Icon(n fyne.ThemeIconName) fyne.Resource {
}

func (t *configurableTheme) Size(s fyne.ThemeSizeName) float32 {
if t.sizes[s] == 0 {
if _, ok := t.sizes[s]; !ok {
fyne.LogError(fmt.Sprintf("size %s not defined in theme %s", s, t.name), nil)
return 0
}

return t.sizes[s]
Expand Down
12 changes: 12 additions & 0 deletions theme/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const (
//
// Since: 2.4
SizeNameSelectionRadius fyne.ThemeSizeName = "selectionRadius"

// SizeNameScrollBarRadius is the name of theme lookup for the scroll bar corner radius.
//
// Since: 2.5
SizeNameScrollBarRadius = "scrollBarRadius"
)

// CaptionTextSize returns the size for caption text.
Expand Down Expand Up @@ -134,6 +139,13 @@ func SelectionRadiusSize() float32 {
return Current().Size(SizeNameSelectionRadius)
}

// ScrollBarRadiusSize returns the scroll bar corner radius size.
//
// Since: 2.5
func ScrollBarRadiusSize() float32 {
dweymouth marked this conversation as resolved.
Show resolved Hide resolved
return Current().Size(SizeNameScrollBarRadius)
}

// SeparatorThicknessSize is the standard thickness of the separator widget.
//
// Since: 2.0
Expand Down
2 changes: 2 additions & 0 deletions theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ func (t *builtinTheme) Size(s fyne.ThemeSizeName) float32 {
return 5
case SizeNameSelectionRadius:
return 3
case SizeNameScrollBarRadius:
return 3
default:
return 0
}
Expand Down
Loading