canvas

package
v2.0.0-...-f45adc8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package canvas contains all of the primitive CanvasObjects that make up a Fyne GUI.

The types implemented in this package are used as building blocks in order to build higher order functionality. These types are designed to be non-interactive, by design. If additional functionality is required, it's usually a sign that this type should be used as part of a custom widget.

Index

Constants

View Source
const (
	// DurationStandard is the time a standard interface animation will run.
	//
	// Since: 2.0
	DurationStandard = time.Millisecond * 300
	// DurationShort is the time a subtle or small transition should use.
	//
	// Since: 2.0
	DurationShort = time.Millisecond * 150
)

Variables

This section is empty.

Functions

func NewColorRGBAAnimation

func NewColorRGBAAnimation(start, stop color.Color, d time.Duration, fn func(color.Color)) *fyne.Animation

NewColorRGBAAnimation sets up a new animation that will transition from the start to stop Color over the specified Duration. The colour transition will move linearly through the RGB colour space. The content of fn should apply the color values to an object and refresh it. You should call Start() on the returned animation to start it.

Since: 2.0

func NewPositionAnimation

func NewPositionAnimation(start, stop fyne.Position, d time.Duration, fn func(fyne.Position)) *fyne.Animation

NewPositionAnimation sets up a new animation that will transition from the start to stop Position over the specified Duration. The content of fn should apply the position value to an object for the change to be visible. You should call Start() on the returned animation to start it.

Since: 2.0

func NewSizeAnimation

func NewSizeAnimation(start, stop fyne.Size, d time.Duration, fn func(fyne.Size)) *fyne.Animation

NewSizeAnimation sets up a new animation that will transition from the start to stop Size over the specified Duration. The content of fn should apply the size value to an object for the change to be visible. You should call Start() on the returned animation to start it.

Since: 2.0

func Refresh

func Refresh(obj fyne.CanvasObject)

Refresh instructs the containing canvas to refresh the specified obj.

Types

type Circle

type Circle struct {
	Position1 fyne.Position // The current top-left position of the Circle
	Position2 fyne.Position // The current bottomright position of the Circle
	Hidden    bool          // Is this circle currently hidden

	FillColor   color.Color // The circle fill color
	StrokeColor color.Color // The circle stroke color
	StrokeWidth float32     // The stroke width of the circle
}

Circle describes a colored circle primitive in a Fyne canvas

func NewCircle

func NewCircle(color color.Color) *Circle

NewCircle returns a new Circle instance

func (*Circle) Hide

func (c *Circle) Hide()

Hide will set this circle to not be visible

func (*Circle) MinSize

func (c *Circle) MinSize() fyne.Size

MinSize for a Circle simply returns Size{1, 1} as there is no explicit content

func (*Circle) Move

func (c *Circle) Move(pos fyne.Position)

Move the circle object to a new position, relative to its parent / canvas

func (*Circle) Position

func (c *Circle) Position() fyne.Position

Position gets the current top-left position of this circle object, relative to its parent / canvas

func (*Circle) Refresh

func (c *Circle) Refresh()

Refresh causes this object to be redrawn with its configured state.

func (*Circle) Resize

func (c *Circle) Resize(size fyne.Size)

Resize sets a new bottom-right position for the circle object If it has a stroke width this will cause it to Refresh.

func (*Circle) Show

func (c *Circle) Show()

Show will set this circle to be visible

func (*Circle) Size

func (c *Circle) Size() fyne.Size

Size returns the current size of bounding box for this circle object

func (*Circle) Visible

func (c *Circle) Visible() bool

Visible returns true if this circle is visible, false otherwise

type Image

type Image struct {

	// one of the following sources will provide our image data
	File     string        // Load the image from a file
	Resource fyne.Resource // Load the image from an in-memory resource
	Image    image.Image   // Specify a loaded image to use in this canvas object

	Translucency float64    // Set a translucency value > 0.0 to fade the image
	FillMode     ImageFill  // Specify how the image should expand to fill or fit the available space
	ScaleMode    ImageScale // Specify the type of scaling interpolation applied to the image
	// contains filtered or unexported fields
}

Image describes a drawable image area that can render in a Fyne canvas The image may be a vector or a bitmap representation, it will fill the area. The fill mode can be changed by setting FillMode to a different ImageFill.

func NewImageFromFile

func NewImageFromFile(file string) *Image

NewImageFromFile creates a new image from a local file. Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

func NewImageFromImage

func NewImageFromImage(img image.Image) *Image

NewImageFromImage returns a new Image instance that is rendered from the Go image.Image passed in. Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

func NewImageFromReader

func NewImageFromReader(read io.Reader, name string) *Image

NewImageFromReader creates a new image from a data stream. The name parameter is required to uniquely identify this image (for caching etc.). If the image in this io.Reader is an SVG, the name should end ".svg". Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

Since: 2.0

func NewImageFromResource

func NewImageFromResource(res fyne.Resource) *Image

NewImageFromResource creates a new image by loading the specified resource. Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

func NewImageFromURI

func NewImageFromURI(uri fyne.URI) *Image

NewImageFromURI creates a new image from named resource. File URIs will read the file path and other schemes will download the data into a resource. HTTP and HTTPs URIs will use the GET method by default to request the resource. Images returned from this method will scale to fit the canvas object. The method for scaling can be set using the Fill field.

Since: 2.0

func (*Image) Alpha

func (i *Image) Alpha() float64

Alpha is a convenience function that returns the alpha value for an image based on its Translucency value. The result is 1.0 - Translucency.

func (*Image) Aspect

func (i *Image) Aspect() float32

Aspect will return the original content aspect after it was last refreshed.

Since: 2.4

func (*Image) Hide

func (i *Image) Hide()

Hide will set this image to not be visible

func (*Image) MinSize

func (i *Image) MinSize() fyne.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Image) Move

func (i *Image) Move(pos fyne.Position)

Move the image object to a new position, relative to its parent top, left corner.

func (*Image) Position

func (o *Image) Position() fyne.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Image) Refresh

func (i *Image) Refresh()

Refresh causes this image to be redrawn with its configured state.

func (*Image) Resize

func (i *Image) Resize(s fyne.Size)

Resize on an image will scale the content or reposition it according to FillMode. It will normally cause a Refresh to ensure the pixels are recalculated.

func (*Image) SetMinSize

func (o *Image) SetMinSize(size fyne.Size)

SetMinSize specifies the smallest size this object should be.

func (*Image) Show

func (o *Image) Show()

Show will set this object to be visible.

func (*Image) Size

func (o *Image) Size() fyne.Size

Size returns the current size of this canvas object.

func (*Image) Visible

func (o *Image) Visible() bool

Visible returns true if this object is visible, false otherwise.

type ImageFill

type ImageFill int

ImageFill defines the different type of ways an image can stretch to fill its space.

const (
	// ImageFillStretch will scale the image to match the Size() values.
	// This is the default and does not maintain aspect ratio.
	ImageFillStretch ImageFill = iota
	// ImageFillContain makes the image fit within the object Size(),
	// centrally and maintaining aspect ratio.
	// There may be transparent sections top and bottom or left and right.
	ImageFillContain // (Fit)
	// ImageFillOriginal ensures that the container grows to the pixel dimensions
	// required to fit the original image. The aspect of the image will be maintained so,
	// as with ImageFillContain there may be transparent areas around the image.
	// Note that the minSize may be smaller than the image dimensions if scale > 1.
	ImageFillOriginal
)

type ImageScale

type ImageScale int32

ImageScale defines the different scaling filters used to scaling images

const (
	// ImageScaleSmooth will scale the image using ApproxBiLinear filter (or GL equivalent)
	ImageScaleSmooth ImageScale = iota
	// ImageScalePixels will scale the image using NearestNeighbor filter (or GL equivalent)
	ImageScalePixels
	// ImageScaleFastest will scale the image using hardware GPU if available
	//
	// Since: 2.0
	ImageScaleFastest
)

type Line

type Line struct {
	Position1 fyne.Position // The current top-left position of the Line
	Position2 fyne.Position // The current bottom-right position of the Line
	Hidden    bool          // Is this Line currently hidden

	StrokeColor color.Color // The line stroke color
	StrokeWidth float32     // The stroke width of the line
}

Line describes a colored line primitive in a Fyne canvas. Lines are special as they can have a negative width or height to indicate an inverse slope (i.e. slope up vs down).

func NewLine

func NewLine(color color.Color) *Line

NewLine returns a new Line instance

func (*Line) Hide

func (l *Line) Hide()

Hide will set this line to not be visible

func (*Line) MinSize

func (l *Line) MinSize() fyne.Size

MinSize for a Line simply returns Size{1, 1} as there is no explicit content

func (*Line) Move

func (l *Line) Move(pos fyne.Position)

Move the line object to a new position, relative to its parent / canvas

func (*Line) Position

func (l *Line) Position() fyne.Position

Position gets the current top-left position of this line object, relative to its parent / canvas

func (*Line) Refresh

func (l *Line) Refresh()

Refresh causes this line to be redrawn with its configured state.

func (*Line) Resize

func (l *Line) Resize(size fyne.Size)

Resize sets a new bottom-right position for the line object, then it will then be refreshed.

func (*Line) Show

func (l *Line) Show()

Show will set this line to be visible

func (*Line) Size

func (l *Line) Size() fyne.Size

Size returns the current size of bounding box for this line object

func (*Line) Visible

func (l *Line) Visible() bool

Visible returns true if this line// Show will set this circle to be visible is visible, false otherwise

type LinearGradient

type LinearGradient struct {
	StartColor color.Color // The beginning color of the gradient
	EndColor   color.Color // The end color of the gradient
	Angle      float64     // The angle of the gradient (0/180 for vertical; 90/270 for horizontal)
	// contains filtered or unexported fields
}

LinearGradient defines a Gradient travelling straight at a given angle. The only supported values for the angle are `0.0` (vertical) and `90.0` (horizontal), currently.

func NewHorizontalGradient

func NewHorizontalGradient(start, end color.Color) *LinearGradient

NewHorizontalGradient creates a new horizontally travelling linear gradient. The start color will be at the left of the gradient and the end color will be at the right.

func NewLinearGradient

func NewLinearGradient(start, end color.Color, angle float64) *LinearGradient

NewLinearGradient creates a linear gradient at the specified angle. The angle parameter is the degree angle along which the gradient is calculated. A NewHorizontalGradient uses 270 degrees and NewVerticalGradient is 0 degrees.

func NewVerticalGradient

func NewVerticalGradient(start color.Color, end color.Color) *LinearGradient

NewVerticalGradient creates a new vertically travelling linear gradient. The start color will be at the top of the gradient and the end color will be at the bottom.

func (*LinearGradient) Generate

func (g *LinearGradient) Generate(iw, ih int) image.Image

Generate calculates an image of the gradient with the specified width and height.

func (*LinearGradient) Hide

func (g *LinearGradient) Hide()

Hide will set this gradient to not be visible

func (*LinearGradient) MinSize

func (o *LinearGradient) MinSize() fyne.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*LinearGradient) Move

func (g *LinearGradient) Move(pos fyne.Position)

Move the gradient to a new position, relative to its parent / canvas

func (*LinearGradient) Position

func (o *LinearGradient) Position() fyne.Position

Position gets the current position of this canvas object, relative to its parent.

func (*LinearGradient) Refresh

func (g *LinearGradient) Refresh()

Refresh causes this gradient to be redrawn with its configured state.

func (*LinearGradient) Resize

func (o *LinearGradient) Resize(size fyne.Size)

Resize sets a new size for the canvas object.

func (*LinearGradient) SetMinSize

func (o *LinearGradient) SetMinSize(size fyne.Size)

SetMinSize specifies the smallest size this object should be.

func (*LinearGradient) Show

func (o *LinearGradient) Show()

Show will set this object to be visible.

func (*LinearGradient) Size

func (o *LinearGradient) Size() fyne.Size

Size returns the current size of this canvas object.

func (*LinearGradient) Visible

func (o *LinearGradient) Visible() bool

Visible returns true if this object is visible, false otherwise.

type RadialGradient

type RadialGradient struct {
	StartColor color.Color // The beginning color of the gradient
	EndColor   color.Color // The end color of the gradient
	// The offset of the center for generation of the gradient.
	// This is not a DP measure but relates to the width/height.
	// A value of 0.5 would move the center by the half width/height.
	CenterOffsetX, CenterOffsetY float64
	// contains filtered or unexported fields
}

RadialGradient defines a Gradient travelling radially from a center point outward.

func NewRadialGradient

func NewRadialGradient(start, end color.Color) *RadialGradient

NewRadialGradient creates a new radial gradient.

func (*RadialGradient) Generate

func (g *RadialGradient) Generate(iw, ih int) image.Image

Generate calculates an image of the gradient with the specified width and height.

func (*RadialGradient) Hide

func (g *RadialGradient) Hide()

Hide will set this gradient to not be visible

func (*RadialGradient) MinSize

func (o *RadialGradient) MinSize() fyne.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*RadialGradient) Move

func (g *RadialGradient) Move(pos fyne.Position)

Move the gradient to a new position, relative to its parent / canvas

func (*RadialGradient) Position

func (o *RadialGradient) Position() fyne.Position

Position gets the current position of this canvas object, relative to its parent.

func (*RadialGradient) Refresh

func (g *RadialGradient) Refresh()

Refresh causes this gradient to be redrawn with its configured state.

func (*RadialGradient) Resize

func (o *RadialGradient) Resize(size fyne.Size)

Resize sets a new size for the canvas object.

func (*RadialGradient) SetMinSize

func (o *RadialGradient) SetMinSize(size fyne.Size)

SetMinSize specifies the smallest size this object should be.

func (*RadialGradient) Show

func (o *RadialGradient) Show()

Show will set this object to be visible.

func (*RadialGradient) Size

func (o *RadialGradient) Size() fyne.Size

Size returns the current size of this canvas object.

func (*RadialGradient) Visible

func (o *RadialGradient) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Raster

type Raster struct {

	// Render the raster image from code
	Generator func(w, h int) image.Image

	// Set a translucency value > 0.0 to fade the raster
	Translucency float64
	// Specify the type of scaling interpolation applied to the raster if it is not full-size
	// Since: 1.4.1
	ScaleMode ImageScale
	// contains filtered or unexported fields
}

Raster describes a raster image area that can render in a Fyne canvas

func NewRaster

func NewRaster(generate func(w, h int) image.Image) *Raster

NewRaster returns a new Image instance that is rendered dynamically using the specified generate function. Images returned from this method should draw dynamically to fill the width and height parameters passed to pixelColor.

func NewRasterFromImage

func NewRasterFromImage(img image.Image) *Raster

NewRasterFromImage returns a new Raster instance that is rendered from the Go image.Image passed in. Rasters returned from this method will map pixel for pixel to the screen starting img.Bounds().Min pixels from the top left of the canvas object. Truncates rather than scales the image. If smaller than the target space, the image will be padded with zero-pixels to the target size.

func NewRasterWithPixels

func NewRasterWithPixels(pixelColor func(x, y, w, h int) color.Color) *Raster

NewRasterWithPixels returns a new Image instance that is rendered dynamically by iterating over the specified pixelColor function for each x, y pixel. Images returned from this method should draw dynamically to fill the width and height parameters passed to pixelColor.

func (*Raster) Alpha

func (r *Raster) Alpha() float64

Alpha is a convenience function that returns the alpha value for a raster based on its Translucency value. The result is 1.0 - Translucency.

func (*Raster) Hide

func (r *Raster) Hide()

Hide will set this raster to not be visible

func (*Raster) MinSize

func (o *Raster) MinSize() fyne.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Raster) Move

func (r *Raster) Move(pos fyne.Position)

Move the raster to a new position, relative to its parent / canvas

func (*Raster) Position

func (o *Raster) Position() fyne.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Raster) Refresh

func (r *Raster) Refresh()

Refresh causes this raster to be redrawn with its configured state.

func (*Raster) Resize

func (r *Raster) Resize(s fyne.Size)

Resize on a raster image causes the new size to be set and then calls Refresh. This causes the underlying data to be recalculated and a new output to be drawn.

func (*Raster) SetMinSize

func (o *Raster) SetMinSize(size fyne.Size)

SetMinSize specifies the smallest size this object should be.

func (*Raster) Show

func (o *Raster) Show()

Show will set this object to be visible.

func (*Raster) Size

func (o *Raster) Size() fyne.Size

Size returns the current size of this canvas object.

func (*Raster) Visible

func (o *Raster) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Rectangle

type Rectangle struct {
	FillColor   color.Color // The rectangle fill color
	StrokeColor color.Color // The rectangle stroke color
	StrokeWidth float32     // The stroke width of the rectangle
	// The radius of the rectangle corners
	//
	// Since: 2.4
	CornerRadius float32
	// contains filtered or unexported fields
}

Rectangle describes a colored rectangle primitive in a Fyne canvas

func NewRectangle

func NewRectangle(color color.Color) *Rectangle

NewRectangle returns a new Rectangle instance

func (*Rectangle) Hide

func (r *Rectangle) Hide()

Hide will set this rectangle to not be visible

func (*Rectangle) MinSize

func (o *Rectangle) MinSize() fyne.Size

MinSize returns the specified minimum size, if set, or {1, 1} otherwise.

func (*Rectangle) Move

func (r *Rectangle) Move(pos fyne.Position)

Move the rectangle to a new position, relative to its parent / canvas

func (*Rectangle) Position

func (o *Rectangle) Position() fyne.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Rectangle) Refresh

func (r *Rectangle) Refresh()

Refresh causes this rectangle to be redrawn with its configured state.

func (*Rectangle) Resize

func (r *Rectangle) Resize(s fyne.Size)

Resize on a rectangle updates the new size of this object. If it has a stroke width this will cause it to Refresh.

func (*Rectangle) SetMinSize

func (o *Rectangle) SetMinSize(size fyne.Size)

SetMinSize specifies the smallest size this object should be.

func (*Rectangle) Show

func (o *Rectangle) Show()

Show will set this object to be visible.

func (*Rectangle) Size

func (o *Rectangle) Size() fyne.Size

Size returns the current size of this canvas object.

func (*Rectangle) Visible

func (o *Rectangle) Visible() bool

Visible returns true if this object is visible, false otherwise.

type Text

type Text struct {
	Alignment fyne.TextAlign // The alignment of the text content

	Color     color.Color    // The main text draw color
	Text      string         // The string content of this Text
	TextSize  float32        // Size of the text - if the Canvas scale is 1.0 this will be equivalent to point size
	TextStyle fyne.TextStyle // The style of the text content
	// contains filtered or unexported fields
}

Text describes a text primitive in a Fyne canvas. A text object can have a style set which will apply to the whole string. No formatting or text parsing will be performed

func NewText

func NewText(text string, color color.Color) *Text

NewText returns a new Text implementation

func (*Text) Hide

func (t *Text) Hide()

Hide will set this text to not be visible

func (*Text) MinSize

func (t *Text) MinSize() fyne.Size

MinSize returns the minimum size of this text object based on its font size and content. This is normally determined by the render implementation.

func (*Text) Move

func (t *Text) Move(pos fyne.Position)

Move the text to a new position, relative to its parent / canvas

func (*Text) Position

func (o *Text) Position() fyne.Position

Position gets the current position of this canvas object, relative to its parent.

func (*Text) Refresh

func (t *Text) Refresh()

Refresh causes this text to be redrawn with its configured state.

func (*Text) Resize

func (t *Text) Resize(s fyne.Size)

Resize on a text updates the new size of this object, which may not result in a visual change, depending on alignment.

func (*Text) SetMinSize

func (t *Text) SetMinSize(fyne.Size)

SetMinSize has no effect as the smallest size this canvas object can be is based on its font size and content.

func (*Text) Show

func (o *Text) Show()

Show will set this object to be visible.

func (*Text) Size

func (o *Text) Size() fyne.Size

Size returns the current size of this canvas object.

func (*Text) Visible

func (o *Text) Visible() bool

Visible returns true if this object is visible, false otherwise.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL