~eliasnaur/gio

ref: b981ccf9eda43816ae9d809466fe96c8e0c2475b gio/ui/widget/image.go -rw-r--r-- 652 bytes
b981ccf9Elias Naur ui/input: support single stepping through events 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: Unlicense OR MIT

package widget

import (
	"image"

	"gioui.org/ui"
	"gioui.org/ui/draw"
	"gioui.org/ui/f32"
	"gioui.org/ui/layout"
)

type Image struct {
	Src  image.Image
	Rect image.Rectangle
}

func (im Image) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
	d := image.Point{X: cs.Width.Max, Y: cs.Height.Max}
	if d.X == ui.Inf {
		d.X = cs.Width.Min
	}
	if d.Y == ui.Inf {
		d.Y = cs.Height.Min
	}
	dr := f32.Rectangle{
		Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
	}
	draw.OpImage{Img: im.Src, Rect: im.Rect}.Add(ops)
	draw.OpDraw{Rect: dr}.Add(ops)
	return layout.Dimens{Size: d, Baseline: d.Y}
}