From 15fa3b2497c70c5b09d865c676db86529cb30fb8 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 11 Mar 2023 18:27:16 -0500 Subject: [PATCH] Quelled some of the strangeness --- elements/basic/documentContainer.go | 14 ++++++++++++++ examples/documentContainer/main.go | 10 ++++++++++ textdraw/setter.go | 3 +-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/elements/basic/documentContainer.go b/elements/basic/documentContainer.go index c525cde..7e830b3 100644 --- a/elements/basic/documentContainer.go +++ b/elements/basic/documentContainer.go @@ -267,6 +267,10 @@ func (element *DocumentContainer) ScrollTo (position image.Point) { if position.Y < 0 { position.Y = 0 } + maxScrollHeight := element.maxScrollHeight() + if position.Y > maxScrollHeight { + position.Y = maxScrollHeight + } element.scroll = position if element.core.HasImage() && !element.warping { element.redoAll() @@ -274,6 +278,14 @@ func (element *DocumentContainer) ScrollTo (position image.Point) { } } +func (element *DocumentContainer) maxScrollHeight () (height int) { + padding := element.theme.Padding(theme.PatternSunken) + viewportHeight := element.Bounds().Dy() - padding.Vertical() + height = element.contentBounds.Dy() - viewportHeight + if height < 0 { height = 0 } + return +} + // ScrollAxes returns the supported axes for scrolling. func (element *DocumentContainer) ScrollAxes () (horizontal, vertical bool) { return false, true @@ -339,4 +351,6 @@ func (element *DocumentContainer) doLayout () { element.contentBounds = element.contentBounds.Union(entry.Bounds) dot.Y += height } + element.contentBounds = + element.contentBounds.Sub(element.contentBounds.Min) } diff --git a/examples/documentContainer/main.go b/examples/documentContainer/main.go index 3035399..9c92c3e 100644 --- a/examples/documentContainer/main.go +++ b/examples/documentContainer/main.go @@ -21,6 +21,16 @@ func run () { "text-wrapped labels.", true)) document.Adopt (basicElements.NewButton ( "You can also include normal elements like buttons,")) + document.Adopt (basicElements.NewButton ( + "You can also include normal elements like buttons,")) + document.Adopt (basicElements.NewButton ( + "You can also include normal elements like buttons,")) + document.Adopt (basicElements.NewButton ( + "You can also include normal elements like buttons,")) + document.Adopt (basicElements.NewButton ( + "You can also include normal elements like buttons,")) + document.Adopt (basicElements.NewButton ( + "You can also include normal elements like buttons,")) document.Adopt (basicElements.NewCheckbox ( "checkboxes,", true)) document.Adopt(basicElements.NewTextBox("", "And text boxes.")) diff --git a/textdraw/setter.go b/textdraw/setter.go index 83b9f90..b43da89 100644 --- a/textdraw/setter.go +++ b/textdraw/setter.go @@ -41,8 +41,7 @@ func (setter *TypeSetter) needLayout () { metrics := setter.face.Metrics() remaining := setter.text y := fixed.Int26_6(0) - maxY := fixed.I(setter.maxHeight) + metrics.Height - for len(remaining) > 0 && (y < maxY || setter.maxHeight == 0) { + for len(remaining) > 0 { // process one line line, remainingFromLine := DoLine ( remaining, setter.face, fixed.I(setter.maxWidth))