Skip to content

Commit

Permalink
Add CircularProgress widget and related renderer
Browse files Browse the repository at this point in the history
This commit adds a new widget called CircularProgress, along with its corresponding renderer. The CircularProgress widget is a circular progress indicator that can be used in Fyne applications. It includes methods to start and stop the progress animation.

The commit also includes a new function called detect_interfaces, which is an alternate to ipconfig/ifconfig. This function detects the available addresses for dispatching.

The changes in this commit aim to enhance the functionality and user experience of the application.
  • Loading branch information
sanjay7178 committed Aug 24, 2024
1 parent 8b009e1 commit 645bb2c
Show file tree
Hide file tree
Showing 3 changed files with 451 additions and 401 deletions.
88 changes: 88 additions & 0 deletions custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package main

import (
"image/color"

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

// "fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"

// "math"
"time"
)

type CircularProgress struct {
widget.BaseWidget
progress float64
running bool
}

func NewCircularProgress() *CircularProgress {
c := &CircularProgress{}
c.ExtendBaseWidget(c)
return c
}

func (c *CircularProgress) CreateRenderer() fyne.WidgetRenderer {
circle := canvas.NewCircle(theme.PrimaryColor())
circle.StrokeWidth = 5
circle.StrokeColor = theme.PrimaryColor()
return &circularProgressRenderer{circle: circle, progress: c}
}

func (c *CircularProgress) Start() {
c.running = true
go func() {
for c.running {
c.progress += 0.01
if c.progress > 1 {
c.progress = 0
}
c.Refresh()
time.Sleep(50 * time.Millisecond)
}
}()
}

func (c *CircularProgress) Stop() {
c.running = false
}

type circularProgressRenderer struct {
circle *canvas.Circle
progress *CircularProgress
}

func (r *circularProgressRenderer) Layout(size fyne.Size) {
r.circle.Resize(size)
r.circle.Move(fyne.NewPos(0, 0))
}

func (r *circularProgressRenderer) MinSize() fyne.Size {
return fyne.NewSize(50, 50)
}

func (r *circularProgressRenderer) Refresh() {
_ = 360 * r.progress.progress
r.circle.StrokeWidth = 5
r.circle.StrokeColor = theme.PrimaryColor()
r.circle.FillColor = theme.BackgroundColor()
r.circle.Refresh()
r.circle.StrokeWidth = 5
r.circle.StrokeColor = theme.PrimaryColor()
r.circle.FillColor = theme.BackgroundColor()
r.circle.Refresh()
}

func (r *circularProgressRenderer) BackgroundColor() color.Color {
return theme.BackgroundColor()
}

func (r *circularProgressRenderer) Objects() []fyne.CanvasObject {
return []fyne.CanvasObject{r.circle}
}

func (r *circularProgressRenderer) Destroy() {}
Loading

0 comments on commit 645bb2c

Please sign in to comment.