fyne-widgets/examples/webcam/main.go

51 lines
1.1 KiB
Go

package main
import (
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"git.martyn.berlin/martyn/fyne-widgets/pkg/layouts"
"git.martyn.berlin/martyn/fyne-widgets/pkg/webcam"
)
var webcamID int
var webcamLabel *widget.Label
var webcamWidget *webcam.Webcam
func switchWebcam(id int) {
webcamLabel.Text = "Webcam: " + strconv.Itoa(id)
webcamLabel.Refresh()
webcamWidget.WebcamID = int64(id)
webcamWidget.Refresh()
}
func incWebCamID() {
webcamID = webcamID + 1
switchWebcam(webcamID)
}
func decWebCamID() {
webcamID = webcamID - 1
switchWebcam(webcamID)
}
func main() {
a := app.New()
w := a.NewWindow("Webcam")
webcamWidget = webcam.NewWebcam()
layout := layouts.NewFloatingControlsLayout()
layout.FloatingControlsLocation = layouts.FloatingControlsCenter
webcamID = 0
webcamLabel = widget.NewLabel("Webcam: 0")
buttons := container.NewHBox(webcamLabel, widget.NewButton("-", decWebCamID), widget.NewButton("+", incWebCamID))
w.SetContent(container.New(&layout, webcamWidget, buttons))
w.Resize(fyne.NewSize(640, 480))
w.ShowAndRun()
}