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