Use float32 in ui package.
This commit is contained in:
parent
ad697d5508
commit
23ce18b51b
@ -19,19 +19,19 @@ func NewButtonAlign(text string, click MouseClickFn, align allg5.HorizontalAlign
|
|||||||
return &Button{ControlBase: ControlBase{OnClick: click}, Text: text, HorizontalAlignment: align}
|
return &Button{ControlBase: ControlBase{OnClick: click}, Text: text, HorizontalAlignment: align}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Button) DesiredSize(ctx Context) geom.PointF {
|
func (b *Button) DesiredSize(ctx Context) geom.PointF32 {
|
||||||
var fonts = ctx.Fonts()
|
var fonts = ctx.Fonts()
|
||||||
var fnt = fonts.Get("default")
|
var fnt = fonts.Get("default")
|
||||||
var w = fnt.TextWidth(b.Text)
|
var w = fnt.TextWidth(b.Text)
|
||||||
var fntH = fnt.Height()
|
var fntH = fnt.Height()
|
||||||
return geom.PtF(float64(w+fntH), float64(2*fntH))
|
return geom.PtF32(w+fntH, 2*fntH)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Button) Render(ctx Context) {
|
func (b *Button) Render(ctx Context) {
|
||||||
var fonts = ctx.Fonts()
|
var fonts = ctx.Fonts()
|
||||||
|
|
||||||
var min = b.Bounds.Min.To32()
|
var min = b.Bounds.Min
|
||||||
var max = b.Bounds.Max.To32()
|
var max = b.Bounds.Max
|
||||||
|
|
||||||
var fnt = fonts.Get("default")
|
var fnt = fonts.Get("default")
|
||||||
var fntH = fnt.Height()
|
var fntH = fnt.Height()
|
||||||
|
@ -14,8 +14,8 @@ type CheckboxValueChangedFn func(bool)
|
|||||||
|
|
||||||
func drawCheckedBitmap(fill, stroke color.Color) *allg5.Bitmap {
|
func drawCheckedBitmap(fill, stroke color.Color) *allg5.Bitmap {
|
||||||
return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) {
|
return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) {
|
||||||
var size = float64(checkboxSize)
|
var size float64 = checkboxSize
|
||||||
var margin = float64(checkboxMargin)
|
var margin float64 = checkboxMargin
|
||||||
|
|
||||||
gc.SetFillColor(fill)
|
gc.SetFillColor(fill)
|
||||||
draw2dkit.RoundedRectangle(gc, margin, margin, size-margin, size-margin, margin, margin)
|
draw2dkit.RoundedRectangle(gc, margin, margin, size-margin, size-margin, margin, margin)
|
||||||
@ -32,8 +32,8 @@ func drawCheckedBitmap(fill, stroke color.Color) *allg5.Bitmap {
|
|||||||
|
|
||||||
func drawUncheckedBitmap(fill, stroke color.Color) *allg5.Bitmap {
|
func drawUncheckedBitmap(fill, stroke color.Color) *allg5.Bitmap {
|
||||||
return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) {
|
return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) {
|
||||||
var size = float64(checkboxSize)
|
var size float64 = checkboxSize
|
||||||
var margin = float64(checkboxMargin)
|
var margin float64 = checkboxMargin
|
||||||
|
|
||||||
gc.SetLineWidth(2)
|
gc.SetLineWidth(2)
|
||||||
gc.SetStrokeColor(stroke)
|
gc.SetStrokeColor(stroke)
|
||||||
@ -80,11 +80,11 @@ func (c *Checkbox) Handle(ctx Context, ev allg5.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checkbox) DesiredSize(ctx Context) geom.PointF {
|
func (c *Checkbox) DesiredSize(ctx Context) geom.PointF32 {
|
||||||
var fonts = ctx.Fonts()
|
var fonts = ctx.Fonts()
|
||||||
var fnt = fonts.Get("default")
|
var fnt = fonts.Get("default")
|
||||||
var w = fnt.TextWidth(c.Text)
|
var w = fnt.TextWidth(c.Text)
|
||||||
return geom.PtF(float64(w+checkboxSize), checkboxSize)
|
return geom.PtF32(w+checkboxSize, checkboxSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Checkbox) box() *allg5.Bitmap {
|
func (c *Checkbox) box() *allg5.Bitmap {
|
||||||
@ -97,7 +97,7 @@ func (c *Checkbox) box() *allg5.Bitmap {
|
|||||||
func (c *Checkbox) Render(ctx Context) {
|
func (c *Checkbox) Render(ctx Context) {
|
||||||
var fonts = ctx.Fonts()
|
var fonts = ctx.Fonts()
|
||||||
|
|
||||||
var min = c.Bounds.Min.To32()
|
var min = c.Bounds.Min
|
||||||
var fnt = fonts.Get("default")
|
var fnt = fonts.Get("default")
|
||||||
|
|
||||||
fnt.Draw(min.X+checkboxSize, min.Y-.67*fnt.Ascent()+.5*checkboxSize, ctx.Palette().Darkest(), allg5.AlignLeft, c.Text)
|
fnt.Draw(min.X+checkboxSize, min.Y-.67*fnt.Ascent()+.5*checkboxSize, ctx.Palette().Darkest(), allg5.AlignLeft, c.Text)
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -75,40 +73,40 @@ func (c *columns) AppendCreate(ctx Context, ctrl Control) {
|
|||||||
c.next()
|
c.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *columns) DesiredSize(ctx Context) geom.PointF {
|
func (c *columns) DesiredSize(ctx Context) geom.PointF32 {
|
||||||
var w float64
|
var w float32
|
||||||
var h float64
|
var h float32
|
||||||
for _, col := range c.cols {
|
for _, col := range c.cols {
|
||||||
var sz = col.p.DesiredSize(ctx)
|
var sz = col.p.DesiredSize(ctx)
|
||||||
if !math.IsNaN(w) {
|
if !geom.IsNaN32(w) {
|
||||||
if math.IsNaN(sz.X) {
|
if geom.IsNaN32(sz.X) {
|
||||||
w = sz.X
|
w = sz.X
|
||||||
} else {
|
} else {
|
||||||
w += sz.X
|
w += sz.X
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !math.IsNaN(h) {
|
if !geom.IsNaN32(h) {
|
||||||
if math.IsNaN(sz.Y) {
|
if geom.IsNaN32(sz.Y) {
|
||||||
h = sz.Y
|
h = sz.Y
|
||||||
} else {
|
} else {
|
||||||
h = math.Max(h, sz.Y)
|
h = geom.Max32(h, sz.Y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return geom.PtF(w, h)
|
return geom.PtF32(w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *columns) Arrange(ctx Context, rect geom.RectangleF) {
|
func (c *columns) Arrange(ctx Context, rect geom.RectangleF32) {
|
||||||
c.ContainerBase.SetRect(rect)
|
c.ContainerBase.SetRect(rect)
|
||||||
var w, h = rect.Dx(), rect.Dy()
|
var w, h = rect.Dx(), rect.Dy()
|
||||||
var cols = float64(len(c.cols))
|
var cols = float32(len(c.cols))
|
||||||
for i, col := range c.cols {
|
for i, col := range c.cols {
|
||||||
var ii = float64(i)
|
var ii = float32(i)
|
||||||
var colH = col.p.DesiredSize(ctx).Y
|
var colH = col.p.DesiredSize(ctx).Y
|
||||||
if colH > h {
|
if colH > h {
|
||||||
colH = h
|
colH = h
|
||||||
}
|
}
|
||||||
var colR = geom.RectF(rect.Min.X+ii*w/cols, rect.Min.Y, rect.Min.X+(ii+1)*w/cols, rect.Min.Y+colH)
|
var colR = geom.RectF32(rect.Min.X+ii*w/cols, rect.Min.Y, rect.Min.X+(ii+1)*w/cols, rect.Min.Y+colH)
|
||||||
Arrange(ctx, col.p, colR)
|
Arrange(ctx, col.p, colR)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
type Container interface {
|
type Container interface {
|
||||||
Control
|
Control
|
||||||
Children() []Control
|
Children() []Control
|
||||||
Arrange(Context, geom.RectangleF)
|
Arrange(Context, geom.RectangleF32)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContainer(parent Container, children ...Control) *ContainerBase {
|
func NewContainer(parent Container, children ...Control) *ContainerBase {
|
||||||
@ -28,7 +28,7 @@ func (c *ContainerBase) Children() []Control {
|
|||||||
return c.children
|
return c.children
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ContainerBase) Arrange(ctx Context, rect geom.RectangleF) {
|
func (c *ContainerBase) Arrange(ctx Context, rect geom.RectangleF32) {
|
||||||
c.ControlBase.SetRect(rect)
|
c.ControlBase.SetRect(rect)
|
||||||
for _, child := range c.children {
|
for _, child := range c.children {
|
||||||
Arrange(ctx, child, rect)
|
Arrange(ctx, child, rect)
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
"opslag.de/schobers/zntg/allg5"
|
"opslag.de/schobers/zntg/allg5"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Control = &ContentScrollbar{}
|
var _ Control = &ContentScrollbar{}
|
||||||
|
|
||||||
type ContentScrollbarValueChangedFn func(float64)
|
type ContentScrollbarValueChangedFn func(float32)
|
||||||
|
|
||||||
type ContentScrollbar struct {
|
type ContentScrollbar struct {
|
||||||
ControlBase
|
ControlBase
|
||||||
Length float64
|
Length float32
|
||||||
Value float64
|
Value float32
|
||||||
Orientation Orientation
|
Orientation Orientation
|
||||||
OnChanged ContentScrollbarValueChangedFn
|
OnChanged ContentScrollbarValueChangedFn
|
||||||
handle *contentScrollbarHandle
|
handle *contentScrollbarHandle
|
||||||
barLength float64
|
barLength float32
|
||||||
scrollDistance float64
|
scrollDistance float32
|
||||||
}
|
}
|
||||||
|
|
||||||
type contentScrollbarHandle struct {
|
type contentScrollbarHandle struct {
|
||||||
@ -33,8 +31,8 @@ func (h *contentScrollbarHandle) Render(ctx Context) {
|
|||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var min = h.Bounds.Min.To32()
|
var min = h.Bounds.Min
|
||||||
var max = h.Bounds.Max.To32()
|
var max = h.Bounds.Max
|
||||||
allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, c)
|
allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,8 +47,8 @@ func (s *ContentScrollbar) Destroyed(ctx Context) {
|
|||||||
s.handle.Destroyed(ctx)
|
s.handle.Destroyed(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContentScrollbar) length() (float64, float64) {
|
func (s *ContentScrollbar) length() (float32, float32) {
|
||||||
var min, max float64
|
var min, max float32
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
min = s.Bounds.Min.X
|
min = s.Bounds.Min.X
|
||||||
@ -83,7 +81,7 @@ func (s *ContentScrollbar) updateBarLength() {
|
|||||||
s.scrollDistance = d
|
s.scrollDistance = d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContentScrollbar) barViewCenter() float64 {
|
func (s *ContentScrollbar) barViewCenter() float32 {
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
return (s.Bounds.Min.Y + s.Bounds.Max.Y) * .5
|
return (s.Bounds.Min.Y + s.Bounds.Max.Y) * .5
|
||||||
@ -92,7 +90,7 @@ func (s *ContentScrollbar) barViewCenter() float64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContentScrollbar) toValue(x, y float64) float64 {
|
func (s *ContentScrollbar) toValue(x, y float32) float32 {
|
||||||
var pos = y
|
var pos = y
|
||||||
if OrientationHorizontal == s.Orientation {
|
if OrientationHorizontal == s.Orientation {
|
||||||
pos = x
|
pos = x
|
||||||
@ -110,7 +108,7 @@ func (s *ContentScrollbar) toValue(x, y float64) float64 {
|
|||||||
return s.scrollDistance * offset
|
return s.scrollDistance * offset
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContentScrollbar) change(v float64) {
|
func (s *ContentScrollbar) change(v float32) {
|
||||||
if v != s.Value {
|
if v != s.Value {
|
||||||
s.Value = v
|
s.Value = v
|
||||||
var onChanged = s.OnChanged
|
var onChanged = s.OnChanged
|
||||||
@ -121,7 +119,7 @@ func (s *ContentScrollbar) change(v float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContentScrollbar) snapTo(x, y int) {
|
func (s *ContentScrollbar) snapTo(x, y int) {
|
||||||
var val = s.toValue(float64(x), float64(y))
|
var val = s.toValue(float32(x), float32(y))
|
||||||
s.change(val)
|
s.change(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +127,7 @@ func (s *ContentScrollbar) increment(d int) {
|
|||||||
if s.Orientation == OrientationVertical {
|
if s.Orientation == OrientationVertical {
|
||||||
d *= -1
|
d *= -1
|
||||||
}
|
}
|
||||||
var val = s.Value + float64(d)*ScrollbarWidth
|
var val = s.Value + float32(d)*ScrollbarWidth
|
||||||
if val < 0 {
|
if val < 0 {
|
||||||
val = 0
|
val = 0
|
||||||
} else if val > s.scrollDistance {
|
} else if val > s.scrollDistance {
|
||||||
@ -160,15 +158,15 @@ func (s *ContentScrollbar) Handle(ctx Context, ev allg5.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContentScrollbar) DesiredSize(Context) geom.PointF {
|
func (s *ContentScrollbar) DesiredSize(Context) geom.PointF32 {
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
return geom.PtF(math.NaN(), ScrollbarWidth)
|
return geom.PtF32(geom.NaN32(), ScrollbarWidth)
|
||||||
}
|
}
|
||||||
return geom.PtF(ScrollbarWidth, math.NaN())
|
return geom.PtF32(ScrollbarWidth, geom.NaN32())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ContentScrollbar) SetRect(rect geom.RectangleF) {
|
func (s *ContentScrollbar) SetRect(rect geom.RectangleF32) {
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
if rect.Dy() > ScrollbarWidth {
|
if rect.Dy() > ScrollbarWidth {
|
||||||
@ -182,7 +180,7 @@ func (s *ContentScrollbar) SetRect(rect geom.RectangleF) {
|
|||||||
s.ControlBase.SetRect(rect)
|
s.ControlBase.SetRect(rect)
|
||||||
s.updateBarLength()
|
s.updateBarLength()
|
||||||
|
|
||||||
var offset float64
|
var offset float32
|
||||||
if 0 < s.scrollDistance {
|
if 0 < s.scrollDistance {
|
||||||
offset = s.Value / s.scrollDistance
|
offset = s.Value / s.scrollDistance
|
||||||
}
|
}
|
||||||
@ -191,9 +189,9 @@ func (s *ContentScrollbar) SetRect(rect geom.RectangleF) {
|
|||||||
var end = begin + s.barLength
|
var end = begin + s.barLength
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
s.handle.SetRect(geom.RectF(begin, rect.Min.Y, end, rect.Max.Y))
|
s.handle.SetRect(geom.RectF32(begin, rect.Min.Y, end, rect.Max.Y))
|
||||||
default:
|
default:
|
||||||
s.handle.SetRect(geom.RectF(rect.Min.X, begin, rect.Max.X, end))
|
s.handle.SetRect(geom.RectF32(rect.Min.X, begin, rect.Max.X, end))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@ package ui
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"opslag.de/schobers/zntg/allg5"
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
|
"opslag.de/schobers/zntg/allg5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Control interface {
|
type Control interface {
|
||||||
@ -13,9 +13,9 @@ type Control interface {
|
|||||||
|
|
||||||
Update(Context, time.Duration)
|
Update(Context, time.Duration)
|
||||||
Handle(Context, allg5.Event)
|
Handle(Context, allg5.Event)
|
||||||
DesiredSize(Context) geom.PointF
|
DesiredSize(Context) geom.PointF32
|
||||||
Rect() geom.RectangleF
|
Rect() geom.RectangleF32
|
||||||
SetRect(geom.RectangleF)
|
SetRect(geom.RectangleF32)
|
||||||
Render(Context)
|
Render(Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,12 +25,12 @@ var _ Control = &ControlBase{}
|
|||||||
|
|
||||||
type ControlBase struct {
|
type ControlBase struct {
|
||||||
Parent Container
|
Parent Container
|
||||||
Bounds geom.RectangleF
|
Bounds geom.RectangleF32
|
||||||
Disabled bool
|
Disabled bool
|
||||||
IsOver bool
|
IsOver bool
|
||||||
IsPressed bool
|
IsPressed bool
|
||||||
OnClick MouseClickFn
|
OnClick MouseClickFn
|
||||||
MinSize geom.PointF
|
MinSize geom.PointF32
|
||||||
Background *allg5.Color
|
Background *allg5.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ func (c *ControlBase) Update(Context, time.Duration) {}
|
|||||||
func (c *ControlBase) Handle(ctx Context, ev allg5.Event) {
|
func (c *ControlBase) Handle(ctx Context, ev allg5.Event) {
|
||||||
switch e := ev.(type) {
|
switch e := ev.(type) {
|
||||||
case *allg5.MouseMoveEvent:
|
case *allg5.MouseMoveEvent:
|
||||||
c.IsOver = c.IsInRect(float64(e.X), float64(e.Y))
|
c.IsOver = c.IsInRect(float32(e.X), float32(e.Y))
|
||||||
case *allg5.MouseButtonDownEvent:
|
case *allg5.MouseButtonDownEvent:
|
||||||
if c.IsOver {
|
if c.IsOver {
|
||||||
c.IsPressed = true
|
c.IsPressed = true
|
||||||
@ -62,17 +62,17 @@ func (c *ControlBase) Handle(ctx Context, ev allg5.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ControlBase) DesiredSize(Context) geom.PointF {
|
func (c *ControlBase) DesiredSize(Context) geom.PointF32 {
|
||||||
return c.MinSize
|
return c.MinSize
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ControlBase) SetRect(rect geom.RectangleF) {
|
func (c *ControlBase) SetRect(rect geom.RectangleF32) {
|
||||||
c.Bounds = rect
|
c.Bounds = rect
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ControlBase) Render(ctx Context) {
|
func (c *ControlBase) Render(ctx Context) {
|
||||||
var min = c.Bounds.Min.To32()
|
var min = c.Bounds.Min
|
||||||
var max = c.Bounds.Max.To32()
|
var max = c.Bounds.Max
|
||||||
if nil != c.Background {
|
if nil != c.Background {
|
||||||
allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, *c.Background)
|
allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, *c.Background)
|
||||||
}
|
}
|
||||||
@ -81,10 +81,10 @@ func (c *ControlBase) Render(ctx Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ControlBase) Rect() geom.RectangleF {
|
func (c *ControlBase) Rect() geom.RectangleF32 {
|
||||||
return c.Bounds
|
return c.Bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ControlBase) IsInRect(x, y float64) bool {
|
func (c *ControlBase) IsInRect(x, y float32) bool {
|
||||||
return geom.PtF(x, y).In(c.Bounds)
|
return geom.PtF32(x, y).In(c.Bounds)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,42 +55,42 @@ func (p *dockPanel) AppendCreate(ctx Context, d Dock, children ...Control) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *dockPanel) DesiredSize(ctx Context) geom.PointF {
|
func (p *dockPanel) DesiredSize(ctx Context) geom.PointF32 {
|
||||||
var width, height float64 = 0, 0
|
var width, height float32 = 0, 0
|
||||||
for i, child := range p.children {
|
for i, child := range p.children {
|
||||||
var d = p.docks[i]
|
var d = p.docks[i]
|
||||||
var desired = child.DesiredSize(ctx)
|
var desired = child.DesiredSize(ctx)
|
||||||
switch {
|
switch {
|
||||||
case d == DockLeft || d == DockRight:
|
case d == DockLeft || d == DockRight:
|
||||||
if !math.IsNaN(width) {
|
if !geom.IsNaN32(width) {
|
||||||
if math.IsNaN(desired.X) {
|
if geom.IsNaN32(desired.X) {
|
||||||
width = desired.X
|
width = desired.X
|
||||||
} else {
|
} else {
|
||||||
width += desired.X
|
width += desired.X
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !math.IsNaN(desired.Y) {
|
if !geom.IsNaN32(desired.Y) {
|
||||||
height = math.Max(height, desired.Y)
|
height = geom.Max32(height, desired.Y)
|
||||||
}
|
}
|
||||||
case d == DockTop || d == DockBottom:
|
case d == DockTop || d == DockBottom:
|
||||||
if !math.IsNaN(height) {
|
if !geom.IsNaN32(height) {
|
||||||
if math.IsNaN(desired.Y) {
|
if geom.IsNaN32(desired.Y) {
|
||||||
height = desired.Y
|
height = desired.Y
|
||||||
} else {
|
} else {
|
||||||
height += desired.Y
|
height += desired.Y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !math.IsNaN(desired.X) {
|
if !geom.IsNaN32(desired.X) {
|
||||||
width = math.Max(width, desired.X)
|
width = geom.Max32(width, desired.X)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return geom.PtF(width, height)
|
return geom.PtF32(width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *dockPanel) arrangeChildren(ctx Context) []geom.RectangleF {
|
func (p *dockPanel) arrangeChildren(ctx Context) []geom.RectangleF32 {
|
||||||
var n = len(p.children)
|
var n = len(p.children)
|
||||||
var rects = make([]geom.RectangleF, n)
|
var rects = make([]geom.RectangleF32, n)
|
||||||
|
|
||||||
var rem = p.Bounds
|
var rem = p.Bounds
|
||||||
var last = n - 1
|
var last = n - 1
|
||||||
@ -102,12 +100,12 @@ func (p *dockPanel) arrangeChildren(ctx Context) []geom.RectangleF {
|
|||||||
} else {
|
} else {
|
||||||
var d = p.docks[i]
|
var d = p.docks[i]
|
||||||
var desired = child.DesiredSize(ctx)
|
var desired = child.DesiredSize(ctx)
|
||||||
var width, height, top, left float64
|
var width, height, top, left float32
|
||||||
switch {
|
switch {
|
||||||
case d == DockLeft || d == DockRight:
|
case d == DockLeft || d == DockRight:
|
||||||
width = rem.Dx()
|
width = rem.Dx()
|
||||||
if !math.IsNaN(desired.X) {
|
if !geom.IsNaN32(desired.X) {
|
||||||
width = math.Min(desired.X, width)
|
width = geom.Min32(desired.X, width)
|
||||||
}
|
}
|
||||||
if d == DockLeft {
|
if d == DockLeft {
|
||||||
left = rem.Min.X
|
left = rem.Min.X
|
||||||
@ -118,8 +116,8 @@ func (p *dockPanel) arrangeChildren(ctx Context) []geom.RectangleF {
|
|||||||
height = rem.Dy()
|
height = rem.Dy()
|
||||||
case d == DockTop || d == DockBottom:
|
case d == DockTop || d == DockBottom:
|
||||||
height = rem.Dy()
|
height = rem.Dy()
|
||||||
if !math.IsNaN(desired.Y) {
|
if !geom.IsNaN32(desired.Y) {
|
||||||
height = math.Min(desired.Y, height)
|
height = geom.Min32(desired.Y, height)
|
||||||
}
|
}
|
||||||
if d == DockTop {
|
if d == DockTop {
|
||||||
top = rem.Min.Y
|
top = rem.Min.Y
|
||||||
@ -129,23 +127,23 @@ func (p *dockPanel) arrangeChildren(ctx Context) []geom.RectangleF {
|
|||||||
left = rem.Min.X
|
left = rem.Min.X
|
||||||
width = rem.Dx()
|
width = rem.Dx()
|
||||||
}
|
}
|
||||||
rects[i] = geom.RectF(left, top, left+width, top+height)
|
rects[i] = geom.RectF32(left, top, left+width, top+height)
|
||||||
switch d {
|
switch d {
|
||||||
case DockLeft:
|
case DockLeft:
|
||||||
rem = geom.RectF(rem.Min.X+width, rem.Min.Y, rem.Max.X, rem.Max.Y)
|
rem = geom.RectF32(rem.Min.X+width, rem.Min.Y, rem.Max.X, rem.Max.Y)
|
||||||
case DockTop:
|
case DockTop:
|
||||||
rem = geom.RectF(rem.Min.X, rem.Min.Y+height, rem.Max.X, rem.Max.Y)
|
rem = geom.RectF32(rem.Min.X, rem.Min.Y+height, rem.Max.X, rem.Max.Y)
|
||||||
case DockRight:
|
case DockRight:
|
||||||
rem = geom.RectF(rem.Min.X, rem.Min.Y, rem.Max.X-width, rem.Max.Y)
|
rem = geom.RectF32(rem.Min.X, rem.Min.Y, rem.Max.X-width, rem.Max.Y)
|
||||||
case DockBottom:
|
case DockBottom:
|
||||||
rem = geom.RectF(rem.Min.X, rem.Min.Y, rem.Max.X, rem.Max.Y-height)
|
rem = geom.RectF32(rem.Min.X, rem.Min.Y, rem.Max.X, rem.Max.Y-height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rects
|
return rects
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *dockPanel) Arrange(ctx Context, rect geom.RectangleF) {
|
func (p *dockPanel) Arrange(ctx Context, rect geom.RectangleF32) {
|
||||||
p.ContainerBase.SetRect(rect)
|
p.ContainerBase.SetRect(rect)
|
||||||
var rects = p.arrangeChildren(ctx)
|
var rects = p.arrangeChildren(ctx)
|
||||||
for i, child := range p.children {
|
for i, child := range p.children {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"opslag.de/schobers/zntg/allg5"
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
|
"opslag.de/schobers/zntg/allg5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Label struct {
|
type Label struct {
|
||||||
@ -11,17 +11,17 @@ type Label struct {
|
|||||||
HorizontalAlignment allg5.HorizontalAlignment
|
HorizontalAlignment allg5.HorizontalAlignment
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Label) DesiredSize(ctx Context) geom.PointF {
|
func (l *Label) DesiredSize(ctx Context) geom.PointF32 {
|
||||||
var fonts = ctx.Fonts()
|
var fonts = ctx.Fonts()
|
||||||
var fnt = fonts.Get("default")
|
var fnt = fonts.Get("default")
|
||||||
var _, _, w, h = fnt.TextDimensions(l.Text)
|
var _, _, w, h = fnt.TextDimensions(l.Text)
|
||||||
return geom.PtF(float64(w), float64(h))
|
return geom.PtF32(w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Label) Render(ctx Context) {
|
func (l *Label) Render(ctx Context) {
|
||||||
var fonts = ctx.Fonts()
|
var fonts = ctx.Fonts()
|
||||||
|
|
||||||
var min = l.Bounds.Min.To32()
|
var min = l.Bounds.Min
|
||||||
|
|
||||||
var fnt = fonts.Get("default")
|
var fnt = fonts.Get("default")
|
||||||
fnt.Draw(min.X, min.Y+fnt.Height()-fnt.Ascent(), ctx.Palette().Darkest(), l.HorizontalAlignment, l.Text)
|
fnt.Draw(min.X, min.Y+fnt.Height()-fnt.Ascent(), ctx.Palette().Darkest(), l.HorizontalAlignment, l.Text)
|
||||||
|
18
ui/margin.go
18
ui/margin.go
@ -4,35 +4,35 @@ import "opslag.de/schobers/geom"
|
|||||||
|
|
||||||
type margin struct {
|
type margin struct {
|
||||||
Wrapper
|
Wrapper
|
||||||
Left, Top, Right, Bottom float64
|
Left, Top, Right, Bottom float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func Margin(c Control, m float64) Control {
|
func Margin(c Control, m float32) Control {
|
||||||
return &margin{Wrap(c), m, m, m, m}
|
return &margin{Wrap(c), m, m, m, m}
|
||||||
}
|
}
|
||||||
|
|
||||||
func LeftMargin(c Control, m float64) Control {
|
func LeftMargin(c Control, m float32) Control {
|
||||||
return &margin{Wrap(c), m, 0, 0, 0}
|
return &margin{Wrap(c), m, 0, 0, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TopMargin(c Control, m float64) Control {
|
func TopMargin(c Control, m float32) Control {
|
||||||
return &margin{Wrap(c), 0, m, 0, 0}
|
return &margin{Wrap(c), 0, m, 0, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HorizontalMargin(c Control, m float64) Control {
|
func HorizontalMargin(c Control, m float32) Control {
|
||||||
return &margin{Wrap(c), m, 0, m, 0}
|
return &margin{Wrap(c), m, 0, m, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func VerticalMargin(c Control, m float64) Control {
|
func VerticalMargin(c Control, m float32) Control {
|
||||||
return &margin{Wrap(c), 0, m, 0, m}
|
return &margin{Wrap(c), 0, m, 0, m}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *margin) DesiredSize(ctx Context) geom.PointF {
|
func (m *margin) DesiredSize(ctx Context) geom.PointF32 {
|
||||||
var sz = m.Wrapper.DesiredSize(ctx)
|
var sz = m.Wrapper.DesiredSize(ctx)
|
||||||
return geom.PtF(sz.X+m.Left+m.Right, sz.Y+m.Top+m.Bottom)
|
return geom.PtF32(sz.X+m.Left+m.Right, sz.Y+m.Top+m.Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *margin) Arrange(ctx Context, rect geom.RectangleF) {
|
func (m *margin) Arrange(ctx Context, rect geom.RectangleF32) {
|
||||||
m.Wrapper.SetRect(rect)
|
m.Wrapper.SetRect(rect)
|
||||||
rect.Min.X += m.Left
|
rect.Min.X += m.Left
|
||||||
rect.Min.Y += m.Top
|
rect.Min.Y += m.Top
|
||||||
|
14
ui/scroll.go
14
ui/scroll.go
@ -1,8 +1,8 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"opslag.de/schobers/zntg/allg5"
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
|
"opslag.de/schobers/zntg/allg5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type scroll struct {
|
type scroll struct {
|
||||||
@ -23,7 +23,7 @@ func Scroll(c Control, o Orientation) Control {
|
|||||||
dock.Append(DockRight, c)
|
dock.Append(DockRight, c)
|
||||||
}
|
}
|
||||||
var s = &scroll{Wrap(dock), c, bar}
|
var s = &scroll{Wrap(dock), c, bar}
|
||||||
bar.OnChanged = func(v float64) {
|
bar.OnChanged = func(v float32) {
|
||||||
|
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
@ -33,7 +33,7 @@ func (s *scroll) Handle(ctx Context, ev allg5.Event) {
|
|||||||
s.Wrapper.Handle(ctx, ev)
|
s.Wrapper.Handle(ctx, ev)
|
||||||
switch e := ev.(type) {
|
switch e := ev.(type) {
|
||||||
case *allg5.MouseMoveEvent:
|
case *allg5.MouseMoveEvent:
|
||||||
if 0 != e.DeltaZ && !s.Bar.IsOver && geom.PtF(float64(e.X), float64(e.Y)).In(s.Bounds) {
|
if 0 != e.DeltaZ && !s.Bar.IsOver && geom.PtF32(float32(e.X), float32(e.Y)).In(s.Bounds) {
|
||||||
var d = e.DeltaZ
|
var d = e.DeltaZ
|
||||||
if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) {
|
if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) {
|
||||||
d *= 10
|
d *= 10
|
||||||
@ -54,18 +54,18 @@ func (s *scroll) Render(ctx Context) {
|
|||||||
bmp.SetAsTarget()
|
bmp.SetAsTarget()
|
||||||
switch s.Bar.Orientation {
|
switch s.Bar.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
Arrange(ctx, s.Content, geom.RectF(-s.Bar.Value, 0, w, h))
|
Arrange(ctx, s.Content, geom.RectF32(-s.Bar.Value, 0, w, h))
|
||||||
case OrientationVertical:
|
case OrientationVertical:
|
||||||
Arrange(ctx, s.Content, geom.RectF(0, -s.Bar.Value, w, h))
|
Arrange(ctx, s.Content, geom.RectF32(0, -s.Bar.Value, w, h))
|
||||||
}
|
}
|
||||||
s.Content.Render(ctx)
|
s.Content.Render(ctx)
|
||||||
ctx.Display().SetAsTarget()
|
ctx.Display().SetAsTarget()
|
||||||
var min = s.Bounds.Min.To32()
|
var min = s.Bounds.Min
|
||||||
bmp.Draw(min.X, min.Y)
|
bmp.Draw(min.X, min.Y)
|
||||||
s.Bar.Render(ctx)
|
s.Bar.Render(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scroll) Arrange(ctx Context, rect geom.RectangleF) {
|
func (s *scroll) Arrange(ctx Context, rect geom.RectangleF32) {
|
||||||
var sz = s.Content.DesiredSize(ctx)
|
var sz = s.Content.DesiredSize(ctx)
|
||||||
switch s.Bar.Orientation {
|
switch s.Bar.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
|
|
||||||
"github.com/llgcode/draw2d/draw2dimg"
|
"github.com/llgcode/draw2d/draw2dimg"
|
||||||
|
|
||||||
"opslag.de/schobers/zntg/allg5"
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
|
"opslag.de/schobers/zntg/allg5"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Control = &Scrollbar{}
|
var _ Control = &Scrollbar{}
|
||||||
@ -79,9 +79,9 @@ func (s *Scrollbar) Destroyed(ctx Context) {
|
|||||||
s.handle.Destroyed(ctx)
|
s.handle.Destroyed(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scrollbar) barViewRange() (float64, float64) {
|
func (s *Scrollbar) barViewRange() (float32, float32) {
|
||||||
var small bool
|
var small bool
|
||||||
var min, max float64
|
var min, max float32
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
min = s.Bounds.Min.X + ScrollbarWidth
|
min = s.Bounds.Min.X + ScrollbarWidth
|
||||||
@ -99,7 +99,7 @@ func (s *Scrollbar) barViewRange() (float64, float64) {
|
|||||||
return min, max
|
return min, max
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scrollbar) barViewCenter() float64 {
|
func (s *Scrollbar) barViewCenter() float32 {
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
return (s.Bounds.Min.Y + s.Bounds.Max.Y) * .5
|
return (s.Bounds.Min.Y + s.Bounds.Max.Y) * .5
|
||||||
@ -108,7 +108,7 @@ func (s *Scrollbar) barViewCenter() float64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scrollbar) toValue(x, y float64) int {
|
func (s *Scrollbar) toValue(x, y float32) int {
|
||||||
var n = y
|
var n = y
|
||||||
if OrientationHorizontal == s.Orientation {
|
if OrientationHorizontal == s.Orientation {
|
||||||
n = x
|
n = x
|
||||||
@ -118,7 +118,7 @@ func (s *Scrollbar) toValue(x, y float64) int {
|
|||||||
return s.Minimum
|
return s.Minimum
|
||||||
}
|
}
|
||||||
var off = (n - min) / (max - min)
|
var off = (n - min) / (max - min)
|
||||||
var v = s.Minimum + int(off*float64(s.Maximum-s.Minimum)+.5)
|
var v = s.Minimum + int(off*float32(s.Maximum-s.Minimum)+.5)
|
||||||
if v < s.Minimum {
|
if v < s.Minimum {
|
||||||
v = s.Minimum
|
v = s.Minimum
|
||||||
} else if v > s.Maximum {
|
} else if v > s.Maximum {
|
||||||
@ -138,7 +138,7 @@ func (s *Scrollbar) change(v int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scrollbar) snapTo(x, y int) {
|
func (s *Scrollbar) snapTo(x, y int) {
|
||||||
var val = s.toValue(float64(x), float64(y))
|
var val = s.toValue(float32(x), float32(y))
|
||||||
s.change(val)
|
s.change(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,17 +174,17 @@ func (s *Scrollbar) Handle(ctx Context, ev allg5.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scrollbar) DesiredSize(Context) geom.PointF {
|
func (s *Scrollbar) DesiredSize(Context) geom.PointF32 {
|
||||||
var width = float64(2 * ScrollbarWidth)
|
var width = float32(2 * ScrollbarWidth)
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
return geom.PtF(math.NaN(), width)
|
return geom.PtF32(geom.NaN32(), width)
|
||||||
}
|
}
|
||||||
return geom.PtF(width, math.NaN())
|
return geom.PtF32(width, geom.NaN32())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scrollbar) SetRect(rect geom.RectangleF) {
|
func (s *Scrollbar) SetRect(rect geom.RectangleF32) {
|
||||||
var width = float64(2 * ScrollbarWidth)
|
var width = float32(2 * ScrollbarWidth)
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
if rect.Dy() > width {
|
if rect.Dy() > width {
|
||||||
@ -198,16 +198,16 @@ func (s *Scrollbar) SetRect(rect geom.RectangleF) {
|
|||||||
s.ControlBase.SetRect(rect)
|
s.ControlBase.SetRect(rect)
|
||||||
|
|
||||||
var min, max = s.barViewRange()
|
var min, max = s.barViewRange()
|
||||||
var off = float64(s.Value-s.Minimum) / float64(s.Maximum-s.Minimum)
|
var off = float32(s.Value-s.Minimum) / float32(s.Maximum-s.Minimum)
|
||||||
var centerH = min + (max-min)*off
|
var centerH = min + (max-min)*off
|
||||||
var r = 0.5 * float64(s.normal.Width())
|
var r = 0.5 * float32(s.normal.Width())
|
||||||
|
|
||||||
var center = s.barViewCenter()
|
var center = s.barViewCenter()
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
s.handle.SetRect(geom.RectF(centerH-r, center-r, centerH+r, center+r))
|
s.handle.SetRect(geom.RectF32(centerH-r, center-r, centerH+r, center+r))
|
||||||
default:
|
default:
|
||||||
s.handle.SetRect(geom.RectF(center-r, centerH-r, center+r, centerH+r))
|
s.handle.SetRect(geom.RectF32(center-r, centerH-r, center+r, centerH+r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ func (s *Scrollbar) Render(ctx Context) {
|
|||||||
var min64, max64 = s.barViewRange()
|
var min64, max64 = s.barViewRange()
|
||||||
var min, max = float32(min64), float32(max64)
|
var min, max = float32(min64), float32(max64)
|
||||||
|
|
||||||
var centerH = s.handle.Bounds.Center().To32()
|
var centerH = s.handle.Bounds.Center()
|
||||||
|
|
||||||
switch s.Orientation {
|
switch s.Orientation {
|
||||||
case OrientationHorizontal:
|
case OrientationHorizontal:
|
||||||
@ -228,7 +228,7 @@ func (s *Scrollbar) Render(ctx Context) {
|
|||||||
allg5.DrawLine(center, centerH.Y, center, min, ctx.Palette().Primary(), 2)
|
allg5.DrawLine(center, centerH.Y, center, min, ctx.Palette().Primary(), 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
var minH = s.handle.Bounds.Min.To32()
|
var minH = s.handle.Bounds.Min
|
||||||
var state = s.normal
|
var state = s.normal
|
||||||
if s.handle.IsOver {
|
if s.handle.IsOver {
|
||||||
if s.handle.IsPressed {
|
if s.handle.IsPressed {
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"opslag.de/schobers/zntg/allg5"
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
|
"opslag.de/schobers/zntg/allg5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type State interface {
|
type State interface {
|
||||||
@ -53,7 +53,7 @@ func (s *StateBase) Handle(ctx Context, ev allg5.Event) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Arrange(ctx Context, c Control, rect geom.RectangleF) {
|
func Arrange(ctx Context, c Control, rect geom.RectangleF32) {
|
||||||
if cont, ok := c.(Container); ok {
|
if cont, ok := c.(Container); ok {
|
||||||
cont.Arrange(ctx, rect)
|
cont.Arrange(ctx, rect)
|
||||||
} else {
|
} else {
|
||||||
@ -64,7 +64,7 @@ func Arrange(ctx Context, c Control, rect geom.RectangleF) {
|
|||||||
func (s *StateBase) Render(ctx Context) error {
|
func (s *StateBase) Render(ctx Context) error {
|
||||||
if nil != s.Control {
|
if nil != s.Control {
|
||||||
var disp = ctx.Display()
|
var disp = ctx.Display()
|
||||||
Arrange(ctx, s.Control, geom.RectF(0, 0, float64(disp.Width()), float64(disp.Height())))
|
Arrange(ctx, s.Control, geom.RectF32(0, 0, float32(disp.Width()), float32(disp.Height())))
|
||||||
s.Control.Render(ctx)
|
s.Control.Render(ctx)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
|
|
||||||
"opslag.de/schobers/zntg/allg5"
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
|
"opslag.de/schobers/zntg/allg5"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Control = &StatusBar{}
|
var _ Control = &StatusBar{}
|
||||||
@ -17,15 +15,15 @@ type StatusBar struct {
|
|||||||
RightText string
|
RightText string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *StatusBar) DesiredSize(Context) geom.PointF {
|
func (b *StatusBar) DesiredSize(Context) geom.PointF32 {
|
||||||
return geom.PtF(math.NaN(), statusBarHeight)
|
return geom.PtF32(geom.NaN32(), statusBarHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *StatusBar) Render(ctx Context) {
|
func (b *StatusBar) Render(ctx Context) {
|
||||||
var fonts = ctx.Fonts()
|
var fonts = ctx.Fonts()
|
||||||
|
|
||||||
var min = b.Bounds.Min.To32()
|
var min = b.Bounds.Min
|
||||||
var max = b.Bounds.Max.To32()
|
var max = b.Bounds.Max
|
||||||
allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, ctx.Palette().Primary())
|
allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, ctx.Palette().Primary())
|
||||||
|
|
||||||
var fnt = fonts.Get("default")
|
var fnt = fonts.Get("default")
|
||||||
|
@ -3,13 +3,13 @@ package ui
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"opslag.de/schobers/zntg/allg5"
|
|
||||||
"opslag.de/schobers/geom"
|
"opslag.de/schobers/geom"
|
||||||
|
"opslag.de/schobers/zntg/allg5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Wrapper struct {
|
type Wrapper struct {
|
||||||
Wrapped Control
|
Wrapped Control
|
||||||
Bounds geom.RectangleF
|
Bounds geom.RectangleF32
|
||||||
}
|
}
|
||||||
|
|
||||||
func Wrap(c Control) Wrapper {
|
func Wrap(c Control) Wrapper {
|
||||||
@ -32,15 +32,15 @@ func (w *Wrapper) Handle(ctx Context, ev allg5.Event) {
|
|||||||
w.Wrapped.Handle(ctx, ev)
|
w.Wrapped.Handle(ctx, ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wrapper) DesiredSize(ctx Context) geom.PointF {
|
func (w *Wrapper) DesiredSize(ctx Context) geom.PointF32 {
|
||||||
return w.Wrapped.DesiredSize(ctx)
|
return w.Wrapped.DesiredSize(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wrapper) Rect() geom.RectangleF {
|
func (w *Wrapper) Rect() geom.RectangleF32 {
|
||||||
return w.Bounds
|
return w.Bounds
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wrapper) SetRect(rect geom.RectangleF) {
|
func (w *Wrapper) SetRect(rect geom.RectangleF32) {
|
||||||
w.Bounds = rect
|
w.Bounds = rect
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ func (w *Wrapper) Children() []Control {
|
|||||||
return []Control{w.Wrapped}
|
return []Control{w.Wrapped}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wrapper) Arrange(ctx Context, rect geom.RectangleF) {
|
func (w *Wrapper) Arrange(ctx Context, rect geom.RectangleF32) {
|
||||||
w.Bounds = rect
|
w.Bounds = rect
|
||||||
Arrange(ctx, w.Wrapped, rect)
|
Arrange(ctx, w.Wrapped, rect)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user