Upgrade tomo version
This commit is contained in:
parent
c91d4577e7
commit
2ecfafa469
11
box.go
11
box.go
@ -259,6 +259,11 @@ func (this *box) handleMouseUp (button input.Button) {
|
|||||||
listener(button)
|
listener(button)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func (this *box) handleScroll (x, y float64) {
|
||||||
|
for _, listener := range this.on.scroll.Listeners() {
|
||||||
|
listener(x, y)
|
||||||
|
}
|
||||||
|
}
|
||||||
func (this *box) handleKeyDown (key input.Key, numberPad bool) {
|
func (this *box) handleKeyDown (key input.Key, numberPad bool) {
|
||||||
for _, listener := range this.on.keyDown.Listeners() {
|
for _, listener := range this.on.keyDown.Listeners() {
|
||||||
listener(key, numberPad)
|
listener(key, numberPad)
|
||||||
@ -374,6 +379,10 @@ func (this *box) setParent (parent parent) {
|
|||||||
this.parent = parent
|
this.parent = parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *box) getParent () parent {
|
||||||
|
return this.parent
|
||||||
|
}
|
||||||
|
|
||||||
func (this *box) flushActionQueue () {
|
func (this *box) flushActionQueue () {
|
||||||
if this.parent == nil || this.parent.window() == nil { return }
|
if this.parent == nil || this.parent.window() == nil { return }
|
||||||
|
|
||||||
@ -412,7 +421,7 @@ func (this *box) canBeFocused () bool {
|
|||||||
return this.focusable
|
return this.focusable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *box) boxUnder (point image.Point) anyBox {
|
func (this *box) boxUnder (point image.Point, category eventCategory) anyBox {
|
||||||
if point.In(this.bounds) {
|
if point.In(this.bounds) {
|
||||||
return this.outer
|
return this.outer
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,11 +13,11 @@ type containerBox struct {
|
|||||||
hAlign, vAlign tomo.Align
|
hAlign, vAlign tomo.Align
|
||||||
contentBounds image.Rectangle
|
contentBounds image.Rectangle
|
||||||
scroll image.Point
|
scroll image.Point
|
||||||
|
capture [4]bool
|
||||||
|
|
||||||
gap image.Point
|
gap image.Point
|
||||||
children []tomo.Box
|
children []tomo.Box
|
||||||
layout tomo.Layout
|
layout tomo.Layout
|
||||||
propagateEvents bool
|
|
||||||
|
|
||||||
on struct {
|
on struct {
|
||||||
contentBoundsChange event.FuncBroadcaster
|
contentBoundsChange event.FuncBroadcaster
|
||||||
@ -25,7 +25,7 @@ type containerBox struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) NewContainerBox() tomo.ContainerBox {
|
func (backend *Backend) NewContainerBox() tomo.ContainerBox {
|
||||||
this := &containerBox { propagateEvents: true }
|
this := &containerBox { }
|
||||||
this.box = backend.newBox(this)
|
this.box = backend.newBox(this)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@ -68,8 +68,20 @@ func (this *containerBox) OnContentBoundsChange (callback func()) event.Cookie {
|
|||||||
return this.on.contentBoundsChange.Connect(callback)
|
return this.on.contentBoundsChange.Connect(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *containerBox) SetPropagateEvents (propagate bool) {
|
func (this *containerBox) CaptureDND (capture bool) {
|
||||||
this.propagateEvents = propagate
|
this.capture[eventCategoryDND] = capture
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *containerBox) CaptureMouse (capture bool) {
|
||||||
|
this.capture[eventCategoryMouse] = capture
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *containerBox) CaptureScroll (capture bool) {
|
||||||
|
this.capture[eventCategoryScroll] = capture
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *containerBox) CaptureKeyboard (capture bool) {
|
||||||
|
this.capture[eventCategoryKeyboard] = capture
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *containerBox) SetGap (gap image.Point) {
|
func (this *containerBox) SetGap (gap image.Point) {
|
||||||
@ -175,7 +187,7 @@ func (this *containerBox) drawBackgroundPart (can canvas.Canvas) {
|
|||||||
|
|
||||||
func (this *containerBox) invalidateTransparentChildren () {
|
func (this *containerBox) invalidateTransparentChildren () {
|
||||||
window := this.window()
|
window := this.window()
|
||||||
if this.window == nil { return }
|
if window == nil { return }
|
||||||
for _, box := range this.children {
|
for _, box := range this.children {
|
||||||
box := assertAnyBox(box)
|
box := assertAnyBox(box)
|
||||||
if box.transparent() {
|
if box.transparent() {
|
||||||
@ -251,15 +263,15 @@ func (this *containerBox) recursiveRedo () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *containerBox) boxUnder (point image.Point) anyBox {
|
func (this *containerBox) boxUnder (point image.Point, category eventCategory) anyBox {
|
||||||
if this.propagateEvents {
|
if !this.capture[category] {
|
||||||
for _, box := range this.children {
|
for _, box := range this.children {
|
||||||
candidate := box.(anyBox).boxUnder(point)
|
candidate := box.(anyBox).boxUnder(point, category)
|
||||||
if candidate != nil { return candidate }
|
if candidate != nil { return candidate }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.box.boxUnder(point)
|
return this.box.boxUnder(point, category)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *containerBox) propagate (callback func (anyBox) bool) bool {
|
func (this *containerBox) propagate (callback func (anyBox) bool) bool {
|
||||||
@ -281,3 +293,7 @@ func (this *containerBox) propagateAlt (callback func (anyBox) bool) bool {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *containerBox) captures (category eventCategory) bool {
|
||||||
|
return this.capture[category]
|
||||||
|
}
|
||||||
|
79
event.go
79
event.go
@ -8,6 +8,31 @@ import "git.tebibyte.media/tomo/xgbkb"
|
|||||||
import "github.com/jezek/xgbutil/xevent"
|
import "github.com/jezek/xgbutil/xevent"
|
||||||
import "git.tebibyte.media/tomo/tomo/input"
|
import "git.tebibyte.media/tomo/tomo/input"
|
||||||
|
|
||||||
|
type scrollSum struct {
|
||||||
|
x, y int
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: this needs to be configurable, we need a config api
|
||||||
|
const scrollDistance = 16
|
||||||
|
|
||||||
|
func (sum *scrollSum) add (button xproto.Button, window *window, state uint16) {
|
||||||
|
if xgbkb.StateToModifiers(state).Shift {
|
||||||
|
switch button {
|
||||||
|
case 4: sum.x -= scrollDistance
|
||||||
|
case 5: sum.x += scrollDistance
|
||||||
|
case 6: sum.y -= scrollDistance
|
||||||
|
case 7: sum.y += scrollDistance
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch button {
|
||||||
|
case 4: sum.y -= scrollDistance
|
||||||
|
case 5: sum.y += scrollDistance
|
||||||
|
case 6: sum.x -= scrollDistance
|
||||||
|
case 7: sum.x += scrollDistance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var buttonCodeTable = map[xproto.Keysym] input.Key {
|
var buttonCodeTable = map[xproto.Keysym] input.Key {
|
||||||
0xFFFFFF: input.KeyNone,
|
0xFFFFFF: input.KeyNone,
|
||||||
|
|
||||||
@ -208,7 +233,7 @@ func (window *window) handleKeyPress (
|
|||||||
} else if key == input.KeyEscape && window.shy {
|
} else if key == input.KeyEscape && window.shy {
|
||||||
window.Close()
|
window.Close()
|
||||||
} else if window.focused != nil {
|
} else if window.focused != nil {
|
||||||
window.focused.handleKeyDown(key, numberPad)
|
window.keyboardTarget().handleKeyDown(key, numberPad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +266,7 @@ func (window *window) handleKeyRelease (
|
|||||||
window.updateModifiers(keyEvent.State)
|
window.updateModifiers(keyEvent.State)
|
||||||
|
|
||||||
if window.focused != nil {
|
if window.focused != nil {
|
||||||
window.focused.handleKeyUp(key, numberPad)
|
window.keyboardTarget().handleKeyUp(key, numberPad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,20 +286,15 @@ func (window *window) handleButtonPress (
|
|||||||
if !insideWindow && window.shy && !scrolling {
|
if !insideWindow && window.shy && !scrolling {
|
||||||
window.Close()
|
window.Close()
|
||||||
} else if scrolling {
|
} else if scrolling {
|
||||||
// TODO
|
underneath := window.boxUnder(point, eventCategoryScroll)
|
||||||
// underneath := window.scrollTargetChildAt(point)
|
if underneath != nil {
|
||||||
// if underneath != nil {
|
sum := scrollSum { }
|
||||||
// if child, ok := underneath.element.(ability.ScrollTarget); ok {
|
sum.add(buttonEvent.Detail, window, buttonEvent.State)
|
||||||
// sum := scrollSum { }
|
window.compressScrollSum(buttonEvent, &sum)
|
||||||
// sum.add(buttonEvent.Detail, window, buttonEvent.State)
|
underneath.handleScroll(float64(sum.x), float64(sum.y))
|
||||||
// window.compressScrollSum(buttonEvent, &sum)
|
}
|
||||||
// child.HandleScroll (
|
|
||||||
// point, float64(sum.x), float64(sum.y),
|
|
||||||
// modifiers)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
underneath := window.boxUnder(point)
|
underneath := window.boxUnder(point, eventCategoryMouse)
|
||||||
window.drags[buttonEvent.Detail] = underneath
|
window.drags[buttonEvent.Detail] = underneath
|
||||||
if underneath != nil {
|
if underneath != nil {
|
||||||
underneath.handleMouseDown(input.Button(buttonEvent.Detail))
|
underneath.handleMouseDown(input.Button(buttonEvent.Detail))
|
||||||
@ -318,7 +338,7 @@ func (window *window) handleMotionNotify (
|
|||||||
handled = true
|
handled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
underneath := window.boxUnder(image.Pt(x, y))
|
underneath := window.boxUnder(image.Pt(x, y), eventCategoryMouse)
|
||||||
window.hover(underneath)
|
window.hover(underneath)
|
||||||
|
|
||||||
if !handled {
|
if !handled {
|
||||||
@ -391,6 +411,33 @@ func (window *window) compressConfigureNotify (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (window *window) compressScrollSum (
|
||||||
|
firstEvent xproto.ButtonPressEvent,
|
||||||
|
sum *scrollSum,
|
||||||
|
) {
|
||||||
|
window.backend.x.Sync()
|
||||||
|
xevent.Read(window.backend.x, false)
|
||||||
|
|
||||||
|
for index, untypedEvent := range xevent.Peek(window.backend.x) {
|
||||||
|
if untypedEvent.Err != nil { continue }
|
||||||
|
|
||||||
|
typedEvent, ok := untypedEvent.Event.(xproto.ButtonPressEvent)
|
||||||
|
if !ok { continue }
|
||||||
|
|
||||||
|
if firstEvent.Event == typedEvent.Event &&
|
||||||
|
typedEvent.Detail >= 4 &&
|
||||||
|
typedEvent.Detail <= 7 {
|
||||||
|
|
||||||
|
sum.add(typedEvent.Detail, window, typedEvent.State)
|
||||||
|
defer func (index int) {
|
||||||
|
xevent.DequeueAt(window.backend.x, index)
|
||||||
|
} (index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (window *window) compressMotionNotify (
|
func (window *window) compressMotionNotify (
|
||||||
firstEvent xproto.MotionNotifyEvent,
|
firstEvent xproto.MotionNotifyEvent,
|
||||||
) (
|
) (
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.tebibyte.media/tomo/x
|
|||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.tebibyte.media/tomo/tomo v0.28.0
|
git.tebibyte.media/tomo/tomo v0.29.0
|
||||||
git.tebibyte.media/tomo/typeset v0.5.2
|
git.tebibyte.media/tomo/typeset v0.5.2
|
||||||
git.tebibyte.media/tomo/xgbkb v1.0.1
|
git.tebibyte.media/tomo/xgbkb v1.0.1
|
||||||
github.com/jezek/xgb v1.1.0
|
github.com/jezek/xgb v1.1.0
|
||||||
|
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/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
|
||||||
git.tebibyte.media/tomo/tomo v0.28.0 h1:wB+RpYw48Jn2DUQhXwdUe54BnYJf/79On3jxnBYvQ1Q=
|
git.tebibyte.media/tomo/tomo v0.29.0 h1:uvdPaEQYcWH965y85SjIKwhLklnTbs+x6MRwLfdRvfo=
|
||||||
git.tebibyte.media/tomo/tomo v0.28.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
git.tebibyte.media/tomo/tomo v0.29.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
|
||||||
git.tebibyte.media/tomo/typeset v0.5.2 h1:qHxN62/VDnrAouOuzxLmLleQNwAebshrfVYvtoOnAG4=
|
git.tebibyte.media/tomo/typeset v0.5.2 h1:qHxN62/VDnrAouOuzxLmLleQNwAebshrfVYvtoOnAG4=
|
||||||
git.tebibyte.media/tomo/typeset v0.5.2/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
|
git.tebibyte.media/tomo/typeset v0.5.2/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
|
||||||
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=
|
git.tebibyte.media/tomo/xgbkb v1.0.1 h1:b3HDUopjdQp1MZrb5Vpil4bOtk3NnNXtfQW27Blw2kE=
|
||||||
|
37
system.go
37
system.go
@ -37,6 +37,7 @@ type parent interface {
|
|||||||
canvas () canvas.Canvas
|
canvas () canvas.Canvas
|
||||||
notifyMinimumSizeChange (anyBox)
|
notifyMinimumSizeChange (anyBox)
|
||||||
drawBackgroundPart (canvas.Canvas)
|
drawBackgroundPart (canvas.Canvas)
|
||||||
|
captures (eventCategory) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type anyBox interface {
|
type anyBox interface {
|
||||||
@ -48,10 +49,11 @@ type anyBox interface {
|
|||||||
doMinimumSize ()
|
doMinimumSize ()
|
||||||
contentMinimum () image.Point
|
contentMinimum () image.Point
|
||||||
setParent (parent)
|
setParent (parent)
|
||||||
|
getParent () parent
|
||||||
flushActionQueue ()
|
flushActionQueue ()
|
||||||
recursiveRedo ()
|
recursiveRedo ()
|
||||||
canBeFocused () bool
|
canBeFocused () bool
|
||||||
boxUnder (image.Point) anyBox
|
boxUnder (image.Point, eventCategory) anyBox
|
||||||
transparent () bool
|
transparent () bool
|
||||||
|
|
||||||
propagate (func (anyBox) bool) bool
|
propagate (func (anyBox) bool) bool
|
||||||
@ -67,7 +69,7 @@ type anyBox interface {
|
|||||||
handleMouseMove ()
|
handleMouseMove ()
|
||||||
handleMouseDown (input.Button)
|
handleMouseDown (input.Button)
|
||||||
handleMouseUp (input.Button)
|
handleMouseUp (input.Button)
|
||||||
// handleScroll (float64, float64)
|
handleScroll (float64, float64)
|
||||||
handleKeyDown (input.Key, bool)
|
handleKeyDown (input.Key, bool)
|
||||||
handleKeyUp (input.Key, bool)
|
handleKeyUp (input.Key, bool)
|
||||||
}
|
}
|
||||||
@ -153,9 +155,36 @@ func (window *window) anyFocused () bool {
|
|||||||
return window.focused != nil
|
return window.focused != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *window) boxUnder (point image.Point) anyBox {
|
type eventCategory int; const (
|
||||||
|
eventCategoryDND eventCategory = iota
|
||||||
|
eventCategoryMouse
|
||||||
|
eventCategoryScroll
|
||||||
|
eventCategoryKeyboard
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this *window) boxUnder (point image.Point, category eventCategory) anyBox {
|
||||||
if this.root == nil { return nil }
|
if this.root == nil { return nil }
|
||||||
return this.root.boxUnder(point)
|
return this.root.boxUnder(point, category)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *window) captures (eventCategory) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *window) keyboardTarget () anyBox {
|
||||||
|
focused := this.window().focused
|
||||||
|
if focused == nil { return nil }
|
||||||
|
parent := focused.getParent()
|
||||||
|
for {
|
||||||
|
parentBox, ok := parent.(anyBox)
|
||||||
|
if !ok { break }
|
||||||
|
if parent.captures(eventCategoryKeyboard) {
|
||||||
|
return parentBox
|
||||||
|
}
|
||||||
|
parent = parentBox.getParent()
|
||||||
|
}
|
||||||
|
|
||||||
|
return focused
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *window) focusNext () {
|
func (this *window) focusNext () {
|
||||||
|
@ -298,7 +298,7 @@ func (this *textBox) doLayout () {
|
|||||||
this.drawer.SetMaxWidth(innerBounds.Dx())
|
this.drawer.SetMaxWidth(innerBounds.Dx())
|
||||||
this.drawer.SetMaxHeight(innerBounds.Dy())
|
this.drawer.SetMaxHeight(innerBounds.Dy())
|
||||||
|
|
||||||
this.contentBounds = this.normalizedLayoutBoundsSpace().Sub(this.scroll)
|
this.contentBounds = this.normalizedLayoutBoundsSpace().Add(this.scroll)
|
||||||
|
|
||||||
if previousContentBounds != this.contentBounds {
|
if previousContentBounds != this.contentBounds {
|
||||||
this.on.contentBoundsChange.Broadcast()
|
this.on.contentBoundsChange.Broadcast()
|
||||||
|
14
window.go
14
window.go
@ -73,6 +73,20 @@ func (backend *Backend) NewWindow (
|
|||||||
return output, err
|
return output, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (backend *Backend) NewPlainWindow (
|
||||||
|
bounds image.Rectangle,
|
||||||
|
) (
|
||||||
|
output tomo.MainWindow,
|
||||||
|
err error,
|
||||||
|
) {
|
||||||
|
backend.assert()
|
||||||
|
window, err := backend.newWindow(bounds, false)
|
||||||
|
window.setType("dock")
|
||||||
|
|
||||||
|
output = mainWindow { window: window }
|
||||||
|
return output, err
|
||||||
|
}
|
||||||
|
|
||||||
func (backend *Backend) newWindow (
|
func (backend *Backend) newWindow (
|
||||||
bounds image.Rectangle,
|
bounds image.Rectangle,
|
||||||
override bool,
|
override bool,
|
||||||
|
Reference in New Issue
Block a user