CanvasView

Canvas shapes

Canvas text

Type of a view that allows to draw on it using a custom drawing function. This is useful for creating custom visual elements or components with complex shapes and designs. The "draw-function" property sets a drawing function that gets called every time the view needs to be redrawn. This function receives a Canvas object as an argument, which provides various methods for customizing styles, text, and drawing. The coordinates and sizes are specified in pixels only

Create from source

func NewCanvasView(session Session, params Params) CanvasView

Create the new custom draw view and returns its interface

Create from resource

CanvasView {
    id = canvasView,
    width = 100%,
    height = 100%,
}

Interface description

Inherit methods, properties and events from View

Redraw()

Force CanvasView to redraw its content

Properties

"draw-function"

Property sets the draw function of CanvasView

Constant: DrawFunction

Types: func(Canvas)

Examples

var image rui.Image

func imageCanvasDemo(canvas rui.Canvas) {
    if image != nil {
        canvas.DrawImage(50, 20, image)
    } else {
        image = rui.LoadImage("image.svg", func(img rui.Image) {
            if img.LoadingStatus() == rui.ImageReady {
                canvas.View().Redraw()
            }
        }, canvas.View().Session())
    }
}
canvas := rui.NewCanvasView(session, rui.Params{
    rui.Width:        rui.Percent(100),
    rui.Height:       rui.Percent(100),
    rui.DrawFunction: imageCanvasDemo,
})
func CanvasViewByID(rootView View, id string) CanvasView

Return a CanvasView with id equal to the argument of the function or nil if there is no such View or View is not a CanvasView

func RedrawCanvasView(rootView View, canvasViewID string)

Finds CanvasView with canvasViewID and redraws it

func LoadImage(url string, onLoaded func(Image), session Session) Image

Starts the async image loading by url