Compare commits

..

8 Commits

Author SHA1 Message Date
102c187566 Added generic margin. 2020-12-13 07:43:00 +01:00
11e37af9c2 Added shorthand method for retrieving default font for the control. 2020-12-13 07:40:58 +01:00
5babda0ca9 Added (optional) dropshadow for label. 2020-12-13 07:40:58 +01:00
b1cdbea90f Changed colors of button text a bit. 2020-12-13 07:40:58 +01:00
7d5168614e Added override for scrollbar color. 2020-12-13 07:40:58 +01:00
b0a13d1a3c ContainerBase now provides a DesiredSize (maximum of all children, if any). 2020-12-13 07:40:58 +01:00
cc32cf5bc3 Added scaled ImageSource. 2020-12-13 07:40:58 +01:00
0f03760e66 Added Resize & SetIcon to Renderer.
Refactored Size (on Renderer) to return geom.Point instead of geom.PointF32.
Refactored Width and Height (on Texture) to return int instead of float32.

Refactored texture dimensions to be represented by ints instead of float32s.
2020-12-13 07:40:19 +01:00
9 changed files with 29 additions and 26 deletions

View File

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

View File

@ -5,7 +5,6 @@ import (
"image/color"
"github.com/veandco/go-sdl2/sdl"
"opslag.de/schobers/geom"
"opslag.de/schobers/zntg/ui"
)
@ -21,12 +20,12 @@ type Texture struct {
var _ ui.Texture = &Texture{}
func (t *Texture) Height() float32 {
func (t *Texture) Height() int {
_, _, _, height, err := t.Texture.Query()
if err != nil {
return geom.NaN32()
return -1
}
return float32(height)
return int(height)
}
func (t *Texture) Native() *sdl.Texture { return t.Texture }
@ -44,12 +43,12 @@ func (t *Texture) Size() (int32, int32, error) {
return width, height, err
}
func (t *Texture) Width() float32 {
func (t *Texture) Width() int {
_, _, width, _, err := t.Texture.Query()
if err != nil {
return geom.NaN32()
return -1
}
return float32(width)
return int(width)
}
var _ ui.ImageSource = &TextureImageSource{}

View File

@ -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 := icon.Width(), icon.Height()
iconW, iconH := float32(icon.Width()), float32(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), iconH)
_, iconW = ScaleToHeight(SizeOfTexture(icon).ToF32(), 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)
}
icon := c.getOrCreateNormalIcon(ctx)
_, iconWidth := ScaleToHeight(SizeOfTexture(icon), h)
_, iconWidth := ScaleToHeight(SizeOfTexture(icon).ToF32(), 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), boundsH)
_, iconWidth := ScaleToHeight(SizeOfTexture(scaledIcon).ToF32(), boundsH)
rect := geom.RectRelF32(pos.X, pos.Y, iconWidth, boundsH)
ctx.Renderer().DrawTextureOptions(scaledIcon, rect, DrawOptions{Tint: iconColor})
pos.X += iconWidth + pad

View File

@ -91,16 +91,18 @@ func (o *debugOverlay) renderControl(ctx Context, control Control) {
return
}
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)
childPos := pos.Add2D(nameTexture.Width()+8, 0)
childPos := pos.Add2D(nameTextureWidth+ctx.Style().Dimensions.Margin, 0)
for _, child := range node.Children {
if childPos.Y == maxY {
childPos.Y = maxY + nameTexture.Height()
childPos.Y = maxY + nameTextureHeight
}
renderHoverNode(childPos, child)
maxY = childPos.Y
childPos.Y += nameTexture.Height() + 8
childPos.Y += nameTextureHeight + ctx.Style().Dimensions.Margin
}
}
renderHoverNode(geom.PtF32(4, 4), o.hoverNodes)

View File

@ -12,6 +12,7 @@ var defaultPalette *Palette
var defaultStyle *Style
type Dimensions struct {
Margin float32
OutlineWidth float32
ScrollbarWidth float32
TextPadding float32
@ -67,6 +68,7 @@ type Style struct {
func DefaultDimensions() *Dimensions {
return &Dimensions{
Margin: 8.,
OutlineWidth: 2.,
ScrollbarWidth: 16.,
TextPadding: 8.,

View File

@ -4,8 +4,8 @@ import "opslag.de/schobers/geom"
type Texture interface {
Destroy() error
Height() float32
Width() float32
Height() int
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()) }

View File

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