-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CircularProgress widget and related renderer
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
1 parent
8b009e1
commit 645bb2c
Showing
3 changed files
with
451 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
Oops, something went wrong.