feat: trying to add clipboard, requires changing from canvas object

This commit is contained in:
2024-07-16 12:36:36 -05:00
parent aff1de4515
commit 6315bc003d
3 changed files with 41 additions and 45 deletions

View File

@@ -2,7 +2,7 @@
Icon = "resources/images/icon.png" Icon = "resources/images/icon.png"
Name = "Computer Info" Name = "Computer Info"
ID = "ryanehamil.computerinfo" ID = "ryanehamil.computerinfo"
Version = "1.2.1" Version = "1.3.1"
Build = 6 Build = 6
[Development] [Development]

View File

@@ -16,7 +16,7 @@ func main() {
w.Resize(fyne.NewSize(800, 200)) w.Resize(fyne.NewSize(800, 200))
w.SetContent(computerinfo.Container()) w.SetContent(computerinfo.CanvasObject())
w.ShowAndRun() w.ShowAndRun()
} }

View File

@@ -2,69 +2,65 @@ package computerinfo
import ( import (
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
fyneLayout "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/widget"
"fyne.io/fyne/v2/theme"
"github.com/ryanehamil/computerinfo/src/utils" "github.com/ryanehamil/computerinfo/src/utils"
) )
// obj_ComputerName returns a canvas object containing the computer name text // CustomTappableLabel is a label that supports tapping
func obj_ComputerName() fyne.CanvasObject { type CustomTappableLabel struct {
// Get the computer name from the utils package widget.Label
computername := utils.GetComputerName() }
// Create a new text label with the computer name // NewCustomTappableLabel creates a new tappable label
label := canvas.NewText(computername, theme.TextColor()) func NewCustomTappableLabel(text string) *CustomTappableLabel {
label.TextSize = 100 label := &CustomTappableLabel{
label.TextStyle = fyne.TextStyle{Bold: true} Label: widget.Label{
label.Alignment = fyne.TextAlignCenter Text: text,
TextStyle: fyne.TextStyle{Bold: true},
// Return the label as a canvas object },
}
label.ExtendBaseWidget(label)
return label
}
// Tapped is called when the label is tapped
func (l *CustomTappableLabel) Tapped(_ *fyne.PointEvent) {
fyne.CurrentApp().Driver().AllWindows()[0].Clipboard().SetContent(l.Text)
}
// TappedSecondary is called when the label is right-clicked (not used here)
func (l *CustomTappableLabel) TappedSecondary(_ *fyne.PointEvent) {}
func obj_ComputerName() fyne.CanvasObject {
computername := utils.GetComputerName()
label := NewCustomTappableLabel(computername)
label.Alignment = fyne.TextAlignCenter
// label.TextSize = 100
return label return label
} }
// obj_IPAddress returns a slice of canvas objects containing the IP addresses of the computer
func obj_IPAddress() []fyne.CanvasObject { func obj_IPAddress() []fyne.CanvasObject {
ipAddresses := utils.GetIPAddress()
labels := []fyne.CanvasObject{} labels := []fyne.CanvasObject{}
// Get the IP addresses of the computer for _, ip := range ipAddresses {
ipaddress := utils.GetIPAddress() container.NewHBox()
label := NewCustomTappableLabel(ip)
// Loop over the IP addresses and create a label for each one
for _, ip := range ipaddress {
label := canvas.NewText(ip, theme.TextColor())
label.TextSize = 20
label.TextStyle = fyne.TextStyle{Bold: true}
label.Alignment = fyne.TextAlignCenter label.Alignment = fyne.TextAlignCenter
// label.TextSize = 20
labels = append(labels, label) labels = append(labels, label)
} }
// Return the slice of labels as canvas objects
return labels return labels
} }
// allObjects returns a slice of canvas objects containing both the computer name and IP addresses
func allObjects() []fyne.CanvasObject { func allObjects() []fyne.CanvasObject {
return []fyne.CanvasObject{ return append([]fyne.CanvasObject{
// Get the computer name canvas object
obj_ComputerName(), obj_ComputerName(),
// Create a VBox container containing the IP addresses }, obj_IPAddress()...)
container.NewVBox(
obj_IPAddress()...,
),
}
} }
// Container creates a container object for the window func CanvasObject() fyne.CanvasObject {
func Container() fyne.CanvasObject { return container.NewVBox(allObjects()...)
// Create a vertical layout
verticalLayout := fyneLayout.NewVBoxLayout()
// Create a new container using the vertical layout and the canvas objects
cont := container.New(verticalLayout, allObjects()...)
cont.Resize(fyne.NewSize(200, 200))
// Return the container
return cont
} }