Skip to content

Commit

Permalink
Merge pull request fyne-io#4960 from andydotxyz/fix/containerthemeove…
Browse files Browse the repository at this point in the history
…rride

Last of the theme override code
  • Loading branch information
andydotxyz authored Jun 28, 2024
2 parents 78dcf92 + 6b58b5b commit 7a8bc42
Show file tree
Hide file tree
Showing 29 changed files with 2,030 additions and 1,700 deletions.
23 changes: 14 additions & 9 deletions container/apptabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ 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(theme.Color(theme.ColorNameShadow)),
indicator: canvas.NewRectangle(theme.Color(theme.ColorNamePrimary)),
divider: canvas.NewRectangle(th.Color(theme.ColorNameShadow, v)),
indicator: canvas.NewRectangle(th.Color(theme.ColorNamePrimary, v)),
},
appTabs: t,
}
Expand Down Expand Up @@ -420,23 +423,25 @@ func (r *appTabsRenderer) updateIndicator(animate bool) {

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

switch r.appTabs.location {
case TabLocationTop:
indicatorPos = fyne.NewPos(selectedPos.X, r.bar.MinSize().Height)
indicatorSize = fyne.NewSize(selectedSize.Width, theme.Padding())
indicatorSize = fyne.NewSize(selectedSize.Width, pad)
case TabLocationLeading:
indicatorPos = fyne.NewPos(r.bar.MinSize().Width, selectedPos.Y)
indicatorSize = fyne.NewSize(theme.Padding(), selectedSize.Height)
indicatorSize = fyne.NewSize(pad, selectedSize.Height)
case TabLocationBottom:
indicatorPos = fyne.NewPos(selectedPos.X, r.bar.Position().Y-theme.Padding())
indicatorSize = fyne.NewSize(selectedSize.Width, theme.Padding())
indicatorPos = fyne.NewPos(selectedPos.X, r.bar.Position().Y-pad)
indicatorSize = fyne.NewSize(selectedSize.Width, pad)
case TabLocationTrailing:
indicatorPos = fyne.NewPos(r.bar.Position().X-theme.Padding(), selectedPos.Y)
indicatorSize = fyne.NewSize(theme.Padding(), selectedSize.Height)
indicatorPos = fyne.NewPos(r.bar.Position().X-pad, selectedPos.Y)
indicatorSize = fyne.NewSize(pad, selectedSize.Height)
}

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

func (r *appTabsRenderer) updateTabs(max int) {
Expand Down
25 changes: 15 additions & 10 deletions container/doctabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ 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(theme.Color(theme.ColorNameShadow)),
indicator: canvas.NewRectangle(theme.Color(theme.ColorNamePrimary)),
divider: canvas.NewRectangle(th.Color(theme.ColorNameShadow, v)),
indicator: canvas.NewRectangle(th.Color(theme.ColorNamePrimary, v)),
},
docTabs: t,
scroller: NewScroll(&fyne.Container{}),
Expand Down Expand Up @@ -384,9 +387,10 @@ 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), animate)
r.moveIndicator(fyne.NewPos(0, 0), fyne.NewSize(0, 0), th, animate)
return
}

Expand Down Expand Up @@ -419,20 +423,21 @@ func (r *docTabsRenderer) updateIndicator(animate bool) {

var indicatorPos fyne.Position
var indicatorSize fyne.Size
pad := th.Size(theme.SizeNamePadding)

switch r.docTabs.location {
case TabLocationTop:
indicatorPos = fyne.NewPos(selectedPos.X-scrollOffset.X, r.bar.MinSize().Height)
indicatorSize = fyne.NewSize(fyne.Min(selectedSize.Width, scrollSize.Width-indicatorPos.X), theme.Padding())
indicatorSize = fyne.NewSize(fyne.Min(selectedSize.Width, scrollSize.Width-indicatorPos.X), pad)
case TabLocationLeading:
indicatorPos = fyne.NewPos(r.bar.MinSize().Width, selectedPos.Y-scrollOffset.Y)
indicatorSize = fyne.NewSize(theme.Padding(), fyne.Min(selectedSize.Height, scrollSize.Height-indicatorPos.Y))
indicatorSize = fyne.NewSize(pad, fyne.Min(selectedSize.Height, scrollSize.Height-indicatorPos.Y))
case TabLocationBottom:
indicatorPos = fyne.NewPos(selectedPos.X-scrollOffset.X, r.bar.Position().Y-theme.Padding())
indicatorSize = fyne.NewSize(fyne.Min(selectedSize.Width, scrollSize.Width-indicatorPos.X), theme.Padding())
indicatorPos = fyne.NewPos(selectedPos.X-scrollOffset.X, r.bar.Position().Y-pad)
indicatorSize = fyne.NewSize(fyne.Min(selectedSize.Width, scrollSize.Width-indicatorPos.X), pad)
case TabLocationTrailing:
indicatorPos = fyne.NewPos(r.bar.Position().X-theme.Padding(), selectedPos.Y-scrollOffset.Y)
indicatorSize = fyne.NewSize(theme.Padding(), fyne.Min(selectedSize.Height, scrollSize.Height-indicatorPos.Y))
indicatorPos = fyne.NewPos(r.bar.Position().X-pad, selectedPos.Y-scrollOffset.Y)
indicatorSize = fyne.NewSize(pad, fyne.Min(selectedSize.Height, scrollSize.Height-indicatorPos.Y))
}

if indicatorPos.X < 0 {
Expand All @@ -449,7 +454,7 @@ func (r *docTabsRenderer) updateIndicator(animate bool) {
return
}

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

func (r *docTabsRenderer) updateAllTabs() {
Expand Down
19 changes: 13 additions & 6 deletions container/innerwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ func (w *InnerWindow) CreateRenderer() fyne.WidgetRenderer {
}
title := newDraggableLabel(w.title, w)
title.Truncation = fyne.TextTruncateEllipsis
th := w.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

bar := NewBorder(nil, nil, buttons, icon, title)
bg := canvas.NewRectangle(theme.Color(theme.ColorNameOverlayBackground))
contentBG := canvas.NewRectangle(theme.Color(theme.ColorNameBackground))
bg := canvas.NewRectangle(th.Color(theme.ColorNameOverlayBackground, v))
contentBG := canvas.NewRectangle(th.Color(theme.ColorNameBackground, v))
corner := newDraggableCorner(w)

objects := []fyne.CanvasObject{bg, contentBG, bar, w.content, corner}
Expand Down Expand Up @@ -119,7 +121,9 @@ type innerWindowRenderer struct {
}

func (i *innerWindowRenderer) Layout(size fyne.Size) {
pad := theme.Padding()
th := i.win.Theme()
pad := th.Size(theme.SizeNamePadding)

pos := fyne.NewSquareOffsetPos(pad / 2)
size = size.Subtract(fyne.NewSquareSize(pad))
i.LayoutShadow(size, pos)
Expand All @@ -144,7 +148,8 @@ func (i *innerWindowRenderer) Layout(size fyne.Size) {
}

func (i *innerWindowRenderer) MinSize() fyne.Size {
pad := theme.Padding()
th := i.win.Theme()
pad := th.Size(theme.SizeNamePadding)
contentMin := i.win.content.MinSize()
barMin := i.bar.MinSize()

Expand All @@ -154,9 +159,11 @@ func (i *innerWindowRenderer) MinSize() fyne.Size {
}

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

Expand Down
77 changes: 49 additions & 28 deletions container/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (r *splitContainerRenderer) Layout(size fyne.Size) {
leadingSize.Width = lw
leadingSize.Height = size.Height
dividerPos.X = lw
dividerSize.Width = dividerThickness()
dividerSize.Width = dividerThickness(r.divider)
dividerSize.Height = size.Height
trailingPos.X = lw + dividerSize.Width
trailingSize.Width = tw
Expand All @@ -112,7 +112,7 @@ func (r *splitContainerRenderer) Layout(size fyne.Size) {
leadingSize.Height = lh
dividerPos.Y = lh
dividerSize.Width = size.Width
dividerSize.Height = dividerThickness()
dividerSize.Height = dividerThickness(r.divider)
trailingPos.Y = lh + dividerSize.Height
trailingSize.Width = size.Width
trailingSize.Height = th
Expand Down Expand Up @@ -151,11 +151,13 @@ func (r *splitContainerRenderer) Refresh() {
// [1] is divider which doesn't change
r.objects[2] = r.split.Trailing
r.Layout(r.split.Size())

r.divider.Refresh()
canvas.Refresh(r.split)
}

func (r *splitContainerRenderer) computeSplitLengths(total, lMin, tMin float32) (float32, float32) {
available := float64(total - dividerThickness())
available := float64(total - dividerThickness(r.divider))
if available <= 0 {
return 0, 0
}
Expand Down Expand Up @@ -234,8 +236,11 @@ 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)
background := canvas.NewRectangle(theme.Color(theme.ColorNameShadow))
foreground := canvas.NewRectangle(theme.Color(theme.ColorNameForeground))
th := d.Theme()
v := fyne.CurrentApp().Settings().ThemeVariant()

background := canvas.NewRectangle(th.Color(theme.ColorNameShadow, v))
foreground := canvas.NewRectangle(th.Color(theme.ColorNameForeground, v))
return &dividerRenderer{
divider: d,
background: background,
Expand Down Expand Up @@ -267,12 +272,12 @@ func (d *divider) Dragged(e *fyne.DragEvent) {
x, y := d.currentDragPos.Components()
var offset, leadingRatio, trailingRatio float64
if d.split.Horizontal {
widthFree := float64(d.split.Size().Width - dividerThickness())
widthFree := float64(d.split.Size().Width - dividerThickness(d))
leadingRatio = float64(d.split.Leading.MinSize().Width) / widthFree
trailingRatio = 1. - (float64(d.split.Trailing.MinSize().Width) / widthFree)
offset = float64(x-d.startDragOff.X) / widthFree
} else {
heightFree := float64(d.split.Size().Height - dividerThickness())
heightFree := float64(d.split.Size().Height - dividerThickness(d))
leadingRatio = float64(d.split.Leading.MinSize().Height) / heightFree
trailingRatio = 1. - (float64(d.split.Trailing.MinSize().Height) / heightFree)
offset = float64(y-d.startDragOff.Y) / heightFree
Expand Down Expand Up @@ -315,55 +320,71 @@ func (r *dividerRenderer) Layout(size fyne.Size) {
r.background.Resize(size)
var x, y, w, h float32
if r.divider.split.Horizontal {
x = (dividerThickness() - handleThickness()) / 2
y = (size.Height - handleLength()) / 2
w = handleThickness()
h = handleLength()
x = (dividerThickness(r.divider) - handleThickness(r.divider)) / 2
y = (size.Height - handleLength(r.divider)) / 2
w = handleThickness(r.divider)
h = handleLength(r.divider)
} else {
x = (size.Width - handleLength()) / 2
y = (dividerThickness() - handleThickness()) / 2
w = handleLength()
h = handleThickness()
x = (size.Width - handleLength(r.divider)) / 2
y = (dividerThickness(r.divider) - handleThickness(r.divider)) / 2
w = handleLength(r.divider)
h = handleThickness(r.divider)
}
r.foreground.Move(fyne.NewPos(x, y))
r.foreground.Resize(fyne.NewSize(w, h))
}

func (r *dividerRenderer) MinSize() fyne.Size {
if r.divider.split.Horizontal {
return fyne.NewSize(dividerThickness(), dividerLength())
return fyne.NewSize(dividerThickness(r.divider), dividerLength(r.divider))
}
return fyne.NewSize(dividerLength(), dividerThickness())
return fyne.NewSize(dividerLength(r.divider), dividerThickness(r.divider))
}

func (r *dividerRenderer) Objects() []fyne.CanvasObject {
return r.objects
}

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

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

func dividerThickness() float32 {
return theme.Padding() * 2
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
}

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

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

}

func handleLength() float32 {
return theme.Padding() * 4
func handleLength(d *divider) float32 {
th := dividerTheme(d)
return th.Size(theme.SizeNamePadding) * 4
}
Loading

0 comments on commit 7a8bc42

Please sign in to comment.