Skip to content

Line

This example demonstrates how to draw a line in Fyne using the canvas package.

Show Code
package main
import (
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
)
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("Line")
// Create a red line
line := canvas.NewLine(color.RGBA{R: 255, G: 0, B: 0, A: 255})
line.StrokeWidth = 4 // thickness
// The line needs a container to give it space
content := container.NewWithoutLayout(line)
line.Resize(fyne.NewSize(200, 0)) // length in px
line.Move(fyne.NewPos(20, 50)) // x, y position
myWindow.SetContent(content)
myWindow.Resize(fyne.NewSize(300, 150))
myWindow.ShowAndRun()
}