diff --git a/ui/button.go b/ui/button.go index 8e75d4b..55f6c6d 100644 --- a/ui/button.go +++ b/ui/button.go @@ -19,19 +19,19 @@ func NewButtonAlign(text string, click MouseClickFn, align allg5.HorizontalAlign 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 fnt = fonts.Get("default") var w = fnt.TextWidth(b.Text) 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) { var fonts = ctx.Fonts() - var min = b.Bounds.Min.To32() - var max = b.Bounds.Max.To32() + var min = b.Bounds.Min + var max = b.Bounds.Max var fnt = fonts.Get("default") var fntH = fnt.Height() diff --git a/ui/checkbox.go b/ui/checkbox.go index 9679200..2acb898 100644 --- a/ui/checkbox.go +++ b/ui/checkbox.go @@ -14,8 +14,8 @@ type CheckboxValueChangedFn func(bool) func drawCheckedBitmap(fill, stroke color.Color) *allg5.Bitmap { return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) { - var size = float64(checkboxSize) - var margin = float64(checkboxMargin) + var size float64 = checkboxSize + var margin float64 = checkboxMargin gc.SetFillColor(fill) 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 { return drawBitmap(checkboxSize, checkboxSize, func(gc *draw2dimg.GraphicContext) { - var size = float64(checkboxSize) - var margin = float64(checkboxMargin) + var size float64 = checkboxSize + var margin float64 = checkboxMargin gc.SetLineWidth(2) 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 fnt = fonts.Get("default") 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 { @@ -97,7 +97,7 @@ func (c *Checkbox) box() *allg5.Bitmap { func (c *Checkbox) Render(ctx Context) { var fonts = ctx.Fonts() - var min = c.Bounds.Min.To32() + var min = c.Bounds.Min var fnt = fonts.Get("default") fnt.Draw(min.X+checkboxSize, min.Y-.67*fnt.Ascent()+.5*checkboxSize, ctx.Palette().Darkest(), allg5.AlignLeft, c.Text) diff --git a/ui/columns.go b/ui/columns.go index 157683f..b4d09b9 100644 --- a/ui/columns.go +++ b/ui/columns.go @@ -1,8 +1,6 @@ package ui import ( - "math" - "opslag.de/schobers/geom" ) @@ -75,40 +73,40 @@ func (c *columns) AppendCreate(ctx Context, ctrl Control) { c.next() } -func (c *columns) DesiredSize(ctx Context) geom.PointF { - var w float64 - var h float64 +func (c *columns) DesiredSize(ctx Context) geom.PointF32 { + var w float32 + var h float32 for _, col := range c.cols { var sz = col.p.DesiredSize(ctx) - if !math.IsNaN(w) { - if math.IsNaN(sz.X) { + if !geom.IsNaN32(w) { + if geom.IsNaN32(sz.X) { w = sz.X } else { w += sz.X } } - if !math.IsNaN(h) { - if math.IsNaN(sz.Y) { + if !geom.IsNaN32(h) { + if geom.IsNaN32(sz.Y) { h = sz.Y } 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) 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 { - var ii = float64(i) + var ii = float32(i) var colH = col.p.DesiredSize(ctx).Y if 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) } } diff --git a/ui/container.go b/ui/container.go index 8fe477d..25c708a 100644 --- a/ui/container.go +++ b/ui/container.go @@ -10,7 +10,7 @@ import ( type Container interface { Control Children() []Control - Arrange(Context, geom.RectangleF) + Arrange(Context, geom.RectangleF32) } func NewContainer(parent Container, children ...Control) *ContainerBase { @@ -28,7 +28,7 @@ func (c *ContainerBase) Children() []Control { 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) for _, child := range c.children { Arrange(ctx, child, rect) diff --git a/ui/contentscrollbar.go b/ui/contentscrollbar.go index 82a85f7..e7e4a3c 100644 --- a/ui/contentscrollbar.go +++ b/ui/contentscrollbar.go @@ -1,25 +1,23 @@ package ui import ( - "math" - "opslag.de/schobers/geom" "opslag.de/schobers/zntg/allg5" ) var _ Control = &ContentScrollbar{} -type ContentScrollbarValueChangedFn func(float64) +type ContentScrollbarValueChangedFn func(float32) type ContentScrollbar struct { ControlBase - Length float64 - Value float64 + Length float32 + Value float32 Orientation Orientation OnChanged ContentScrollbarValueChangedFn handle *contentScrollbarHandle - barLength float64 - scrollDistance float64 + barLength float32 + scrollDistance float32 } type contentScrollbarHandle struct { @@ -33,8 +31,8 @@ func (h *contentScrollbarHandle) Render(ctx Context) { } else { } } - var min = h.Bounds.Min.To32() - var max = h.Bounds.Max.To32() + var min = h.Bounds.Min + var max = h.Bounds.Max 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) } -func (s *ContentScrollbar) length() (float64, float64) { - var min, max float64 +func (s *ContentScrollbar) length() (float32, float32) { + var min, max float32 switch s.Orientation { case OrientationHorizontal: min = s.Bounds.Min.X @@ -83,7 +81,7 @@ func (s *ContentScrollbar) updateBarLength() { s.scrollDistance = d } -func (s *ContentScrollbar) barViewCenter() float64 { +func (s *ContentScrollbar) barViewCenter() float32 { switch s.Orientation { case OrientationHorizontal: 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 if OrientationHorizontal == s.Orientation { pos = x @@ -110,7 +108,7 @@ func (s *ContentScrollbar) toValue(x, y float64) float64 { return s.scrollDistance * offset } -func (s *ContentScrollbar) change(v float64) { +func (s *ContentScrollbar) change(v float32) { if v != s.Value { s.Value = v var onChanged = s.OnChanged @@ -121,7 +119,7 @@ func (s *ContentScrollbar) change(v float64) { } 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) } @@ -129,7 +127,7 @@ func (s *ContentScrollbar) increment(d int) { if s.Orientation == OrientationVertical { d *= -1 } - var val = s.Value + float64(d)*ScrollbarWidth + var val = s.Value + float32(d)*ScrollbarWidth if val < 0 { val = 0 } 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 { 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 { case OrientationHorizontal: if rect.Dy() > ScrollbarWidth { @@ -182,7 +180,7 @@ func (s *ContentScrollbar) SetRect(rect geom.RectangleF) { s.ControlBase.SetRect(rect) s.updateBarLength() - var offset float64 + var offset float32 if 0 < s.scrollDistance { offset = s.Value / s.scrollDistance } @@ -191,9 +189,9 @@ func (s *ContentScrollbar) SetRect(rect geom.RectangleF) { var end = begin + s.barLength switch s.Orientation { 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: - 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)) } } diff --git a/ui/control.go b/ui/control.go index 7ff090a..5f31411 100644 --- a/ui/control.go +++ b/ui/control.go @@ -3,8 +3,8 @@ package ui import ( "time" - "opslag.de/schobers/zntg/allg5" "opslag.de/schobers/geom" + "opslag.de/schobers/zntg/allg5" ) type Control interface { @@ -13,9 +13,9 @@ type Control interface { Update(Context, time.Duration) Handle(Context, allg5.Event) - DesiredSize(Context) geom.PointF - Rect() geom.RectangleF - SetRect(geom.RectangleF) + DesiredSize(Context) geom.PointF32 + Rect() geom.RectangleF32 + SetRect(geom.RectangleF32) Render(Context) } @@ -25,12 +25,12 @@ var _ Control = &ControlBase{} type ControlBase struct { Parent Container - Bounds geom.RectangleF + Bounds geom.RectangleF32 Disabled bool IsOver bool IsPressed bool OnClick MouseClickFn - MinSize geom.PointF + MinSize geom.PointF32 Background *allg5.Color } @@ -46,7 +46,7 @@ func (c *ControlBase) Update(Context, time.Duration) {} func (c *ControlBase) Handle(ctx Context, ev allg5.Event) { switch e := ev.(type) { 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: if c.IsOver { 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 } -func (c *ControlBase) SetRect(rect geom.RectangleF) { +func (c *ControlBase) SetRect(rect geom.RectangleF32) { c.Bounds = rect } func (c *ControlBase) Render(ctx Context) { - var min = c.Bounds.Min.To32() - var max = c.Bounds.Max.To32() + var min = c.Bounds.Min + var max = c.Bounds.Max if nil != 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 } -func (c *ControlBase) IsInRect(x, y float64) bool { - return geom.PtF(x, y).In(c.Bounds) +func (c *ControlBase) IsInRect(x, y float32) bool { + return geom.PtF32(x, y).In(c.Bounds) } diff --git a/ui/dockpanel.go b/ui/dockpanel.go index 1a19397..57c78a4 100644 --- a/ui/dockpanel.go +++ b/ui/dockpanel.go @@ -1,8 +1,6 @@ package ui import ( - "math" - "opslag.de/schobers/geom" ) @@ -57,42 +55,42 @@ func (p *dockPanel) AppendCreate(ctx Context, d Dock, children ...Control) error return nil } -func (p *dockPanel) DesiredSize(ctx Context) geom.PointF { - var width, height float64 = 0, 0 +func (p *dockPanel) DesiredSize(ctx Context) geom.PointF32 { + var width, height float32 = 0, 0 for i, child := range p.children { var d = p.docks[i] var desired = child.DesiredSize(ctx) switch { case d == DockLeft || d == DockRight: - if !math.IsNaN(width) { - if math.IsNaN(desired.X) { + if !geom.IsNaN32(width) { + if geom.IsNaN32(desired.X) { width = desired.X } else { width += desired.X } } - if !math.IsNaN(desired.Y) { - height = math.Max(height, desired.Y) + if !geom.IsNaN32(desired.Y) { + height = geom.Max32(height, desired.Y) } case d == DockTop || d == DockBottom: - if !math.IsNaN(height) { - if math.IsNaN(desired.Y) { + if !geom.IsNaN32(height) { + if geom.IsNaN32(desired.Y) { height = desired.Y } else { height += desired.Y } } - if !math.IsNaN(desired.X) { - width = math.Max(width, desired.X) + if !geom.IsNaN32(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 rects = make([]geom.RectangleF, n) + var rects = make([]geom.RectangleF32, n) var rem = p.Bounds var last = n - 1 @@ -102,12 +100,12 @@ func (p *dockPanel) arrangeChildren(ctx Context) []geom.RectangleF { } else { var d = p.docks[i] var desired = child.DesiredSize(ctx) - var width, height, top, left float64 + var width, height, top, left float32 switch { case d == DockLeft || d == DockRight: width = rem.Dx() - if !math.IsNaN(desired.X) { - width = math.Min(desired.X, width) + if !geom.IsNaN32(desired.X) { + width = geom.Min32(desired.X, width) } if d == DockLeft { left = rem.Min.X @@ -118,8 +116,8 @@ func (p *dockPanel) arrangeChildren(ctx Context) []geom.RectangleF { height = rem.Dy() case d == DockTop || d == DockBottom: height = rem.Dy() - if !math.IsNaN(desired.Y) { - height = math.Min(desired.Y, height) + if !geom.IsNaN32(desired.Y) { + height = geom.Min32(desired.Y, height) } if d == DockTop { top = rem.Min.Y @@ -129,23 +127,23 @@ func (p *dockPanel) arrangeChildren(ctx Context) []geom.RectangleF { left = rem.Min.X 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 { 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: - 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: - 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: - 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 } -func (p *dockPanel) Arrange(ctx Context, rect geom.RectangleF) { +func (p *dockPanel) Arrange(ctx Context, rect geom.RectangleF32) { p.ContainerBase.SetRect(rect) var rects = p.arrangeChildren(ctx) for i, child := range p.children { diff --git a/ui/label.go b/ui/label.go index e7fe97e..edc3837 100644 --- a/ui/label.go +++ b/ui/label.go @@ -1,8 +1,8 @@ package ui import ( - "opslag.de/schobers/zntg/allg5" "opslag.de/schobers/geom" + "opslag.de/schobers/zntg/allg5" ) type Label struct { @@ -11,17 +11,17 @@ type Label struct { HorizontalAlignment allg5.HorizontalAlignment } -func (l *Label) DesiredSize(ctx Context) geom.PointF { +func (l *Label) DesiredSize(ctx Context) geom.PointF32 { var fonts = ctx.Fonts() var fnt = fonts.Get("default") 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) { var fonts = ctx.Fonts() - var min = l.Bounds.Min.To32() + var min = l.Bounds.Min var fnt = fonts.Get("default") fnt.Draw(min.X, min.Y+fnt.Height()-fnt.Ascent(), ctx.Palette().Darkest(), l.HorizontalAlignment, l.Text) diff --git a/ui/margin.go b/ui/margin.go index 0d08f54..00c8d4a 100644 --- a/ui/margin.go +++ b/ui/margin.go @@ -4,35 +4,35 @@ import "opslag.de/schobers/geom" type margin struct { 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} } -func LeftMargin(c Control, m float64) Control { +func LeftMargin(c Control, m float32) Control { 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} } -func HorizontalMargin(c Control, m float64) Control { +func HorizontalMargin(c Control, m float32) Control { 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} } -func (m *margin) DesiredSize(ctx Context) geom.PointF { +func (m *margin) DesiredSize(ctx Context) geom.PointF32 { 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) rect.Min.X += m.Left rect.Min.Y += m.Top diff --git a/ui/scroll.go b/ui/scroll.go index 36714ec..72ddff4 100644 --- a/ui/scroll.go +++ b/ui/scroll.go @@ -1,8 +1,8 @@ package ui import ( - "opslag.de/schobers/zntg/allg5" "opslag.de/schobers/geom" + "opslag.de/schobers/zntg/allg5" ) type scroll struct { @@ -23,7 +23,7 @@ func Scroll(c Control, o Orientation) Control { dock.Append(DockRight, c) } var s = &scroll{Wrap(dock), c, bar} - bar.OnChanged = func(v float64) { + bar.OnChanged = func(v float32) { } return s @@ -33,7 +33,7 @@ func (s *scroll) Handle(ctx Context, ev allg5.Event) { s.Wrapper.Handle(ctx, ev) switch e := ev.(type) { 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 if allg5.IsAnyKeyDown(allg5.KeyLShift, allg5.KeyRShift) { d *= 10 @@ -54,18 +54,18 @@ func (s *scroll) Render(ctx Context) { bmp.SetAsTarget() switch s.Bar.Orientation { 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: - 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) ctx.Display().SetAsTarget() - var min = s.Bounds.Min.To32() + var min = s.Bounds.Min bmp.Draw(min.X, min.Y) 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) switch s.Bar.Orientation { case OrientationHorizontal: diff --git a/ui/scrollbar.go b/ui/scrollbar.go index 3e7903a..b2cf7ee 100644 --- a/ui/scrollbar.go +++ b/ui/scrollbar.go @@ -5,8 +5,8 @@ import ( "github.com/llgcode/draw2d/draw2dimg" - "opslag.de/schobers/zntg/allg5" "opslag.de/schobers/geom" + "opslag.de/schobers/zntg/allg5" ) var _ Control = &Scrollbar{} @@ -79,9 +79,9 @@ func (s *Scrollbar) Destroyed(ctx Context) { s.handle.Destroyed(ctx) } -func (s *Scrollbar) barViewRange() (float64, float64) { +func (s *Scrollbar) barViewRange() (float32, float32) { var small bool - var min, max float64 + var min, max float32 switch s.Orientation { case OrientationHorizontal: min = s.Bounds.Min.X + ScrollbarWidth @@ -99,7 +99,7 @@ func (s *Scrollbar) barViewRange() (float64, float64) { return min, max } -func (s *Scrollbar) barViewCenter() float64 { +func (s *Scrollbar) barViewCenter() float32 { switch s.Orientation { case OrientationHorizontal: 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 if OrientationHorizontal == s.Orientation { n = x @@ -118,7 +118,7 @@ func (s *Scrollbar) toValue(x, y float64) int { return s.Minimum } 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 { v = s.Minimum } else if v > s.Maximum { @@ -138,7 +138,7 @@ func (s *Scrollbar) change(v 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) } @@ -174,17 +174,17 @@ func (s *Scrollbar) Handle(ctx Context, ev allg5.Event) { } } -func (s *Scrollbar) DesiredSize(Context) geom.PointF { - var width = float64(2 * ScrollbarWidth) +func (s *Scrollbar) DesiredSize(Context) geom.PointF32 { + var width = float32(2 * ScrollbarWidth) switch s.Orientation { 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) { - var width = float64(2 * ScrollbarWidth) +func (s *Scrollbar) SetRect(rect geom.RectangleF32) { + var width = float32(2 * ScrollbarWidth) switch s.Orientation { case OrientationHorizontal: if rect.Dy() > width { @@ -198,16 +198,16 @@ func (s *Scrollbar) SetRect(rect geom.RectangleF) { s.ControlBase.SetRect(rect) 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 r = 0.5 * float64(s.normal.Width()) + var r = 0.5 * float32(s.normal.Width()) var center = s.barViewCenter() switch s.Orientation { 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: - 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 min, max = float32(min64), float32(max64) - var centerH = s.handle.Bounds.Center().To32() + var centerH = s.handle.Bounds.Center() switch s.Orientation { case OrientationHorizontal: @@ -228,7 +228,7 @@ func (s *Scrollbar) Render(ctx Context) { 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 if s.handle.IsOver { if s.handle.IsPressed { diff --git a/ui/state.go b/ui/state.go index fcf2109..a5205b2 100644 --- a/ui/state.go +++ b/ui/state.go @@ -4,8 +4,8 @@ import ( "log" "time" - "opslag.de/schobers/zntg/allg5" "opslag.de/schobers/geom" + "opslag.de/schobers/zntg/allg5" ) type State interface { @@ -53,7 +53,7 @@ func (s *StateBase) Handle(ctx Context, ev allg5.Event) error { 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 { cont.Arrange(ctx, rect) } else { @@ -64,7 +64,7 @@ func Arrange(ctx Context, c Control, rect geom.RectangleF) { func (s *StateBase) Render(ctx Context) error { if nil != s.Control { 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) } return nil diff --git a/ui/statusbar.go b/ui/statusbar.go index e33216a..ef3bb89 100644 --- a/ui/statusbar.go +++ b/ui/statusbar.go @@ -1,10 +1,8 @@ package ui import ( - "math" - - "opslag.de/schobers/zntg/allg5" "opslag.de/schobers/geom" + "opslag.de/schobers/zntg/allg5" ) var _ Control = &StatusBar{} @@ -17,15 +15,15 @@ type StatusBar struct { RightText string } -func (b *StatusBar) DesiredSize(Context) geom.PointF { - return geom.PtF(math.NaN(), statusBarHeight) +func (b *StatusBar) DesiredSize(Context) geom.PointF32 { + return geom.PtF32(geom.NaN32(), statusBarHeight) } func (b *StatusBar) Render(ctx Context) { var fonts = ctx.Fonts() - var min = b.Bounds.Min.To32() - var max = b.Bounds.Max.To32() + var min = b.Bounds.Min + var max = b.Bounds.Max allg5.DrawFilledRectangle(min.X, min.Y, max.X, max.Y, ctx.Palette().Primary()) var fnt = fonts.Get("default") diff --git a/ui/wrapper.go b/ui/wrapper.go index a4bc17a..649d4e8 100644 --- a/ui/wrapper.go +++ b/ui/wrapper.go @@ -3,13 +3,13 @@ package ui import ( "time" - "opslag.de/schobers/zntg/allg5" "opslag.de/schobers/geom" + "opslag.de/schobers/zntg/allg5" ) type Wrapper struct { Wrapped Control - Bounds geom.RectangleF + Bounds geom.RectangleF32 } func Wrap(c Control) Wrapper { @@ -32,15 +32,15 @@ func (w *Wrapper) Handle(ctx Context, ev allg5.Event) { 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) } -func (w *Wrapper) Rect() geom.RectangleF { +func (w *Wrapper) Rect() geom.RectangleF32 { return w.Bounds } -func (w *Wrapper) SetRect(rect geom.RectangleF) { +func (w *Wrapper) SetRect(rect geom.RectangleF32) { w.Bounds = rect } @@ -52,7 +52,7 @@ func (w *Wrapper) Children() []Control { 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 Arrange(ctx, w.Wrapped, rect) }