fyne-widgets/examples/waveform/main.go

45 lines
1.3 KiB
Go
Raw Permalink Normal View History

2022-02-11 18:32:22 +00:00
package main
import (
"image/color"
"math/rand"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"git.martyn.berlin/martyn/fyne-widgets/pkg/layouts"
2022-02-11 19:07:21 +00:00
"git.martyn.berlin/martyn/fyne-widgets/pkg/waveform"
2022-02-11 18:32:22 +00:00
)
func main() {
a := app.New()
2022-02-11 19:07:21 +00:00
w := a.NewWindow("Waveform")
2022-02-11 18:32:22 +00:00
randomAudioData := make([]int32, 1200)
for i := 0; i < 1200; i++ {
randomAudioData[i] = rand.Int31()
}
2022-02-11 19:07:21 +00:00
as := waveform.NewWaveform(randomAudioData)
as2 := waveform.NewWaveform(randomAudioData)
2022-02-11 18:32:22 +00:00
as2.OverrideBackground = true
as2.OverrideBackgroundColor = color.RGBA{0, 0, 0xff, 0xff} // no effect because of the next line
as2.TransparentBackground = true
as2.SetMinSize(fyne.NewSize(1200, 64))
2022-02-11 19:07:21 +00:00
as3 := waveform.NewWaveform(randomAudioData)
2022-02-11 18:32:22 +00:00
as3.StretchSamples = true
as3.SetMinSize(fyne.NewSize(100, 64))
as3.OverrideForeground = true
as3.OverrideForegroundColor = color.RGBA{0xff, 0, 0, 0xff}
as3.TransparentBackground = false
layout := layouts.NewFloatingControlsLayout()
layout.FloatingControlsLocation = layouts.FloatingControlsCenter
image := canvas.NewImageFromResource(theme.FyneLogo())
image.SetMinSize(fyne.NewSize(200, 64*3))
contain := container.New(&layout, container.NewBorder(image, as, nil, nil, as3), container.NewBorder(nil, nil, nil, nil, as2))
w.SetContent(contain)
w.ShowAndRun()
}