Made this crazy selection system

This commit is contained in:
2023-04-17 02:05:53 -04:00
parent 775390e884
commit 5ca3b80e8e
9 changed files with 251 additions and 10 deletions

View File

@@ -15,6 +15,7 @@ type entity struct {
minWidth int
minHeight int
selected bool
layoutInvalid bool
isContainer bool
}
@@ -42,6 +43,11 @@ func (ent *entity) unlink () {
}
ent.parent = nil
ent.window = nil
if element, ok := ent.element.(tomo.Selectable); ok {
ent.selected = false
element.HandleSelectionChange()
}
}
func (entity *entity) link (parent *entity) {
@@ -96,6 +102,14 @@ func (entity *entity) scrollTargetChildAt (point image.Point) *entity {
return nil
}
func (entity *entity) forMouseTargetContainers (callback func (tomo.MouseTargetContainer)) {
if entity.parent == nil { return }
if parent, ok := entity.parent.element.(tomo.MouseTargetContainer); ok {
callback(parent)
}
entity.parent.forMouseTargetContainers(callback)
}
// ----------- Entity ----------- //
func (entity *entity) Invalidate () {
@@ -195,6 +209,14 @@ func (entity *entity) PlaceChild (index int, bounds image.Rectangle) {
child.InvalidateLayout()
}
func (entity *entity) SelectChild (index int, selected bool) {
child := entity.children[index]
if element, ok := entity.element.(tomo.Selectable); ok {
child.selected = selected
element.HandleSelectionChange()
}
}
func (entity *entity) ChildMinimumSize (index int) (width, height int) {
childEntity := entity.children[index]
return childEntity.minWidth, childEntity.minHeight
@@ -220,6 +242,12 @@ func (entity *entity) FocusPrevious () {
entity.window.system.focusPrevious()
}
// ----------- SelectableEntity ----------- //
func (entity *entity) Selected () bool {
return entity.selected
}
// ----------- FlexibleEntity ----------- //
func (entity *entity) NotifyFlexibleHeightChange () {

View File

@@ -206,12 +206,19 @@ func (window *window) handleButtonPress (
}
} else {
underneath := window.system.childAt(point)
window.system.drags[buttonEvent.Detail] = underneath
if child, ok := underneath.element.(tomo.MouseTarget); ok {
window.system.drags[buttonEvent.Detail] = child
child.HandleMouseDown (
point.X, point.Y,
input.Button(buttonEvent.Detail))
}
callback := func (container tomo.MouseTargetContainer) {
container.HandleChildMouseDown (
point.X, point.Y,
input.Button(buttonEvent.Detail),
underneath.element)
}
underneath.forMouseTargetContainers(callback)
}
window.system.afterEvent()
@@ -223,12 +230,22 @@ func (window *window) handleButtonRelease (
) {
buttonEvent := *event.ButtonReleaseEvent
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { return }
child := window.system.drags[buttonEvent.Detail]
if child != nil {
child.HandleMouseUp (
dragging := window.system.drags[buttonEvent.Detail]
if dragging != nil {
if child, ok := dragging.element.(tomo.MouseTarget); ok {
child.HandleMouseUp (
int(buttonEvent.EventX),
int(buttonEvent.EventY),
input.Button(buttonEvent.Detail))
}
callback := func (container tomo.MouseTargetContainer) {
container.HandleChildMouseUp (
int(buttonEvent.EventX),
int(buttonEvent.EventY),
input.Button(buttonEvent.Detail))
input.Button(buttonEvent.Detail),
dragging.element)
}
dragging.forMouseTargetContainers(callback)
}
window.system.afterEvent()
@@ -244,7 +261,7 @@ func (window *window) handleMotionNotify (
handled := false
for _, child := range window.system.drags {
if child, ok := child.(tomo.MotionTarget); ok {
if child, ok := child.element.(tomo.MotionTarget); ok {
child.HandleMotion(x, y)
handled = true
}

View File

@@ -33,7 +33,7 @@ type system struct {
drawingInvalid entitySet
anyLayoutInvalid bool
drags [10]tomo.MouseTarget
drags [10]*entity
pushFunc func (image.Rectangle)
}