Integrated the new text drawer
This commit is contained in:
parent
234503f104
commit
a0e7bf1373
@ -6,6 +6,7 @@ import "git.tebibyte.media/sashakoshka/tomo/input"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
// Button is a clickable button.
|
// Button is a clickable button.
|
||||||
@ -14,7 +15,7 @@ type Button struct {
|
|||||||
*core.FocusableCore
|
*core.FocusableCore
|
||||||
core core.CoreControl
|
core core.CoreControl
|
||||||
focusableControl core.FocusableCoreControl
|
focusableControl core.FocusableCoreControl
|
||||||
drawer artist.TextDrawer
|
drawer textdraw.Drawer
|
||||||
|
|
||||||
pressed bool
|
pressed bool
|
||||||
text string
|
text string
|
||||||
|
@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/input"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
// Checkbox is a toggle-able checkbox with a label.
|
// Checkbox is a toggle-able checkbox with a label.
|
||||||
@ -13,7 +14,7 @@ type Checkbox struct {
|
|||||||
*core.FocusableCore
|
*core.FocusableCore
|
||||||
core core.CoreControl
|
core core.CoreControl
|
||||||
focusableControl core.FocusableCoreControl
|
focusableControl core.FocusableCoreControl
|
||||||
drawer artist.TextDrawer
|
drawer textdraw.Drawer
|
||||||
|
|
||||||
pressed bool
|
pressed bool
|
||||||
checked bool
|
checked bool
|
||||||
|
@ -3,6 +3,7 @@ package basicElements
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
// Label is a simple text box.
|
// Label is a simple text box.
|
||||||
@ -12,7 +13,7 @@ type Label struct {
|
|||||||
|
|
||||||
wrap bool
|
wrap bool
|
||||||
text string
|
text string
|
||||||
drawer artist.TextDrawer
|
drawer textdraw.Drawer
|
||||||
|
|
||||||
config config.Wrapped
|
config config.Wrapped
|
||||||
theme theme.Wrapped
|
theme theme.Wrapped
|
||||||
|
@ -5,10 +5,11 @@ import "git.tebibyte.media/sashakoshka/tomo/theme"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||||
|
|
||||||
// ListEntry is an item that can be added to a list.
|
// ListEntry is an item that can be added to a list.
|
||||||
type ListEntry struct {
|
type ListEntry struct {
|
||||||
drawer artist.TextDrawer
|
drawer textdraw.Drawer
|
||||||
bounds image.Rectangle
|
bounds image.Rectangle
|
||||||
text string
|
text string
|
||||||
width int
|
width int
|
||||||
|
@ -5,6 +5,7 @@ import "git.tebibyte.media/sashakoshka/tomo/input"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
// Switch is a toggle-able on/off switch with an optional label. It is
|
// Switch is a toggle-able on/off switch with an optional label. It is
|
||||||
@ -14,7 +15,7 @@ type Switch struct {
|
|||||||
*core.FocusableCore
|
*core.FocusableCore
|
||||||
core core.CoreControl
|
core core.CoreControl
|
||||||
focusableControl core.FocusableCoreControl
|
focusableControl core.FocusableCoreControl
|
||||||
drawer artist.TextDrawer
|
drawer textdraw.Drawer
|
||||||
|
|
||||||
pressed bool
|
pressed bool
|
||||||
checked bool
|
checked bool
|
||||||
|
@ -6,7 +6,9 @@ import "git.tebibyte.media/sashakoshka/tomo/theme"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/textmanip"
|
import "git.tebibyte.media/sashakoshka/tomo/textmanip"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/fixedutil"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||||
|
|
||||||
// TextBox is a single-line text input.
|
// TextBox is a single-line text input.
|
||||||
@ -22,8 +24,8 @@ type TextBox struct {
|
|||||||
placeholder string
|
placeholder string
|
||||||
text []rune
|
text []rune
|
||||||
|
|
||||||
placeholderDrawer artist.TextDrawer
|
placeholderDrawer textdraw.Drawer
|
||||||
valueDrawer artist.TextDrawer
|
valueDrawer textdraw.Drawer
|
||||||
|
|
||||||
config config.Wrapped
|
config config.Wrapped
|
||||||
theme theme.Wrapped
|
theme theme.Wrapped
|
||||||
@ -71,7 +73,8 @@ func (element *TextBox) HandleMouseDown (x, y int, button input.Button) {
|
|||||||
offset := element.Bounds().Min.Add (image.Pt (
|
offset := element.Bounds().Min.Add (image.Pt (
|
||||||
element.config.Padding() - element.scroll,
|
element.config.Padding() - element.scroll,
|
||||||
element.config.Padding()))
|
element.config.Padding()))
|
||||||
runeIndex := element.valueDrawer.AtPosition(point.Sub(offset))
|
runeIndex := element.valueDrawer.AtPosition (
|
||||||
|
fixedutil.Pt(point.Sub(offset)))
|
||||||
element.dragging = true
|
element.dragging = true
|
||||||
if runeIndex > -1 {
|
if runeIndex > -1 {
|
||||||
element.dot = textmanip.EmptyDot(runeIndex)
|
element.dot = textmanip.EmptyDot(runeIndex)
|
||||||
@ -89,7 +92,8 @@ func (element *TextBox) HandleMouseMove (x, y int) {
|
|||||||
offset := element.Bounds().Min.Add (image.Pt (
|
offset := element.Bounds().Min.Add (image.Pt (
|
||||||
element.config.Padding() - element.scroll,
|
element.config.Padding() - element.scroll,
|
||||||
element.config.Padding()))
|
element.config.Padding()))
|
||||||
runeIndex := element.valueDrawer.AtPosition(point.Sub(offset))
|
runeIndex := element.valueDrawer.AtPosition (
|
||||||
|
fixedutil.Pt(point.Sub(offset)))
|
||||||
if runeIndex > -1 {
|
if runeIndex > -1 {
|
||||||
element.dot.End = runeIndex
|
element.dot.End = runeIndex
|
||||||
element.redo()
|
element.redo()
|
||||||
@ -290,7 +294,8 @@ func (element *TextBox) scrollToCursor () {
|
|||||||
bounds := element.Bounds().Inset(element.config.Padding())
|
bounds := element.Bounds().Inset(element.config.Padding())
|
||||||
bounds = bounds.Sub(bounds.Min)
|
bounds = bounds.Sub(bounds.Min)
|
||||||
bounds.Max.X -= element.valueDrawer.Em().Round()
|
bounds.Max.X -= element.valueDrawer.Em().Round()
|
||||||
cursorPosition := element.valueDrawer.PositionOf(element.dot.End)
|
cursorPosition := fixedutil.RoundPt (
|
||||||
|
element.valueDrawer.PositionAt(element.dot.End))
|
||||||
cursorPosition.X -= element.scroll
|
cursorPosition.X -= element.scroll
|
||||||
maxX := bounds.Max.X
|
maxX := bounds.Max.X
|
||||||
minX := maxX
|
minX := maxX
|
||||||
@ -361,13 +366,17 @@ func (element *TextBox) draw () {
|
|||||||
accent := element.theme.Pattern (
|
accent := element.theme.Pattern (
|
||||||
theme.PatternAccent, state)
|
theme.PatternAccent, state)
|
||||||
canon := element.dot.Canon()
|
canon := element.dot.Canon()
|
||||||
start := element.valueDrawer.PositionOf(canon.Start).Add(offset)
|
foff := fixedutil.Pt(offset)
|
||||||
end := element.valueDrawer.PositionOf(canon.End).Add(offset)
|
start := element.valueDrawer.PositionAt(canon.Start).Add(foff)
|
||||||
end.Y += element.valueDrawer.LineHeight().Round()
|
end := element.valueDrawer.PositionAt(canon.End).Add(foff)
|
||||||
|
end.Y += element.valueDrawer.LineHeight()
|
||||||
artist.FillRectangle (
|
artist.FillRectangle (
|
||||||
innerCanvas,
|
innerCanvas,
|
||||||
accent,
|
accent,
|
||||||
image.Rectangle { start, end })
|
image.Rectangle {
|
||||||
|
fixedutil.RoundPt(start),
|
||||||
|
fixedutil.RoundPt(end),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(element.text) == 0 {
|
if len(element.text) == 0 {
|
||||||
@ -395,8 +404,8 @@ func (element *TextBox) draw () {
|
|||||||
// draw cursor
|
// draw cursor
|
||||||
foreground := element.theme.Pattern (
|
foreground := element.theme.Pattern (
|
||||||
theme.PatternForeground, state)
|
theme.PatternForeground, state)
|
||||||
cursorPosition := element.valueDrawer.PositionOf (
|
cursorPosition := fixedutil.RoundPt (
|
||||||
element.dot.End)
|
element.valueDrawer.PositionAt(element.dot.End))
|
||||||
artist.Line (
|
artist.Line (
|
||||||
innerCanvas,
|
innerCanvas,
|
||||||
foreground, 1,
|
foreground, 1,
|
||||||
|
@ -170,6 +170,11 @@ func (setter *TypeSetter) Face () font.Face {
|
|||||||
return setter.face
|
return setter.face
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Length returns the amount of runes in the typesetter.
|
||||||
|
func (setter *TypeSetter) Length () int {
|
||||||
|
return len(setter.text)
|
||||||
|
}
|
||||||
|
|
||||||
// RuneIterator is a function that can iterate accross a typesetter's runes.
|
// RuneIterator is a function that can iterate accross a typesetter's runes.
|
||||||
type RuneIterator func (
|
type RuneIterator func (
|
||||||
index int,
|
index int,
|
||||||
|
Reference in New Issue
Block a user