package ui import ( "log" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" ) type InputType int const ( Click InputType = iota + 1 Scroll Text ) type InputEvent struct { kind InputType x, y int ctx any } type ClickCtx struct { btn ebiten.MouseButton } type ScrollCtx struct { scrollX, scrollY int } type TextCtx struct { in []rune } // Input queue var Input []InputEvent func consumeInput(i int) { log.Println("consume input", i) if len(Input) == 1 { Input = []InputEvent{} } else { Input[i] = Input[len(Input)-1] } } // Update all ui singletons and collect all occurred input func Update() error { Input = []InputEvent{} if err := TouchManager.Update(); err != nil { return err } // TODO: make hover detector a singleton x, y := ebiten.CursorPosition() scrollX, scrollY := ebiten.Wheel() if scrollX != 0 || scrollY != 0 { Input = append(Input, InputEvent{Scroll, x, y, ScrollCtx{int(scrollX), int(scrollY)}}) } var in []rune in = ebiten.AppendInputChars(in) if len(in) > 0 { Input = append(Input, InputEvent{Text, x, y, TextCtx{in}}) } if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) { Input = append(Input, InputEvent{Click, x, y, ClickCtx{ebiten.MouseButtonLeft}}) } return nil }