Compare commits
8 Commits
f3ce48a1ba
...
102c187566
Author | SHA1 | Date | |
---|---|---|---|
102c187566 | |||
11e37af9c2 | |||
5babda0ca9 | |||
b1cdbea90f | |||
7d5168614e | |||
b0a13d1a3c | |||
cc32cf5bc3 | |||
0f03760e66 |
@ -20,8 +20,8 @@ func (t *texture) Destroy() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *texture) Height() float32 {
|
func (t *texture) Height() int {
|
||||||
return float32(t.bmp.Height())
|
return t.bmp.Height()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *texture) CreateImage() (image.Image, error) {
|
func (t *texture) CreateImage() (image.Image, error) {
|
||||||
@ -31,6 +31,6 @@ func (t *texture) CreateImage() (image.Image, error) {
|
|||||||
return t.source.CreateImage()
|
return t.source.CreateImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *texture) Width() float32 {
|
func (t *texture) Width() int {
|
||||||
return float32(t.bmp.Width())
|
return t.bmp.Width()
|
||||||
}
|
}
|
||||||
|
@ -518,6 +518,6 @@ func (r *Renderer) SetResourceProvider(resources ui.Resources) {
|
|||||||
|
|
||||||
func (r *Renderer) Image() image.Image { return nil }
|
func (r *Renderer) Image() image.Image { return nil }
|
||||||
|
|
||||||
func (r *Renderer) Height() float32 { return r.Size().Y }
|
func (r *Renderer) Height() int { return r.Size().Y }
|
||||||
|
|
||||||
func (r *Renderer) Width() float32 { return r.Size().X }
|
func (r *Renderer) Width() int { return r.Size().X }
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/veandco/go-sdl2/sdl"
|
"github.com/veandco/go-sdl2/sdl"
|
||||||
"opslag.de/schobers/geom"
|
|
||||||
"opslag.de/schobers/zntg/ui"
|
"opslag.de/schobers/zntg/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,12 +20,12 @@ type Texture struct {
|
|||||||
|
|
||||||
var _ ui.Texture = &Texture{}
|
var _ ui.Texture = &Texture{}
|
||||||
|
|
||||||
func (t *Texture) Height() float32 {
|
func (t *Texture) Height() int {
|
||||||
_, _, _, height, err := t.Texture.Query()
|
_, _, _, height, err := t.Texture.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return geom.NaN32()
|
return -1
|
||||||
}
|
}
|
||||||
return float32(height)
|
return int(height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Texture) Native() *sdl.Texture { return t.Texture }
|
func (t *Texture) Native() *sdl.Texture { return t.Texture }
|
||||||
@ -44,12 +43,12 @@ func (t *Texture) Size() (int32, int32, error) {
|
|||||||
return width, height, err
|
return width, height, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Texture) Width() float32 {
|
func (t *Texture) Width() int {
|
||||||
_, _, width, _, err := t.Texture.Query()
|
_, _, width, _, err := t.Texture.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return geom.NaN32()
|
return -1
|
||||||
}
|
}
|
||||||
return float32(width)
|
return int(width)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ui.ImageSource = &TextureImageSource{}
|
var _ ui.ImageSource = &TextureImageSource{}
|
||||||
|
@ -71,7 +71,7 @@ func (b *Button) icon(ctx Context) (Texture, float32, float32) {
|
|||||||
return nil, 0, 0
|
return nil, 0, 0
|
||||||
}
|
}
|
||||||
icon := ctx.Textures().Texture(b.Icon)
|
icon := ctx.Textures().Texture(b.Icon)
|
||||||
iconW, iconH := icon.Width(), icon.Height()
|
iconW, iconH := float32(icon.Width()), float32(icon.Height())
|
||||||
if b.IconHeight != 0 {
|
if b.IconHeight != 0 {
|
||||||
iconW = b.IconHeight * iconW / iconH
|
iconW = b.IconHeight * iconW / iconH
|
||||||
iconH = b.IconHeight
|
iconH = b.IconHeight
|
||||||
@ -217,7 +217,7 @@ func (b *Button) Render(ctx Context) {
|
|||||||
if scaled != nil { // let the renderer scale
|
if scaled != nil { // let the renderer scale
|
||||||
icon = scaled
|
icon = scaled
|
||||||
}
|
}
|
||||||
_, iconW = ScaleToHeight(SizeOfTexture(icon), iconH)
|
_, iconW = ScaleToHeight(SizeOfTexture(icon).ToF32(), iconH)
|
||||||
}
|
}
|
||||||
iconOffsetY = .5 * (boundsH - iconH)
|
iconOffsetY = .5 * (boundsH - iconH)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func (c *Checkbox) desiredSize(ctx Context) geom.PointF32 {
|
|||||||
w += pad + font.WidthOf(c.Text)
|
w += pad + font.WidthOf(c.Text)
|
||||||
}
|
}
|
||||||
icon := c.getOrCreateNormalIcon(ctx)
|
icon := c.getOrCreateNormalIcon(ctx)
|
||||||
_, iconWidth := ScaleToHeight(SizeOfTexture(icon), h)
|
_, iconWidth := ScaleToHeight(SizeOfTexture(icon).ToF32(), h)
|
||||||
w += pad + iconWidth
|
w += pad + iconWidth
|
||||||
return geom.PtF32(w+pad, pad+h+pad)
|
return geom.PtF32(w+pad, pad+h+pad)
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ func (c *Checkbox) Render(ctx Context) {
|
|||||||
if scaledIcon == nil { // let the renderer scale
|
if scaledIcon == nil { // let the renderer scale
|
||||||
scaledIcon = icon
|
scaledIcon = icon
|
||||||
}
|
}
|
||||||
_, iconWidth := ScaleToHeight(SizeOfTexture(scaledIcon), boundsH)
|
_, iconWidth := ScaleToHeight(SizeOfTexture(scaledIcon).ToF32(), boundsH)
|
||||||
rect := geom.RectRelF32(pos.X, pos.Y, iconWidth, boundsH)
|
rect := geom.RectRelF32(pos.X, pos.Y, iconWidth, boundsH)
|
||||||
ctx.Renderer().DrawTextureOptions(scaledIcon, rect, DrawOptions{Tint: iconColor})
|
ctx.Renderer().DrawTextureOptions(scaledIcon, rect, DrawOptions{Tint: iconColor})
|
||||||
pos.X += iconWidth + pad
|
pos.X += iconWidth + pad
|
||||||
|
10
ui/debug.go
10
ui/debug.go
@ -91,16 +91,18 @@ func (o *debugOverlay) renderControl(ctx Context, control Control) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer nameTexture.Destroy()
|
defer nameTexture.Destroy()
|
||||||
renderer.FillRectangle(pos.RectRel2D(nameTexture.Width(), nameTexture.Height()), color.Black)
|
nameTextureWidth := float32(nameTexture.Width())
|
||||||
|
nameTextureHeight := float32(nameTexture.Height())
|
||||||
|
renderer.FillRectangle(pos.RectRel2D(nameTextureWidth, nameTextureHeight), color.Black)
|
||||||
renderer.DrawTexturePoint(nameTexture, pos)
|
renderer.DrawTexturePoint(nameTexture, pos)
|
||||||
childPos := pos.Add2D(nameTexture.Width()+8, 0)
|
childPos := pos.Add2D(nameTextureWidth+ctx.Style().Dimensions.Margin, 0)
|
||||||
for _, child := range node.Children {
|
for _, child := range node.Children {
|
||||||
if childPos.Y == maxY {
|
if childPos.Y == maxY {
|
||||||
childPos.Y = maxY + nameTexture.Height()
|
childPos.Y = maxY + nameTextureHeight
|
||||||
}
|
}
|
||||||
renderHoverNode(childPos, child)
|
renderHoverNode(childPos, child)
|
||||||
maxY = childPos.Y
|
maxY = childPos.Y
|
||||||
childPos.Y += nameTexture.Height() + 8
|
childPos.Y += nameTextureHeight + ctx.Style().Dimensions.Margin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
renderHoverNode(geom.PtF32(4, 4), o.hoverNodes)
|
renderHoverNode(geom.PtF32(4, 4), o.hoverNodes)
|
||||||
|
@ -12,6 +12,7 @@ var defaultPalette *Palette
|
|||||||
var defaultStyle *Style
|
var defaultStyle *Style
|
||||||
|
|
||||||
type Dimensions struct {
|
type Dimensions struct {
|
||||||
|
Margin float32
|
||||||
OutlineWidth float32
|
OutlineWidth float32
|
||||||
ScrollbarWidth float32
|
ScrollbarWidth float32
|
||||||
TextPadding float32
|
TextPadding float32
|
||||||
@ -67,6 +68,7 @@ type Style struct {
|
|||||||
|
|
||||||
func DefaultDimensions() *Dimensions {
|
func DefaultDimensions() *Dimensions {
|
||||||
return &Dimensions{
|
return &Dimensions{
|
||||||
|
Margin: 8.,
|
||||||
OutlineWidth: 2.,
|
OutlineWidth: 2.,
|
||||||
ScrollbarWidth: 16.,
|
ScrollbarWidth: 16.,
|
||||||
TextPadding: 8.,
|
TextPadding: 8.,
|
||||||
|
@ -4,8 +4,8 @@ import "opslag.de/schobers/geom"
|
|||||||
|
|
||||||
type Texture interface {
|
type Texture interface {
|
||||||
Destroy() error
|
Destroy() error
|
||||||
Height() float32
|
Height() int
|
||||||
Width() float32
|
Width() int
|
||||||
}
|
}
|
||||||
|
|
||||||
func SizeOfTexture(t Texture) geom.PointF32 { return geom.PtF32(t.Width(), t.Height()) }
|
func SizeOfTexture(t Texture) geom.Point { return geom.Pt(t.Width(), t.Height()) }
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ScaleTexture(render Renderer, texture Texture, scale float32) Texture {
|
func ScaleTexture(render Renderer, texture Texture, scale float32) Texture {
|
||||||
w := uint(texture.Width() * scale)
|
w := uint(float32(texture.Width()) * scale)
|
||||||
if w == 0 {
|
if w == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ func (t *Textures) Scaled(texture Texture, scale float32) Texture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Textures) ScaledHeight(texture Texture, height float32) (Texture, float32) {
|
func (t *Textures) ScaledHeight(texture Texture, height float32) (Texture, float32) {
|
||||||
scale := height / texture.Height()
|
scale := height / float32(texture.Height())
|
||||||
if geom.IsNaN32(scale) {
|
if geom.IsNaN32(scale) {
|
||||||
return nil, 0
|
return nil, 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user