Compare commits

..

7 Commits

9 changed files with 26 additions and 29 deletions

View File

@ -20,8 +20,8 @@ func (t *texture) Destroy() error {
return nil return nil
} }
func (t *texture) Height() int { func (t *texture) Height() float32 {
return t.bmp.Height() return float32(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() int { func (t *texture) Width() float32 {
return t.bmp.Width() return float32(t.bmp.Width())
} }

View File

@ -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() int { return r.Size().Y } func (r *Renderer) Height() float32 { return r.Size().Y }
func (r *Renderer) Width() int { return r.Size().X } func (r *Renderer) Width() float32 { return r.Size().X }

View File

@ -5,6 +5,7 @@ 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"
) )
@ -20,12 +21,12 @@ type Texture struct {
var _ ui.Texture = &Texture{} var _ ui.Texture = &Texture{}
func (t *Texture) Height() int { func (t *Texture) Height() float32 {
_, _, _, height, err := t.Texture.Query() _, _, _, height, err := t.Texture.Query()
if err != nil { if err != nil {
return -1 return geom.NaN32()
} }
return int(height) return float32(height)
} }
func (t *Texture) Native() *sdl.Texture { return t.Texture } func (t *Texture) Native() *sdl.Texture { return t.Texture }
@ -43,12 +44,12 @@ func (t *Texture) Size() (int32, int32, error) {
return width, height, err return width, height, err
} }
func (t *Texture) Width() int { func (t *Texture) Width() float32 {
_, _, width, _, err := t.Texture.Query() _, _, width, _, err := t.Texture.Query()
if err != nil { if err != nil {
return -1 return geom.NaN32()
} }
return int(width) return float32(width)
} }
var _ ui.ImageSource = &TextureImageSource{} var _ ui.ImageSource = &TextureImageSource{}

View File

@ -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 := float32(icon.Width()), float32(icon.Height()) iconW, iconH := icon.Width(), 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).ToF32(), iconH) _, iconW = ScaleToHeight(SizeOfTexture(icon), iconH)
} }
iconOffsetY = .5 * (boundsH - iconH) iconOffsetY = .5 * (boundsH - iconH)
} }

View File

@ -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).ToF32(), h) _, iconWidth := ScaleToHeight(SizeOfTexture(icon), 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).ToF32(), boundsH) _, iconWidth := ScaleToHeight(SizeOfTexture(scaledIcon), 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

View File

@ -91,18 +91,16 @@ func (o *debugOverlay) renderControl(ctx Context, control Control) {
return return
} }
defer nameTexture.Destroy() defer nameTexture.Destroy()
nameTextureWidth := float32(nameTexture.Width()) renderer.FillRectangle(pos.RectRel2D(nameTexture.Width(), nameTexture.Height()), color.Black)
nameTextureHeight := float32(nameTexture.Height())
renderer.FillRectangle(pos.RectRel2D(nameTextureWidth, nameTextureHeight), color.Black)
renderer.DrawTexturePoint(nameTexture, pos) renderer.DrawTexturePoint(nameTexture, pos)
childPos := pos.Add2D(nameTextureWidth+ctx.Style().Dimensions.Margin, 0) childPos := pos.Add2D(nameTexture.Width()+8, 0)
for _, child := range node.Children { for _, child := range node.Children {
if childPos.Y == maxY { if childPos.Y == maxY {
childPos.Y = maxY + nameTextureHeight childPos.Y = maxY + nameTexture.Height()
} }
renderHoverNode(childPos, child) renderHoverNode(childPos, child)
maxY = childPos.Y maxY = childPos.Y
childPos.Y += nameTextureHeight + ctx.Style().Dimensions.Margin childPos.Y += nameTexture.Height() + 8
} }
} }
renderHoverNode(geom.PtF32(4, 4), o.hoverNodes) renderHoverNode(geom.PtF32(4, 4), o.hoverNodes)

View File

@ -12,7 +12,6 @@ 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
@ -68,7 +67,6 @@ 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.,

View File

@ -4,8 +4,8 @@ import "opslag.de/schobers/geom"
type Texture interface { type Texture interface {
Destroy() error Destroy() error
Height() int Height() float32
Width() int Width() float32
} }
func SizeOfTexture(t Texture) geom.Point { return geom.Pt(t.Width(), t.Height()) } func SizeOfTexture(t Texture) geom.PointF32 { return geom.PtF32(t.Width(), t.Height()) }

View File

@ -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(float32(texture.Width()) * scale) w := uint(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 / float32(texture.Height()) scale := height / texture.Height()
if geom.IsNaN32(scale) { if geom.IsNaN32(scale) {
return nil, 0 return nil, 0
} }