Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a32b06cef | |||
| fe50f5783b | |||
| 73a5fab0bc | |||
| 61addc051b | |||
| 7e275cc70e | |||
| 9856cd327f | |||
| 572e0c49af | |||
| e0f4ecb509 | |||
| fc51ffe33c | |||
| 987f4bfc4a | |||
| b883542f3b | |||
| c8d33a0ef4 | |||
| 9fa764c7b9 | |||
| 84ab0895f8 | |||
| b9c77fd5f7 | |||
| 2722d19ecd | |||
| 4fc44c11e8 | |||
| 0cdb116ec1 | |||
| 6ea1679112 | |||
| b87f32eac9 | |||
| 793526238a | |||
| 884148f006 | |||
| 3e382da688 | |||
| 18b8898644 |
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = tab
|
||||
indent_size = 8
|
||||
charset = utf-8
|
||||
|
||||
[*.md]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
@@ -69,6 +69,7 @@ func (this *Button) SetIcon (id tomo.Icon) {
|
||||
if this.icon != nil {
|
||||
this.Insert(this.icon, this.label)
|
||||
}
|
||||
this.SetTag("icon", this.icon != nil)
|
||||
this.applyLayout()
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ func NewDialog (kind DialogKind, parent tomo.Window, title, message string, opti
|
||||
}
|
||||
}
|
||||
dialog.controlRow = NewInnerContainer(layouts.ContractHorizontal, options...)
|
||||
messageText.SetAttr(tomo.AAlign(tomo.AlignEnd, tomo.AlignEnd))
|
||||
dialog.controlRow.SetAttr(tomo.AAlign(tomo.AlignEnd, tomo.AlignEnd))
|
||||
|
||||
dialog.SetRoot(NewOuterContainer (
|
||||
layouts.Column { true, false },
|
||||
|
||||
4
go.mod
4
go.mod
@@ -2,6 +2,4 @@ module git.tebibyte.media/tomo/objects
|
||||
|
||||
go 1.20
|
||||
|
||||
require git.tebibyte.media/tomo/tomo v0.41.0
|
||||
|
||||
require golang.org/x/image v0.11.0 // indirect
|
||||
require git.tebibyte.media/tomo/tomo v0.45.0
|
||||
|
||||
37
go.sum
37
go.sum
@@ -1,35 +1,2 @@
|
||||
git.tebibyte.media/tomo/tomo v0.41.0 h1:Z+7FHhbGiKjs+kQNvuJOfz47xIct5qxvSJqyDuoNIOs=
|
||||
git.tebibyte.media/tomo/tomo v0.41.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
|
||||
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
git.tebibyte.media/tomo/tomo v0.45.0 h1:fQH0WIPidW275hOq9dE6R7p064xG1RGx2QU68Avlr84=
|
||||
git.tebibyte.media/tomo/tomo v0.45.0/go.mod h1:WrtilgKB1y8O2Yu7X4mYcRiqOlPR8NuUnoA/ynkQWrs=
|
||||
|
||||
@@ -18,6 +18,8 @@ func NewHeading (level int, text string) *Heading {
|
||||
this.SetRole(tomo.R("objects", "Heading"))
|
||||
this.SetTag(fmt.Sprint(level), true)
|
||||
this.SetText(text)
|
||||
this.SetSelectable(true)
|
||||
this.SetFocusable(true)
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
28
icon.go
28
icon.go
@@ -1,12 +1,13 @@
|
||||
package objects
|
||||
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||
|
||||
// Icon displays a single icon.
|
||||
type Icon struct {
|
||||
tomo.Box
|
||||
icon tomo.Icon
|
||||
size tomo.IconSize
|
||||
}
|
||||
|
||||
func iconSizeString (size tomo.IconSize) string {
|
||||
@@ -18,29 +19,28 @@ func iconSizeString (size tomo.IconSize) string {
|
||||
}
|
||||
|
||||
// NewIcon creates a new icon from an icon ID.
|
||||
func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon {
|
||||
func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon {
|
||||
this := &Icon {
|
||||
Box: tomo.NewBox(),
|
||||
}
|
||||
this.SetRole(tomo.R("objects", "Icon"))
|
||||
this.SetTag(iconSizeString(size), true)
|
||||
this.setTexture(id.Texture(size))
|
||||
this.SetIcon(icon, size)
|
||||
this.OnIconSetChange(this.handleIconSetChange)
|
||||
return this
|
||||
}
|
||||
|
||||
// NewMimeIcon creates a new icon from a MIME type.
|
||||
func NewMimeIcon (mime data.Mime, size tomo.IconSize) *Icon {
|
||||
this := &Icon {
|
||||
Box: tomo.NewBox(),
|
||||
}
|
||||
this.SetRole(tomo.R("objects", "Icon"))
|
||||
this.SetTag(iconSizeString(size), true)
|
||||
this.setTexture(tomo.MimeIcon(mime, size))
|
||||
return this
|
||||
// SetIcon sets the icon.
|
||||
func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) {
|
||||
if this.icon == icon { return }
|
||||
this.icon = icon
|
||||
this.setTexture(icon.Texture(size))
|
||||
}
|
||||
|
||||
func (this *Icon) handleIconSetChange () {
|
||||
this.setTexture(this.icon.Texture(this.size))
|
||||
}
|
||||
|
||||
func (this *Icon) setTexture (texture canvas.Texture) {
|
||||
|
||||
this.SetAttr(tomo.ATexture(texture))
|
||||
this.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
|
||||
if texture == nil {
|
||||
|
||||
2
label.go
2
label.go
@@ -13,5 +13,7 @@ func NewLabel (text string) *Label {
|
||||
this.SetRole(tomo.R("objects", "Label"))
|
||||
this.SetText(text)
|
||||
this.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||
this.SetSelectable(true)
|
||||
this.SetFocusable(true)
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ func NewLabelCheckbox (value bool, text string) *LabelCheckbox {
|
||||
}
|
||||
box.SetRole(tomo.R("objects", "LabelCheckbox"))
|
||||
box.label.SetAttr(tomo.AAlign(tomo.AlignStart, tomo.AlignMiddle))
|
||||
box.label.SetSelectable(false)
|
||||
box.label.SetFocusable(false)
|
||||
box.Add(box.checkbox)
|
||||
box.Add(box.label)
|
||||
box.SetAttr(tomo.ALayout(layouts.Row { false, true }))
|
||||
|
||||
@@ -45,13 +45,14 @@ func (flow Flow) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||
index := 0
|
||||
for index < boxes.Len() {
|
||||
// get a slice of boxes for this major step
|
||||
stepIndexEnd := index + minorSteps
|
||||
stepIndexStart := index
|
||||
stepIndexEnd := index + minorSteps
|
||||
if stepIndexEnd > boxes.Len() { stepIndexEnd = boxes.Len() }
|
||||
index += minorSteps
|
||||
|
||||
// find a major size that will fit all boxes on this major step
|
||||
majorSize := 0
|
||||
for index := index; index < stepIndexEnd; index ++ {
|
||||
for index := stepIndexStart; index < stepIndexEnd; index ++ {
|
||||
boxSize := flow.major(boxes.MinimumSize(index))
|
||||
if boxSize > majorSize { majorSize = boxSize }
|
||||
}
|
||||
@@ -61,7 +62,7 @@ func (flow Flow) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||
var size image.Point
|
||||
size = flow.incrMajor(size, majorSize)
|
||||
size = flow.incrMinor(size, minorSize)
|
||||
for index := index; index < stepIndexEnd; index ++ {
|
||||
for index := stepIndexStart; index < stepIndexEnd; index ++ {
|
||||
bounds := image.Rectangle { Min: point, Max: point.Add(size) }
|
||||
boxes.SetBounds(index, bounds)
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ func (column Column) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||
if !hints.OverflowY {
|
||||
gaps := boxes.Len() - 1
|
||||
freeSpace := float64(hints.Bounds.Dy() - hints.Gap.Y * gaps)
|
||||
nExpanding := 0;
|
||||
nExpanding := 0
|
||||
for index := 0; index < boxes.Len(); index ++ {
|
||||
if expands(index) {
|
||||
nExpanding ++
|
||||
@@ -121,7 +121,7 @@ func (row Row) Arrange (hints tomo.LayoutHints, boxes tomo.BoxArranger) {
|
||||
if !hints.OverflowY {
|
||||
gaps := boxes.Len() - 1
|
||||
freeSpace := float64(hints.Bounds.Dx() - hints.Gap.X * gaps)
|
||||
nExpanding := 0;
|
||||
nExpanding := 0
|
||||
for index := 0; index < boxes.Len(); index ++ {
|
||||
if expands(index) {
|
||||
nExpanding ++
|
||||
|
||||
46
mimeicon.go
Normal file
46
mimeicon.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package objects
|
||||
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||
|
||||
// MimeIcon displays an icon of a MIME type.
|
||||
type MimeIcon struct {
|
||||
tomo.Box
|
||||
mime data.Mime
|
||||
size tomo.IconSize
|
||||
}
|
||||
|
||||
// NewMimeIcon creates a new icon from a MIME type.
|
||||
func NewMimeIcon (mime data.Mime, size tomo.IconSize) *MimeIcon {
|
||||
this := &MimeIcon {
|
||||
Box: tomo.NewBox(),
|
||||
}
|
||||
this.SetRole(tomo.R("objects", "MimeIcon"))
|
||||
this.SetIcon(mime, size)
|
||||
this.OnIconSetChange(this.handleIconSetChange)
|
||||
return this
|
||||
}
|
||||
|
||||
// SetIcon sets the MIME type and size of the icon.
|
||||
func (this *MimeIcon) SetIcon (mime data.Mime, size tomo.IconSize) {
|
||||
if this.mime == mime && this.size == size { return }
|
||||
this.mime = mime
|
||||
this.size = size
|
||||
this.setTexture(tomo.MimeIconTexture(mime, size))
|
||||
}
|
||||
|
||||
func (this *MimeIcon) handleIconSetChange () {
|
||||
this.setTexture(tomo.MimeIconTexture(this.mime, this.size))
|
||||
}
|
||||
|
||||
func (this *MimeIcon) setTexture (texture canvas.Texture) {
|
||||
this.SetAttr(tomo.ATexture(texture))
|
||||
this.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
|
||||
if texture == nil {
|
||||
this.SetAttr(tomo.AMinimumSize(0, 0))
|
||||
} else {
|
||||
bounds := texture.Bounds()
|
||||
this.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
|
||||
}
|
||||
}
|
||||
32
scrollbar.go
32
scrollbar.go
@@ -141,19 +141,15 @@ func (this *Scrollbar) handleKeyUp (key input.Key, numpad bool) bool {
|
||||
switch key {
|
||||
case input.KeyUp, input.KeyLeft: return true
|
||||
case input.KeyDown, input.KeyRight: return true
|
||||
case input.KeyHome: return true
|
||||
case input.KeyEnd: return true
|
||||
case input.KeyPageUp: return true
|
||||
case input.KeyPageDown: return true
|
||||
case input.KeyHome: return true
|
||||
case input.KeyEnd: return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) bool {
|
||||
var increment float64; if this.layout.vertical {
|
||||
increment = -0.05
|
||||
} else {
|
||||
increment = 0.05
|
||||
}
|
||||
|
||||
modifiers := this.Window().Modifiers()
|
||||
|
||||
switch key {
|
||||
@@ -161,15 +157,20 @@ func (this *Scrollbar) handleKeyDown (key input.Key, numpad bool) bool {
|
||||
if modifiers.Alt {
|
||||
this.SetValue(0)
|
||||
} else {
|
||||
this.SetValue(this.Value() - increment)
|
||||
this.scrollBy(this.StepSize())
|
||||
}
|
||||
return true
|
||||
case input.KeyDown, input.KeyRight:
|
||||
if modifiers.Alt {
|
||||
this.SetValue(1)
|
||||
} else {
|
||||
this.SetValue(this.Value() + increment)
|
||||
this.scrollBy(-this.StepSize())
|
||||
}
|
||||
case input.KeyPageUp:
|
||||
this.scrollBy(this.PageSize())
|
||||
return true
|
||||
case input.KeyPageDown:
|
||||
this.scrollBy(-this.PageSize())
|
||||
return true
|
||||
case input.KeyHome:
|
||||
this.SetValue(0)
|
||||
@@ -229,11 +230,22 @@ func (this *Scrollbar) handleButtonUp (button input.Button) bool {
|
||||
|
||||
func (this *Scrollbar) handleMouseMove () bool {
|
||||
if !this.dragging { return false }
|
||||
this.drag()
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *Scrollbar) handleScroll (x, y float64) bool {
|
||||
if this.layout.linked == nil { return false }
|
||||
|
||||
delta := (x + y)
|
||||
if this.layout.vertical {
|
||||
x = 0
|
||||
y = delta
|
||||
} else {
|
||||
x = delta
|
||||
y = 0
|
||||
}
|
||||
|
||||
this.layout.linked.ScrollTo (
|
||||
this.layout.linked.ContentBounds().Min.
|
||||
Sub(image.Pt(int(x), int(y))))
|
||||
|
||||
@@ -73,7 +73,11 @@ func NewScrollContainer (sides ScrollSide) *ScrollContainer {
|
||||
this.OnKeyUp(this.handleKeyUp)
|
||||
this.SetRole(tomo.R("objects", "ScrollContainer"))
|
||||
this.SetTag(sides.String(), true)
|
||||
this.SetAttr(tomo.ALayout(layouts.NewGrid(true, false)(true, false)))
|
||||
if sides == ScrollHorizontal {
|
||||
this.SetAttr(tomo.ALayout(layouts.NewGrid(true)(true, false)))
|
||||
} else {
|
||||
this.SetAttr(tomo.ALayout(layouts.NewGrid(true, false)(true, false)))
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -196,6 +200,7 @@ func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
|
||||
} else {
|
||||
vector.Y -= this.PageSize().Y
|
||||
}
|
||||
this.scrollBy(vector)
|
||||
return true
|
||||
case input.KeyPageDown:
|
||||
if modifiers.Shift {
|
||||
@@ -203,6 +208,23 @@ func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
|
||||
} else {
|
||||
vector.Y += this.PageSize().Y
|
||||
}
|
||||
this.scrollBy(vector)
|
||||
return true
|
||||
case input.KeyUp:
|
||||
if modifiers.Shift {
|
||||
vector.X -= this.StepSize().X
|
||||
} else {
|
||||
vector.Y -= this.StepSize().Y
|
||||
}
|
||||
this.scrollBy(vector)
|
||||
return true
|
||||
case input.KeyDown:
|
||||
if modifiers.Shift {
|
||||
vector.X += this.StepSize().X
|
||||
} else {
|
||||
vector.Y += this.StepSize().Y
|
||||
}
|
||||
this.scrollBy(vector)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
61
textinput.go
61
textinput.go
@@ -66,60 +66,61 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
|
||||
dot := this.Dot()
|
||||
modifiers := this.Window().Modifiers()
|
||||
word := modifiers.Control
|
||||
sel := modifiers.Shift
|
||||
changed := false
|
||||
|
||||
// TODO all dot control (movement, selection, etc) should be done in the
|
||||
// backend. (editing should be done here, though)
|
||||
defer func () {
|
||||
this.Select(dot)
|
||||
if changed {
|
||||
this.SetText(string(this.text))
|
||||
this.on.valueChange.Broadcast()
|
||||
}
|
||||
} ()
|
||||
|
||||
switch {
|
||||
case key == input.KeyEnter:
|
||||
this.on.confirm.Broadcast()
|
||||
case key == input.KeyHome || (modifiers.Alt && key == input.KeyLeft):
|
||||
dot.End = 0
|
||||
if !sel { dot.Start = dot.End }
|
||||
case key == input.KeyEnd || (modifiers.Alt && key == input.KeyRight):
|
||||
dot.End = len(this.text)
|
||||
if !sel { dot.Start = dot.End }
|
||||
case key == input.KeyLeft:
|
||||
if sel {
|
||||
dot = text.SelectLeft(this.text, dot, word)
|
||||
} else {
|
||||
dot = text.MoveLeft(this.text, dot, word)
|
||||
}
|
||||
case key == input.KeyRight:
|
||||
if sel {
|
||||
dot = text.SelectRight(this.text, dot, word)
|
||||
} else {
|
||||
dot = text.MoveRight(this.text, dot, word)
|
||||
}
|
||||
return true
|
||||
case key == input.KeyBackspace:
|
||||
this.text, dot = text.Backspace(this.text, dot, word)
|
||||
changed = true
|
||||
return true
|
||||
case key == input.KeyDelete:
|
||||
this.text, dot = text.Delete(this.text, dot, word)
|
||||
changed = true
|
||||
return true
|
||||
case key == input.Key('a') && modifiers.Control:
|
||||
dot.Start = 0
|
||||
dot.End = len(this.text)
|
||||
return true
|
||||
case key.Printable():
|
||||
this.text, dot = text.Type(this.text, dot, rune(key))
|
||||
changed = true
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
this.Select(dot)
|
||||
if changed {
|
||||
this.SetText(string(this.text))
|
||||
this.on.valueChange.Broadcast()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
|
||||
return true
|
||||
modifiers := this.Window().Modifiers()
|
||||
switch {
|
||||
case key == input.KeyEnter:
|
||||
return true
|
||||
case key == input.KeyBackspace:
|
||||
return true
|
||||
case key == input.KeyDelete:
|
||||
return true
|
||||
case key == input.Key('a') && modifiers.Control:
|
||||
return true
|
||||
case key.Printable():
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (this *TextInput) handleScroll (x, y float64) bool {
|
||||
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
||||
if x == 0 { return false }
|
||||
this.ScrollTo(this.ContentBounds().Min.Sub(image.Pt(int(x), int(y))))
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -22,6 +22,6 @@ func NewTextView (text string) *TextView {
|
||||
}
|
||||
|
||||
func (this *TextView) handleScroll (x, y float64) bool {
|
||||
this.ScrollTo(this.ContentBounds().Min.Add(image.Pt(int(x), int(y))))
|
||||
this.ScrollTo(this.ContentBounds().Min.Sub(image.Pt(int(x), int(y))))
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user