mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
0061c73a89
In preparation for an OpColor (and future OpGradient and similar). Label and Editor no longer take an explicit source image. They draw with the current image. Signed-off-by: Elias Naur <mail@eliasnaur.com>
34 lines
652 B
Go
34 lines
652 B
Go
// 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}
|
|
}
|