Compare commits
12 Commits
fad46eafd3
...
v0.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
| bacdd81f60 | |||
| d944f6016f | |||
| 01582d4ad1 | |||
| 3941dae44a | |||
| 85b8536925 | |||
| 6ff5dea308 | |||
| 33969f45e9 | |||
| 832d7e02ef | |||
| fd6297b4fb | |||
| 4deb581667 | |||
| 192e6c6235 | |||
| 9729e3dfda |
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module git.tebibyte.media/tomo/backend
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
git.tebibyte.media/tomo/tomo v0.41.0
|
||||
git.tebibyte.media/tomo/tomo v0.41.1
|
||||
git.tebibyte.media/tomo/typeset v0.7.1
|
||||
git.tebibyte.media/tomo/xgbkb v1.0.1
|
||||
github.com/jezek/xgb v1.1.1
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1,6 +1,6 @@
|
||||
git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
|
||||
git.tebibyte.media/tomo/tomo v0.41.0 h1:Z+7FHhbGiKjs+kQNvuJOfz47xIct5qxvSJqyDuoNIOs=
|
||||
git.tebibyte.media/tomo/tomo v0.41.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
||||
git.tebibyte.media/tomo/tomo v0.41.1 h1:XdbyF3VjsLj1Zppr70gUaufuh49hU32JQo2ENnw4PcA=
|
||||
git.tebibyte.media/tomo/tomo v0.41.1/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
||||
git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8=
|
||||
git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
|
||||
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=
|
||||
|
||||
@@ -20,6 +20,7 @@ func (querier boxQuerier) RecommendedWidth (index int, height int) int {
|
||||
if box, ok := box.(anyContentBox); ok {
|
||||
return box.recommendedWidth(height)
|
||||
}
|
||||
return box.minimumSize().X
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -29,6 +30,7 @@ func (querier boxQuerier) RecommendedHeight (index int, width int) int {
|
||||
if box, ok := box.(anyContentBox); ok {
|
||||
return box.recommendedHeight(width)
|
||||
}
|
||||
return box.minimumSize().Y
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ func (this *containerBox) setAttr (attr tomo.Attr, user bool) {
|
||||
case tomo.AttrOverflow:
|
||||
if this.attrOverflow.Set(attr, user) {
|
||||
this.invalidateLayout()
|
||||
this.invalidateMinimum()
|
||||
}
|
||||
|
||||
case tomo.AttrLayout:
|
||||
@@ -187,7 +188,7 @@ func (this *containerBox) setAttr (attr tomo.Attr, user bool) {
|
||||
|
||||
func (this *containerBox) recommendedHeight (width int) int {
|
||||
layout := this.attrLayout.Value().Layout
|
||||
if layout == nil || this.attrOverflow.Value().Y {
|
||||
if layout == nil || !this.attrOverflow.Value().Y {
|
||||
return this.minSize.Value().Y
|
||||
} else {
|
||||
return layout.RecommendedHeight(this.layoutHints(), this.boxQuerier(), width) +
|
||||
@@ -197,7 +198,7 @@ func (this *containerBox) recommendedHeight (width int) int {
|
||||
|
||||
func (this *containerBox) recommendedWidth (height int) int {
|
||||
layout := this.attrLayout.Value().Layout
|
||||
if layout == nil || this.attrOverflow.Value().X {
|
||||
if layout == nil || !this.attrOverflow.Value().X {
|
||||
return this.minSize.Value().X
|
||||
} else {
|
||||
return layout.RecommendedWidth(this.layoutHints(), this.boxQuerier(), height) +
|
||||
|
||||
@@ -3,7 +3,6 @@ package system
|
||||
import "image"
|
||||
import "git.tebibyte.media/tomo/tomo/input"
|
||||
|
||||
// TODO: redo all of this because there are new event propogation rules
|
||||
// TODO: once go v1.23 comes out, replace the explicit iterator calls here with
|
||||
// range loops
|
||||
|
||||
@@ -25,21 +24,30 @@ func (this *Hierarchy) HandleModifiers (modifiers input.Modifiers) {
|
||||
// HandleModifiers must be called *before* HandleKeyDown.
|
||||
func (this *Hierarchy) HandleKeyDown (key input.Key, numberPad bool) {
|
||||
caught := false
|
||||
this.keyboardTargets(func (target anyBox) bool {
|
||||
if target.handleKeyDown(key, numberPad) {
|
||||
caught = true
|
||||
return false
|
||||
if this.anyFocused() {
|
||||
this.keyboardTargets(func (target anyBox) bool {
|
||||
if target.handleKeyDown(key, numberPad) {
|
||||
caught = true
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
if this.root != nil {
|
||||
caught = this.root.handleKeyDown(key, numberPad)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
if caught { return }
|
||||
|
||||
if key == input.KeyTab && this.modifiers.Alt {
|
||||
|
||||
switch key {
|
||||
case input.KeyTab:
|
||||
if this.modifiers.Shift {
|
||||
this.focusPrevious()
|
||||
} else {
|
||||
this.focusNext()
|
||||
}
|
||||
case input.KeyUp: this.focusPrevious()
|
||||
case input.KeyDown: this.focusNext()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +55,18 @@ func (this *Hierarchy) HandleKeyDown (key input.Key, numberPad bool) {
|
||||
// which triggers this comes with modifier key information, HandleModifiers must
|
||||
// be called *before* HandleKeyUp.
|
||||
func (this *Hierarchy) HandleKeyUp (key input.Key, numberPad bool) {
|
||||
this.keyboardTargets(func (target anyBox) bool {
|
||||
if target.handleKeyUp(key, numberPad) {
|
||||
return false
|
||||
if this.anyFocused() {
|
||||
this.keyboardTargets(func (target anyBox) bool {
|
||||
if target.handleKeyUp(key, numberPad) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
if this.root != nil {
|
||||
this.root.handleKeyUp(key, numberPad)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// HandleMouseDown sends a mouse down event to the Boxes positioned underneath
|
||||
@@ -101,17 +115,18 @@ func (this *Hierarchy) HandleMouseMove (position image.Point) {
|
||||
for _, dragSet := range this.drags {
|
||||
for _, box := range dragSet {
|
||||
if box.handleMouseMove() { break }
|
||||
dragged = true
|
||||
}
|
||||
dragged = true
|
||||
}
|
||||
if dragged { return }
|
||||
|
||||
// TODO we can hover over multiple boxes at once. however, any way of
|
||||
// detecting this involves several slice allocations every time we
|
||||
// process a MouseMove event. perhaps we just ought to suck it up and do
|
||||
// it.
|
||||
// it. or perhaps doing *this* is the better way? we may never know.
|
||||
box := this.boxUnder(position)
|
||||
if box != nil {
|
||||
box := this.considerMaskingParents(box)
|
||||
this.hover(box)
|
||||
box.handleMouseMove()
|
||||
}
|
||||
|
||||
@@ -287,13 +287,26 @@ func (this *Hierarchy) considerMaskingParents (box anyBox) anyBox {
|
||||
return box
|
||||
}
|
||||
|
||||
func (this *Hierarchy) isMasked (box anyBox) bool {
|
||||
parent := box.getParent()
|
||||
for {
|
||||
parentBox, ok := parent.(anyBox)
|
||||
if !ok { break }
|
||||
if parent.masks() {
|
||||
return true
|
||||
}
|
||||
parent = parentBox.getParent()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *Hierarchy) focusNext () {
|
||||
found := !this.anyFocused()
|
||||
focused := false
|
||||
this.propagateAlt(func (box anyBox) bool {
|
||||
if found {
|
||||
// looking for the next box to select
|
||||
if box.canBeFocused() {
|
||||
if box.canBeFocused() && !this.isMasked(box) {
|
||||
// found it
|
||||
this.focus(box)
|
||||
focused = true
|
||||
@@ -318,7 +331,7 @@ func (this *Hierarchy) focusPrevious () {
|
||||
if box == this.focused {
|
||||
return false
|
||||
}
|
||||
if box.canBeFocused() { behind = box }
|
||||
if box.canBeFocused() && !this.isMasked(box) { behind = box }
|
||||
return true
|
||||
})
|
||||
this.focus(behind)
|
||||
|
||||
@@ -167,6 +167,7 @@ func (this *textBox) setAttr (attr tomo.Attr, user bool) {
|
||||
|
||||
case tomo.AttrOverflow:
|
||||
if this.attrOverflow.Set(attr, user) {
|
||||
this.invalidateMinimum()
|
||||
this.invalidateLayout()
|
||||
}
|
||||
|
||||
@@ -248,14 +249,18 @@ func (this *textBox) textOffset () image.Point {
|
||||
Sub(this.drawer.LayoutBoundsSpace().Min)
|
||||
}
|
||||
|
||||
func (this *textBox) handleFocusEnter () {
|
||||
this.invalidateDraw()
|
||||
this.box.handleFocusEnter()
|
||||
}
|
||||
|
||||
func (this *textBox) handleFocusLeave () {
|
||||
this.on.dotChange.Broadcast()
|
||||
this.invalidateDraw()
|
||||
this.box.handleFocusLeave()
|
||||
}
|
||||
|
||||
func (this *textBox) handleMouseDown (button input.Button) bool {
|
||||
if button == input.ButtonLeft {
|
||||
if this.mouseButtonCanDrag(button) {
|
||||
index := this.runeUnderMouse()
|
||||
this.selectStart = index
|
||||
this.selecting = true
|
||||
@@ -265,7 +270,7 @@ func (this *textBox) handleMouseDown (button input.Button) bool {
|
||||
}
|
||||
|
||||
func (this *textBox) handleMouseUp (button input.Button) bool {
|
||||
if button == input.ButtonLeft && this.selecting {
|
||||
if this.mouseButtonCanDrag(button) && this.selecting {
|
||||
index := this.runeUnderMouse()
|
||||
this.selecting = false
|
||||
this.Select(text.Dot { Start: this.selectStart, End: index })
|
||||
@@ -273,6 +278,12 @@ func (this *textBox) handleMouseUp (button input.Button) bool {
|
||||
return this.box.handleMouseUp(button)
|
||||
}
|
||||
|
||||
func (this *textBox) mouseButtonCanDrag (button input.Button) bool {
|
||||
return button == input.ButtonLeft ||
|
||||
button == input.ButtonMiddle ||
|
||||
button == input.ButtonRight
|
||||
}
|
||||
|
||||
func (this *textBox) handleMouseMove () bool {
|
||||
if this.selecting {
|
||||
index := this.runeUnderMouse()
|
||||
@@ -290,7 +301,7 @@ func (this *textBox) runeUnderMouse () int {
|
||||
|
||||
func (this *textBox) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||
if this.box.handleKeyDown(key, numberPad) { return true }
|
||||
if this.selectable { return false }
|
||||
if !this.selectable { return false }
|
||||
|
||||
// because fuck you thats why!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
modifiers := this.Window().Modifiers()
|
||||
@@ -334,7 +345,7 @@ func (this *textBox) handleKeyDown (key input.Key, numberPad bool) bool {
|
||||
|
||||
func (this *textBox) handleKeyUp (key input.Key, numberPad bool) bool {
|
||||
if this.box.handleKeyUp(key, numberPad) { return true }
|
||||
if this.selectable { return false }
|
||||
if !this.selectable { return false }
|
||||
|
||||
modifiers := this.Window().Modifiers()
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user