TextBox text is now vertically centered

This commit is contained in:
Sasha Koshka 2023-03-05 10:58:27 -05:00
parent d38bd1cbf5
commit 7e0d64e8bd
1 changed files with 12 additions and 11 deletions

View File

@ -92,11 +92,18 @@ func (element *TextBox) HandleMouseMove (x, y int) {
}
}
func (element *TextBox) atPosition (position image.Point) int {
padding := element.theme.Padding(theme.PatternInput)
offset := element.Bounds().Min.Add (image.Pt (
func (element *TextBox) textOffset () image.Point {
padding := element.theme.Padding(theme.PatternInput)
bounds := element.Bounds()
innerBounds := padding.Apply(bounds)
textHeight := element.valueDrawer.LineHeight().Round()
return bounds.Min.Add (image.Pt (
padding[artist.SideLeft] - element.scroll,
padding[artist.SideTop]))
padding[artist.SideTop] + (innerBounds.Dy() - textHeight) / 2))
}
func (element *TextBox) atPosition (position image.Point) int {
offset := element.textOffset()
textBoundsMin := element.valueDrawer.LayoutBounds().Min
return element.valueDrawer.AtPosition (
fixedutil.Pt(position.Sub(offset).Add(textBoundsMin)))
@ -115,8 +122,6 @@ func (element *TextBox) HandleKeyDown(key input.Key, modifiers input.Modifiers)
return
}
// TODO: text selection with shift
scrollMemory := element.scroll
altered := true
textChanged := false
@ -358,11 +363,7 @@ func (element *TextBox) draw () {
padding := element.theme.Padding(theme.PatternInput)
innerCanvas := canvas.Cut(element.core, padding.Apply(bounds))
pattern.Draw(element.core, bounds)
offset := bounds.Min.Add (image.Point {
X: padding[artist.SideLeft] - element.scroll,
Y: padding[artist.SideTop],
})
offset := element.textOffset()
if element.Focused() && !element.dot.Empty() {
// draw selection bounds