Skip to content
Open
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
9 changes: 5 additions & 4 deletions ui/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var COLOR_BG = color.RGBA{40, 42, 54, 255}
var COLOR_BG_2 = color.RGBA{68, 71, 90, 255}
var COLOR_ACTIVE = color.RGBA{68, 71, 90, 255}
var COLOR_RED = color.RGBA{255, 85, 85, 255}
var TRANSPARENT = color.RGBA{255, 255, 255, 0}

func (m mainTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
switch name {
Expand All @@ -26,9 +27,12 @@ func (m mainTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) co
case theme.ColorNameError:
return COLOR_RED

case theme.ColorNamePrimary, theme.ColorNameSelection, theme.ColorNameInputBorder, theme.ColorNameSeparator, theme.ColorNameScrollBar:
case theme.ColorNamePrimary, theme.ColorNameInputBorder, theme.ColorNameScrollBar:
return COLOR_PRIMARY

case theme.ColorNameSeparator, theme.ColorNameSelection, theme.ColorNameHover:
return TRANSPARENT

case theme.ColorNameButton:
return COLOR_PRIMARY

Expand All @@ -52,15 +56,12 @@ func (m mainTheme) Font(style fyne.TextStyle) fyne.Resource {
}

func (m mainTheme) Size(name fyne.ThemeSizeName) float32 {

switch name {

case "innerPadding":
return theme.DefaultTheme().Size(name) - theme.DefaultTheme().Size(name)/4

case "inputRadius", "selectionRadius":
return 0

}

return theme.DefaultTheme().Size(name) - theme.DefaultTheme().Size(name)*0.2
Expand Down
67 changes: 67 additions & 0 deletions ui/views/components/text.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package components

import (
"strings"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)

// LargeTextViewer is a custom Fyne widget for displaying large amounts of text efficiently using a List.
type LargeTextViewer struct {
widget.BaseWidget
lines []string // The text content split into lines
list *widget.List // List widget to display the lines
}

// NewLargeTextViewer creates a new LargeTextViewer widget with the given text.
func NewLargeTextViewer(text string) *LargeTextViewer {
viewer := &LargeTextViewer{
lines: strings.Split(text, "\n"),
}
viewer.ExtendBaseWidget(viewer)

// Create the List widget
viewer.list = widget.NewList(
// Length function: returns the total number of lines
func() int {
return len(viewer.lines)
},
// Create function: creates a template for each item
func() fyne.CanvasObject {
text := canvas.NewText("", theme.Color(theme.ColorNameForeground))
text.TextSize = theme.TextSize()
return text
},
// Update function: updates the item at the given index
func(id widget.ListItemID, obj fyne.CanvasObject) {
if id < 0 || id >= len(viewer.lines) {
return // Prevent out-of-bounds access
}
text := obj.(*canvas.Text)
text.Text = viewer.lines[id]
text.Refresh()
},
)

return viewer
}

// SetText updates the text content of the viewer.
func (v *LargeTextViewer) SetText(text string) {
v.lines = strings.Split(text, "\n")
v.list.Refresh()
}

// CreateRenderer creates the renderer for the LargeTextViewer.
func (v *LargeTextViewer) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(v.list)
}

// Resize updates the widget's size.
func (v *LargeTextViewer) Resize(size fyne.Size) {
v.BaseWidget.Resize(size)
v.list.Resize(size)
}
Loading