added gmath dependency
This commit is contained in:
parent
b832628da8
commit
3341553234
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module git.milar.in/milarin/gui
|
|||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
git.milar.in/milarin/gmath v0.0.3
|
||||||
github.com/hajimehoshi/ebiten v1.12.12
|
github.com/hajimehoshi/ebiten v1.12.12
|
||||||
github.com/hajimehoshi/ebiten/v2 v2.3.1
|
github.com/hajimehoshi/ebiten/v2 v2.3.1
|
||||||
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
|
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
|
||||||
|
2
go.sum
2
go.sum
@ -1,3 +1,5 @@
|
|||||||
|
git.milar.in/milarin/gmath v0.0.3 h1:ii6rKNItS55O/wtIFhD1cTN2BMwDZjTBmiOocKURvxM=
|
||||||
|
git.milar.in/milarin/gmath v0.0.3/go.mod h1:HDLftG5RLpiNGKiIWh+O2G1PYkNzyLDADO8Cd/1abiE=
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200707082815-5321531c36a2/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220320163800-277f93cfa958 h1:TL70PMkdPCt9cRhKTqsm+giRpgrd0IGEj763nNr2VFY=
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20220320163800-277f93cfa958 h1:TL70PMkdPCt9cRhKTqsm+giRpgrd0IGEj763nNr2VFY=
|
||||||
|
@ -1,23 +1,5 @@
|
|||||||
package views
|
package views
|
||||||
|
|
||||||
func min[T int | float64](x, y T) T {
|
|
||||||
if x < y {
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
return y
|
|
||||||
}
|
|
||||||
|
|
||||||
func max[T int | float64](x, y T) T {
|
|
||||||
if x > y {
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
return y
|
|
||||||
}
|
|
||||||
|
|
||||||
func limit[T int | float64](v, minv, maxv T) T {
|
|
||||||
return min(max(v, minv), maxv)
|
|
||||||
}
|
|
||||||
|
|
||||||
func iff[T any](condition bool, trueValue, falseValue T) T {
|
func iff[T any](condition bool, trueValue, falseValue T) T {
|
||||||
if condition {
|
if condition {
|
||||||
return trueValue
|
return trueValue
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package views
|
package views
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.milar.in/milarin/gmath"
|
||||||
"git.milar.in/milarin/gui"
|
"git.milar.in/milarin/gui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,13 +33,13 @@ func (v *ConstrainView) Layout(ctx gui.AppContext) (prefWidth, prefHeight int) {
|
|||||||
vw, vh := v.View().Layout(ctx)
|
vw, vh := v.View().Layout(ctx)
|
||||||
|
|
||||||
if v.MaxWidth >= 0 {
|
if v.MaxWidth >= 0 {
|
||||||
prefWidth = iff(vw >= 0, min(vw, v.MaxWidth), v.MaxWidth)
|
prefWidth = iff(vw >= 0, gmath.Min(vw, v.MaxWidth), v.MaxWidth)
|
||||||
} else {
|
} else {
|
||||||
prefWidth = vw
|
prefWidth = vw
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.MaxHeight >= 0 {
|
if v.MaxHeight >= 0 {
|
||||||
prefHeight = iff(vh >= 0, min(vh, v.MaxHeight), v.MaxHeight)
|
prefHeight = iff(vh >= 0, gmath.Min(vh, v.MaxHeight), v.MaxHeight)
|
||||||
} else {
|
} else {
|
||||||
prefHeight = vh
|
prefHeight = vh
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.milar.in/milarin/gmath"
|
||||||
"git.milar.in/milarin/gui"
|
"git.milar.in/milarin/gui"
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
)
|
)
|
||||||
@ -130,10 +131,10 @@ func (v *ScrollView) Draw(img *gui.Image, ctx gui.AppContext) {
|
|||||||
|
|
||||||
func (v *ScrollView) limit() {
|
func (v *ScrollView) limit() {
|
||||||
if v.buf != nil {
|
if v.buf != nil {
|
||||||
v.targetOffset.Y = limit(v.targetOffset.Y, 0, max(v.buf.Bounds().Dy()-v.viewportHeight, 0))
|
v.targetOffset.Y = gmath.Clamp(v.targetOffset.Y, 0, gmath.Max(v.buf.Bounds().Dy()-v.viewportHeight, 0))
|
||||||
v.targetOffset.X = limit(v.targetOffset.X, 0, max(v.buf.Bounds().Dx()-v.viewportWidth, 0))
|
v.targetOffset.X = gmath.Clamp(v.targetOffset.X, 0, gmath.Max(v.buf.Bounds().Dx()-v.viewportWidth, 0))
|
||||||
v.VerticalScrollOffset = limit(v.VerticalScrollOffset, 0, float64(max(v.buf.Bounds().Dy()-v.viewportHeight, 0)))
|
v.VerticalScrollOffset = gmath.Clamp(v.VerticalScrollOffset, 0, float64(gmath.Max(v.buf.Bounds().Dy()-v.viewportHeight, 0)))
|
||||||
v.HorizontalScrollOffset = limit(v.HorizontalScrollOffset, 0, float64(max(v.buf.Bounds().Dx()-v.viewportWidth, 0)))
|
v.HorizontalScrollOffset = gmath.Clamp(v.HorizontalScrollOffset, 0, float64(gmath.Max(v.buf.Bounds().Dx()-v.viewportWidth, 0)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user