Vertical stack example works

This commit is contained in:
Sasha Koshka
2023-01-31 18:04:12 -05:00
parent 2f9504b1e4
commit b0ff1ca0af
8 changed files with 25 additions and 36 deletions

View File

@@ -137,7 +137,7 @@ func (element *Button) draw () {
textBounds := element.drawer.LayoutBounds()
offset := image.Point {
X: innerBounds.Min.X + (innerBounds.Dx() - textBounds.Dx()) / 2,
Y: innerBounds.Min.X + (innerBounds.Dy() - textBounds.Dy()) / 2,
Y: innerBounds.Min.Y + (innerBounds.Dy() - textBounds.Dy()) / 2,
}
// account for the fact that the bounding rectangle will be shifted over

View File

@@ -207,7 +207,7 @@ func (element *Container) redoAll () {
})
artist.FillRectangle(element, pattern, bounds)
// resize all elements, having them draw onto us
// cut our canvas up and give peices to child elements
for _, entry := range element.children {
entry.DrawTo(tomo.Cut(element, entry.Bounds))
}
@@ -217,31 +217,27 @@ func (element *Container) HandleMouseDown (x, y int, button tomo.Button) {
child, handlesMouse := element.ChildAt(image.Pt(x, y)).(tomo.MouseTarget)
if !handlesMouse { return }
element.drags[button] = child
childPosition := element.childPosition(child)
child.HandleMouseDown(x - childPosition.X, y - childPosition.Y, button)
child.HandleMouseDown(x, y, button)
}
func (element *Container) HandleMouseUp (x, y int, button tomo.Button) {
child := element.drags[button]
if child == nil { return }
element.drags[button] = nil
childPosition := element.childPosition(child)
child.HandleMouseUp(x - childPosition.X, y - childPosition.Y, button)
child.HandleMouseUp(x, y, button)
}
func (element *Container) HandleMouseMove (x, y int) {
for _, child := range element.drags {
if child == nil { continue }
childPosition := element.childPosition(child)
child.HandleMouseMove(x - childPosition.X, y - childPosition.Y)
child.HandleMouseMove(x, y)
}
}
func (element *Container) HandleMouseScroll (x, y int, deltaX, deltaY float64) {
child, handlesMouse := element.ChildAt(image.Pt(x, y)).(tomo.MouseTarget)
if !handlesMouse { return }
childPosition := element.childPosition(child)
child.HandleMouseScroll(x - childPosition.X, y - childPosition.Y, deltaX, deltaY)
child.HandleMouseScroll(x, y, deltaX, deltaY)
}
func (element *Container) HandleKeyDown (key tomo.Key, modifiers tomo.Modifiers) {
@@ -475,6 +471,5 @@ func (element *Container) updateMinimumSize () {
}
func (element *Container) recalculate () {
bounds := element.Bounds()
element.layout.Arrange(element.children, bounds.Dx(), bounds.Dy())
element.layout.Arrange(element.children, element.Bounds())
}

View File

@@ -1,6 +1,5 @@
package basic
import "image"
import "git.tebibyte.media/sashakoshka/tomo/theme"
import "git.tebibyte.media/sashakoshka/tomo/artist"
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
@@ -119,8 +118,5 @@ func (element *Label) draw () {
foreground, _ := theme.ForegroundPattern (theme.PatternState {
Case: labelCase,
})
element.drawer.Draw (element, foreground, image.Point {
X: 0 - textBounds.Min.X,
Y: 0 - textBounds.Min.Y,
})
element.drawer.Draw (element, foreground, bounds.Min.Sub(textBounds.Min))
}