11 Commits

7 changed files with 55 additions and 33 deletions

View File

@@ -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 },

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -229,11 +229,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))))

View File

@@ -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,7 @@ func (this *ScrollContainer) handleKeyDown (key input.Key, numpad bool) bool {
} else {
vector.Y += this.PageSize().Y
}
this.scrollBy(vector)
return true
}
return false

View File

@@ -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
}

View File

@@ -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
}