Skip to content
Draft
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
11 changes: 4 additions & 7 deletions container/apptabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ func NewAppTabs(items ...*TabItem) *AppTabs {
// Implements: fyne.Widget
func (t *AppTabs) CreateRenderer() fyne.WidgetRenderer {
t.BaseWidget.ExtendBaseWidget(t)
th := t.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

r := &appTabsRenderer{
baseTabsRenderer: baseTabsRenderer{
bar: &fyne.Container{},
divider: canvas.NewRectangle(th.Color(theme.ColorNameShadow, v)),
indicator: canvas.NewRectangle(th.Color(theme.ColorNamePrimary, v)),
divider: canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameShadow, t)),
indicator: canvas.NewRectangle(theme.ColorForWidget(theme.ColorNamePrimary, t)),
},
appTabs: t,
}
Expand Down Expand Up @@ -422,8 +420,7 @@ func (r *appTabsRenderer) updateIndicator(animate bool) {

var indicatorPos fyne.Position
var indicatorSize fyne.Size
th := r.appTabs.Theme()
pad := th.Size(theme.SizeNamePadding)
pad := theme.SizeForWidget(theme.SizeNamePadding, r.appTabs)

switch r.appTabs.location {
case TabLocationTop:
Expand All @@ -440,7 +437,7 @@ func (r *appTabsRenderer) updateIndicator(animate bool) {
indicatorSize = fyne.NewSize(pad, selectedSize.Height)
}

r.moveIndicator(indicatorPos, indicatorSize, th, animate)
r.moveIndicator(indicatorPos, indicatorSize, r.appTabs.Theme(), animate)
}

func (r *appTabsRenderer) updateTabs(max int) {
Expand Down
13 changes: 5 additions & 8 deletions container/doctabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ func (t *DocTabs) Append(item *TabItem) {
// Implements: fyne.Widget
func (t *DocTabs) CreateRenderer() fyne.WidgetRenderer {
t.ExtendBaseWidget(t)
th := t.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

r := &docTabsRenderer{
baseTabsRenderer: baseTabsRenderer{
bar: &fyne.Container{},
divider: canvas.NewRectangle(th.Color(theme.ColorNameShadow, v)),
indicator: canvas.NewRectangle(th.Color(theme.ColorNamePrimary, v)),
divider: canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameShadow, t)),
indicator: canvas.NewRectangle(theme.ColorForWidget(theme.ColorNamePrimary, t)),
},
docTabs: t,
scroller: NewScroll(&fyne.Container{}),
Expand Down Expand Up @@ -387,10 +385,9 @@ func (r *docTabsRenderer) scrollToSelected() {
}

func (r *docTabsRenderer) updateIndicator(animate bool) {
th := r.docTabs.Theme()
if r.docTabs.current < 0 {
r.indicator.FillColor = color.Transparent
r.moveIndicator(fyne.NewPos(0, 0), fyne.NewSize(0, 0), th, animate)
r.moveIndicator(fyne.NewPos(0, 0), fyne.NewSize(0, 0), r.docTabs.Theme(), animate)
return
}

Expand Down Expand Up @@ -423,7 +420,7 @@ func (r *docTabsRenderer) updateIndicator(animate bool) {

var indicatorPos fyne.Position
var indicatorSize fyne.Size
pad := th.Size(theme.SizeNamePadding)
pad := theme.SizeForWidget(theme.SizeNamePadding, r.docTabs)

switch r.docTabs.location {
case TabLocationTop:
Expand Down Expand Up @@ -454,7 +451,7 @@ func (r *docTabsRenderer) updateIndicator(animate bool) {
return
}

r.moveIndicator(indicatorPos, indicatorSize, th, animate)
r.moveIndicator(indicatorPos, indicatorSize, r.docTabs.Theme(), animate)
}

func (r *docTabsRenderer) updateAllTabs() {
Expand Down
12 changes: 5 additions & 7 deletions container/innerwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (w *InnerWindow) Close() {
func (w *InnerWindow) CreateRenderer() fyne.WidgetRenderer {
w.ExtendBaseWidget(w)
th := w.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

min := newBorderButton(theme.WindowMinimizeIcon(), modeMinimize, th, w.OnMinimized)
if w.OnMinimized == nil {
Expand Down Expand Up @@ -99,15 +98,15 @@ func (w *InnerWindow) CreateRenderer() fyne.WidgetRenderer {
title := newDraggableLabel(w.title, w)
title.Truncation = fyne.TextTruncateEllipsis

height := w.Theme().Size(theme.SizeNameWindowTitleBarHeight)
height := theme.SizeForWidget(theme.SizeNameWindowTitleBarHeight, w)
off := (height - title.labelMinSize().Height) / 2
barMid := New(layout.NewCustomPaddedLayout(off, 0, 0, 0), title)
if w.buttonPosition() == widget.ButtonAlignTrailing {
buttons = NewCenter(NewHBox(min, max, close))
}

bg := canvas.NewRectangle(th.Color(theme.ColorNameOverlayBackground, v))
contentBG := canvas.NewRectangle(th.Color(theme.ColorNameBackground, v))
bg := canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameOverlayBackground, w))
contentBG := canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameBackground, w))
corner := newDraggableCorner(w)
bar := New(&titleBarLayout{buttons: buttons, icon: borderIcon, title: barMid, win: w},
buttons, borderIcon, barMid)
Expand Down Expand Up @@ -214,10 +213,9 @@ func (i *innerWindowRenderer) MinSize() fyne.Size {

func (i *innerWindowRenderer) Refresh() {
th := i.win.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()
i.bg.FillColor = th.Color(theme.ColorNameOverlayBackground, v)
i.bg.FillColor = theme.ColorForWidget(theme.ColorNameOverlayBackground, i.win)
i.bg.Refresh()
i.contentBG.FillColor = th.Color(theme.ColorNameBackground, v)
i.contentBG.FillColor = theme.ColorForWidget(theme.ColorNameBackground, i.win)
i.contentBG.Refresh()

if i.win.buttonPosition() == widget.ButtonAlignTrailing {
Expand Down
35 changes: 9 additions & 26 deletions container/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,9 @@ func newDivider(split *Split) *divider {
// CreateRenderer is a private method to Fyne which links this widget to its renderer
func (d *divider) CreateRenderer() fyne.WidgetRenderer {
d.ExtendBaseWidget(d)
th := d.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

background := canvas.NewRectangle(th.Color(theme.ColorNameShadow, v))
foreground := canvas.NewRectangle(th.Color(theme.ColorNameForeground, v))
background := canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameShadow, d))
foreground := canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameForeground, d))
return &dividerRenderer{
divider: d,
background: background,
Expand Down Expand Up @@ -362,44 +360,29 @@ func (r *dividerRenderer) Objects() []fyne.CanvasObject {
}

func (r *dividerRenderer) Refresh() {
th := r.divider.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

if r.divider.hovered {
r.background.FillColor = th.Color(theme.ColorNameHover, v)
r.background.FillColor = theme.ColorForWidget(theme.ColorNameHover, r.divider)
} else {
r.background.FillColor = th.Color(theme.ColorNameShadow, v)
r.background.FillColor = theme.ColorForWidget(theme.ColorNameShadow, r.divider)
}
r.background.Refresh()
r.foreground.FillColor = th.Color(theme.ColorNameForeground, v)
r.foreground.FillColor = theme.ColorForWidget(theme.ColorNameForeground, r.divider)
r.foreground.Refresh()
r.Layout(r.divider.Size())
}

func dividerTheme(d *divider) fyne.Theme {
if d == nil {
return theme.Current()
}

return d.Theme()
}

func dividerThickness(d *divider) float32 {
th := dividerTheme(d)
return th.Size(theme.SizeNamePadding) * 2
return theme.SizeForWidget(theme.SizeNamePadding, d) * 2
}

func dividerLength(d *divider) float32 {
th := dividerTheme(d)
return th.Size(theme.SizeNamePadding) * 6
return theme.SizeForWidget(theme.SizeNamePadding, d) * 6
}

func handleThickness(d *divider) float32 {
th := dividerTheme(d)
return th.Size(theme.SizeNamePadding) / 2
return theme.SizeForWidget(theme.SizeNamePadding, d) / 2
}

func handleLength(d *divider) float32 {
th := dividerTheme(d)
return th.Size(theme.SizeNamePadding) * 4
return theme.SizeForWidget(theme.SizeNamePadding, d) * 4
}
50 changes: 19 additions & 31 deletions container/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,18 +524,16 @@ type tabButton struct {

func (b *tabButton) CreateRenderer() fyne.WidgetRenderer {
b.ExtendBaseWidget(b)
th := b.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

background := canvas.NewRectangle(th.Color(theme.ColorNameHover, v))
background.CornerRadius = th.Size(theme.SizeNameSelectionRadius)
background := canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameHover, b))
background.CornerRadius = theme.SizeForWidget(theme.SizeNameSelectionRadius, b)
background.Hide()
icon := canvas.NewImageFromResource(b.icon)
if b.icon == nil {
icon.Hide()
}

label := canvas.NewText(b.text, th.Color(theme.ColorNameForeground, v))
label := canvas.NewText(b.text, theme.ColorForWidget(theme.ColorNameForeground, b))
label.TextStyle.Bold = true

close := &tabCloseButton{
Expand Down Expand Up @@ -599,8 +597,7 @@ func (r *tabButtonRenderer) Destroy() {
}

func (r *tabButtonRenderer) Layout(size fyne.Size) {
th := r.button.Theme()
pad := th.Size(theme.SizeNamePadding)
pad := theme.SizeForWidget(theme.SizeNamePadding, r.button)
r.background.Resize(size)
padding := r.padding()
innerSize := size.Subtract(padding)
Expand Down Expand Up @@ -631,17 +628,16 @@ func (r *tabButtonRenderer) Layout(size fyne.Size) {
r.label.Resize(labelSize)
r.label.Move(innerOffset.Add(labelOffset))
}
inlineIconSize := th.Size(theme.SizeNameInlineIcon)
inlineIconSize := theme.SizeForWidget(theme.SizeNameInlineIcon, r.button)
r.close.Move(fyne.NewPos(size.Width-inlineIconSize-pad, (size.Height-inlineIconSize)/2))
r.close.Resize(fyne.NewSquareSize(inlineIconSize))
}

func (r *tabButtonRenderer) MinSize() fyne.Size {
th := r.button.Theme()
var contentWidth, contentHeight float32
textSize := r.label.MinSize()
iconSize := r.iconSize()
padding := th.Size(theme.SizeNamePadding)
padding := theme.SizeForWidget(theme.SizeNamePadding, r.button)
if r.button.iconPosition == buttonIconTop {
contentWidth = fyne.Max(textSize.Width, iconSize)
if r.icon.Visible() {
Expand All @@ -666,7 +662,7 @@ func (r *tabButtonRenderer) MinSize() fyne.Size {
}
}
if r.button.onClosed != nil {
inlineIconSize := th.Size(theme.SizeNameInlineIcon)
inlineIconSize := theme.SizeForWidget(theme.SizeNameInlineIcon, r.button)
contentWidth += inlineIconSize + padding
contentHeight = fyne.Max(contentHeight, inlineIconSize)
}
Expand All @@ -678,12 +674,9 @@ func (r *tabButtonRenderer) Objects() []fyne.CanvasObject {
}

func (r *tabButtonRenderer) Refresh() {
th := r.button.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

if r.button.hovered && !r.button.Disabled() {
r.background.FillColor = th.Color(theme.ColorNameHover, v)
r.background.CornerRadius = th.Size(theme.SizeNameSelectionRadius)
r.background.FillColor = theme.ColorForWidget(theme.ColorNameHover, r.button)
r.background.CornerRadius = theme.SizeForWidget(theme.SizeNameSelectionRadius, r.button)
r.background.Show()
} else {
r.background.Hide()
Expand All @@ -694,14 +687,14 @@ func (r *tabButtonRenderer) Refresh() {
r.label.Alignment = r.button.textAlignment
if !r.button.Disabled() {
if r.button.importance == widget.HighImportance {
r.label.Color = th.Color(theme.ColorNamePrimary, v)
r.label.Color = theme.ColorForWidget(theme.ColorNamePrimary, r.button)
} else {
r.label.Color = th.Color(theme.ColorNameForeground, v)
r.label.Color = theme.ColorForWidget(theme.ColorNameForeground, r.button)
}
} else {
r.label.Color = th.Color(theme.ColorNameDisabled, v)
r.label.Color = theme.ColorForWidget(theme.ColorNameDisabled, r.button)
}
r.label.TextSize = th.Size(theme.SizeNameText)
r.label.TextSize = theme.SizeForWidget(theme.SizeNameText, r.button)
if r.button.text == "" {
r.label.Hide()
} else {
Expand Down Expand Up @@ -737,7 +730,7 @@ func (r *tabButtonRenderer) Refresh() {
}

func (r *tabButtonRenderer) iconSize() float32 {
iconSize := r.button.Theme().Size(theme.SizeNameInlineIcon)
iconSize := theme.SizeForWidget(theme.SizeNameInlineIcon, r.button)
if r.button.iconPosition == buttonIconTop {
return 2 * iconSize
}
Expand All @@ -746,7 +739,7 @@ func (r *tabButtonRenderer) iconSize() float32 {
}

func (r *tabButtonRenderer) padding() fyne.Size {
padding := r.button.Theme().Size(theme.SizeNameInnerPadding)
padding := theme.SizeForWidget(theme.SizeNameInnerPadding, r.button)
if r.label.Text != "" && r.button.iconPosition == buttonIconInline {
return fyne.NewSquareSize(padding * 2)
}
Expand All @@ -768,11 +761,9 @@ type tabCloseButton struct {

func (b *tabCloseButton) CreateRenderer() fyne.WidgetRenderer {
b.ExtendBaseWidget(b)
th := b.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

background := canvas.NewRectangle(th.Color(theme.ColorNameHover, v))
background.CornerRadius = th.Size(theme.SizeNameSelectionRadius)
background := canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameHover, b))
background.CornerRadius = theme.SizeForWidget(theme.SizeNameSelectionRadius, b)
background.Hide()
icon := canvas.NewImageFromResource(theme.CancelIcon())

Expand Down Expand Up @@ -830,12 +821,9 @@ func (r *tabCloseButtonRenderer) Objects() []fyne.CanvasObject {
}

func (r *tabCloseButtonRenderer) Refresh() {
th := r.button.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

if r.button.hovered {
r.background.FillColor = th.Color(theme.ColorNameHover, v)
r.background.CornerRadius = th.Size(theme.SizeNameSelectionRadius)
r.background.FillColor = theme.ColorForWidget(theme.ColorNameHover, r.button)
r.background.CornerRadius = theme.SizeForWidget(theme.SizeNameSelectionRadius, r.button)
r.background.Show()
} else {
r.background.Hide()
Expand Down
20 changes: 6 additions & 14 deletions internal/widget/scroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ func (r *scrollBarRenderer) MinSize() fyne.Size {
}

func (r *scrollBarRenderer) Refresh() {
th := theme.CurrentForWidget(r.scrollBar)
v := fyne.CurrentApp().Settings().ThemeVariant()

r.background.FillColor = th.Color(theme.ColorNameScrollBar, v)
r.background.CornerRadius = th.Size(theme.SizeNameScrollBarRadius)
r.background.FillColor = theme.ColorForWidget(theme.ColorNameScrollBar, r.scrollBar)
r.background.CornerRadius = theme.SizeForWidget(theme.SizeNameScrollBarRadius, r.scrollBar)
r.background.Refresh()
}

Expand All @@ -75,11 +72,8 @@ type scrollBar struct {
}

func (b *scrollBar) CreateRenderer() fyne.WidgetRenderer {
th := theme.CurrentForWidget(b)
v := fyne.CurrentApp().Settings().ThemeVariant()

background := canvas.NewRectangle(th.Color(theme.ColorNameScrollBar, v))
background.CornerRadius = th.Size(theme.SizeNameScrollBarRadius)
background := canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameScrollBar, b))
background.CornerRadius = theme.SizeForWidget(theme.SizeNameScrollBarRadius, b)
r := &scrollBarRenderer{
scrollBar: b,
background: background,
Expand Down Expand Up @@ -197,7 +191,7 @@ func (r *scrollBarAreaRenderer) MinSize() fyne.Size {
func (r *scrollBarAreaRenderer) Refresh() {
th := theme.CurrentForWidget(r.area)
r.bar.Refresh()
r.background.FillColor = th.Color(theme.ColorNameScrollBarBackground, fyne.CurrentApp().Settings().ThemeVariant())
r.background.FillColor = theme.ColorForWidget(theme.ColorNameScrollBarBackground, r.area)
r.background.Hidden = !r.area.isLarge()
r.layoutWithTheme(th, r.area.Size())
canvas.Refresh(r.bar)
Expand Down Expand Up @@ -246,10 +240,8 @@ type scrollBarArea struct {
}

func (a *scrollBarArea) CreateRenderer() fyne.WidgetRenderer {
th := theme.CurrentForWidget(a)
v := fyne.CurrentApp().Settings().ThemeVariant()
a.bar = newScrollBar(a)
background := canvas.NewRectangle(th.Color(theme.ColorNameScrollBarBackground, v))
background := canvas.NewRectangle(theme.ColorForWidget(theme.ColorNameScrollBarBackground, a))
background.Hidden = !a.isLarge()
return &scrollBarAreaRenderer{BaseRenderer: NewBaseRenderer([]fyne.CanvasObject{background, a.bar}), area: a, bar: a.bar, background: background}
}
Expand Down
Loading
Loading