ui: change events to have "Event" suffixed, not prefixed

Match the Go error naming convention (FooError).

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-06-21 17:08:34 +02:00
parent de5d5e19f5
commit 0b6dd4efd9
12 changed files with 64 additions and 64 deletions
+7 -7
View File
@@ -14,7 +14,7 @@ type Event interface {
ImplementsEvent() ImplementsEvent()
} }
type Draw struct { type DrawEvent struct {
Config ui.Config Config ui.Config
Size image.Point Size image.Point
// Whether this draw is system generated // Whether this draw is system generated
@@ -23,12 +23,12 @@ type Draw struct {
sync bool sync bool
} }
type ChangeStage struct { type StageEvent struct {
Stage Stage Stage Stage
} }
// Command is a system event. // CommandEvent is a system event.
type Command struct { type CommandEvent struct {
Type CommandType Type CommandType
// Suppress the default action of the command. // Suppress the default action of the command.
Cancel bool Cancel bool
@@ -110,9 +110,9 @@ func (l Stage) String() string {
} }
} }
func (_ Draw) ImplementsEvent() {} func (_ DrawEvent) ImplementsEvent() {}
func (_ ChangeStage) ImplementsEvent() {} func (_ StageEvent) ImplementsEvent() {}
func (_ *Command) ImplementsEvent() {} func (_ *CommandEvent) ImplementsEvent() {}
func init() { func init() {
args := strings.Split(extraArgs, "|") args := strings.Split(extraArgs, "|")
+6 -6
View File
@@ -183,7 +183,7 @@ func onFrameCallback(env *C.JNIEnv, class C.jclass, view C.jlong, nanos C.jlong)
//export onBack //export onBack
func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean { func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean {
w := views[view] w := views[view]
ev := &Command{Type: CommandBack} ev := &CommandEvent{Type: CommandBack}
w.event(ev) w.event(ev)
if ev.Cancel { if ev.Cancel {
return C.JNI_TRUE return C.JNI_TRUE
@@ -194,7 +194,7 @@ func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean {
//export onFocusChange //export onFocusChange
func onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) { func onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
w := views[view] w := views[view]
w.event(key.Focus{Focus: focus == C.JNI_TRUE}) w.event(key.FocusEvent{Focus: focus == C.JNI_TRUE})
} }
func (w *window) setVisible() { func (w *window) setVisible() {
@@ -212,7 +212,7 @@ func (w *window) setStage(stage Stage) {
return return
} }
w.stage = stage w.stage = stage
w.event(ChangeStage{stage}) w.event(StageEvent{stage})
} }
func (w *window) display() unsafe.Pointer { func (w *window) display() unsafe.Pointer {
@@ -270,7 +270,7 @@ func (w *window) draw(sync bool) {
return return
} }
ppdp := float32(w.dpi) * inchPrDp ppdp := float32(w.dpi) * inchPrDp
w.event(Draw{ w.event(DrawEvent{
Size: image.Point{ Size: image.Point{
X: int(width), X: int(width),
Y: int(height), Y: int(height),
@@ -334,10 +334,10 @@ func convertKeyCode(code C.jint) (rune, bool) {
func onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, keyCode, r C.jint, t C.jlong) { func onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, keyCode, r C.jint, t C.jlong) {
w := views[handle] w := views[handle]
if n, ok := convertKeyCode(keyCode); ok { if n, ok := convertKeyCode(keyCode); ok {
w.event(key.Chord{Name: n}) w.event(key.ChordEvent{Name: n})
} }
if r != 0 { if r != 0 {
w.event(key.Edit{Text: string(rune(r))}) w.event(key.EditEvent{Text: string(rune(r))})
} }
} }
+8 -8
View File
@@ -59,7 +59,7 @@ func onCreate(view C.CFTypeRef) {
C.gio_addLayerToView(view, w.layer) C.gio_addLayerToView(view, w.layer)
views[view] = w views[view] = w
windows <- ow windows <- ow
w.w.event(ChangeStage{StagePaused}) w.w.event(StageEvent{StagePaused})
} }
//export onDraw //export onDraw
@@ -72,13 +72,13 @@ func onDraw(view C.CFTypeRef, dpi, sdpi, width, height C.CGFloat, sync C.int) {
w.visible.Store(true) w.visible.Store(true)
C.gio_updateView(view, w.layer) C.gio_updateView(view, w.layer)
if !wasVisible { if !wasVisible {
w.w.event(ChangeStage{StageRunning}) w.w.event(StageEvent{StageRunning})
} }
isSync := false isSync := false
if sync != 0 { if sync != 0 {
isSync = true isSync = true
} }
w.w.event(Draw{ w.w.event(DrawEvent{
Size: image.Point{ Size: image.Point{
X: int(width + .5), X: int(width + .5),
Y: int(height + .5), Y: int(height + .5),
@@ -96,14 +96,14 @@ func onDraw(view C.CFTypeRef, dpi, sdpi, width, height C.CGFloat, sync C.int) {
func onStop(view C.CFTypeRef) { func onStop(view C.CFTypeRef) {
w := views[view] w := views[view]
w.visible.Store(false) w.visible.Store(false)
w.w.event(ChangeStage{StagePaused}) w.w.event(StageEvent{StagePaused})
} }
//export onDestroy //export onDestroy
func onDestroy(view C.CFTypeRef) { func onDestroy(view C.CFTypeRef) {
w := views[view] w := views[view]
delete(views, view) delete(views, view)
w.w.event(ChangeStage{StageDead}) w.w.event(StageEvent{StageDead})
C.gio_removeLayer(w.layer) C.gio_removeLayer(w.layer)
C.CFRelease(w.layer) C.CFRelease(w.layer)
w.layer = 0 w.layer = 0
@@ -113,7 +113,7 @@ func onDestroy(view C.CFTypeRef) {
//export onFocus //export onFocus
func onFocus(view C.CFTypeRef, focus int) { func onFocus(view C.CFTypeRef, focus int) {
w := views[view] w := views[view]
w.w.event(key.Focus{Focus: focus != 0}) w.w.event(key.FocusEvent{Focus: focus != 0})
} }
//export onLowMemory //export onLowMemory
@@ -150,7 +150,7 @@ func onDeleteBackward(view C.CFTypeRef) {
//export onText //export onText
func onText(view C.CFTypeRef, str *C.char) { func onText(view C.CFTypeRef, str *C.char) {
w := views[view] w := views[view]
w.w.event(key.Edit{ w.w.event(key.EditEvent{
Text: C.GoString(str), Text: C.GoString(str),
}) })
} }
@@ -194,7 +194,7 @@ func (w *window) setAnimating(anim bool) {
} }
func (w *window) onKeyCommand(name rune) { func (w *window) onKeyCommand(name rune) {
w.w.event(key.Chord{ w.w.event(key.ChordEvent{
Name: name, Name: name,
}) })
} }
+6 -6
View File
@@ -57,7 +57,7 @@ func createWindow(opts *WindowOptions) error {
go func() { go func() {
windows <- w.w windows <- w.w
w.focus() w.focus()
w.w.event(ChangeStage{StageRunning}) w.w.event(StageEvent{StageRunning})
w.draw(true) w.draw(true)
select {} select {}
w.cleanup() w.cleanup()
@@ -156,11 +156,11 @@ func (w *window) addEventListeners() {
return nil return nil
}) })
w.addEventListener(w.tarea, "focus", func(this js.Value, args []js.Value) interface{} { w.addEventListener(w.tarea, "focus", func(this js.Value, args []js.Value) interface{} {
w.w.event(key.Focus{Focus: true}) w.w.event(key.FocusEvent{Focus: true})
return nil return nil
}) })
w.addEventListener(w.tarea, "blur", func(this js.Value, args []js.Value) interface{} { w.addEventListener(w.tarea, "blur", func(this js.Value, args []js.Value) interface{} {
w.w.event(key.Focus{Focus: false}) w.w.event(key.FocusEvent{Focus: false})
return nil return nil
}) })
w.addEventListener(w.tarea, "keydown", func(this js.Value, args []js.Value) interface{} { w.addEventListener(w.tarea, "keydown", func(this js.Value, args []js.Value) interface{} {
@@ -188,7 +188,7 @@ func (w *window) addEventListeners() {
func (w *window) flushInput() { func (w *window) flushInput() {
val := w.tarea.Get("value").String() val := w.tarea.Get("value").String()
w.tarea.Set("value", "") w.tarea.Set("value", "")
w.w.event(key.Edit{Text: string(val)}) w.w.event(key.EditEvent{Text: string(val)})
} }
func (w *window) blur() { func (w *window) blur() {
@@ -202,7 +202,7 @@ func (w *window) focus() {
func (w *window) keyEvent(e js.Value) { func (w *window) keyEvent(e js.Value) {
k := e.Get("key").String() k := e.Get("key").String()
if n, ok := translateKey(k); ok { if n, ok := translateKey(k); ok {
cmd := key.Chord{Name: n} cmd := key.ChordEvent{Name: n}
if e.Call("getModifierState", "Control").Bool() { if e.Call("getModifierState", "Control").Bool() {
cmd.Modifiers |= key.ModCommand cmd.Modifiers |= key.ModCommand
} }
@@ -336,7 +336,7 @@ func (w *window) draw(sync bool) {
w.scale = float32(scale) w.scale = float32(scale)
w.mu.Unlock() w.mu.Unlock()
cfg.Now = time.Now() cfg.Now = time.Now()
w.w.event(Draw{ w.w.event(DrawEvent{
Size: image.Point{ Size: image.Point{
X: width, X: width,
Y: height, Y: height,
+5 -5
View File
@@ -66,7 +66,7 @@ func (w *window) setStage(stage Stage) {
return return
} }
w.stage = stage w.stage = stage
w.w.event(ChangeStage{stage}) w.w.event(StageEvent{stage})
} }
//export gio_onFrameCallback //export gio_onFrameCallback
@@ -88,7 +88,7 @@ func gio_onKeys(view C.CFTypeRef, cstr *C.char, ti C.double, mods C.NSUInteger)
w := views[view] w := views[view]
for _, k := range str { for _, k := range str {
if n, ok := convertKey(k); ok { if n, ok := convertKey(k); ok {
w.w.event(key.Chord{Name: n, Modifiers: kmods}) w.w.event(key.ChordEvent{Name: n, Modifiers: kmods})
} }
} }
} }
@@ -97,7 +97,7 @@ func gio_onKeys(view C.CFTypeRef, cstr *C.char, ti C.double, mods C.NSUInteger)
func gio_onText(view C.CFTypeRef, cstr *C.char) { func gio_onText(view C.CFTypeRef, cstr *C.char) {
str := C.GoString(cstr) str := C.GoString(cstr)
w := views[view] w := views[view]
w.w.event(key.Edit{Text: str}) w.w.event(key.EditEvent{Text: str})
} }
//export gio_onMouse //export gio_onMouse
@@ -133,7 +133,7 @@ func gio_onDraw(view C.CFTypeRef) {
//export gio_onFocus //export gio_onFocus
func gio_onFocus(view C.CFTypeRef, focus C.BOOL) { func gio_onFocus(view C.CFTypeRef, focus C.BOOL) {
w := views[view] w := views[view]
w.w.event(key.Focus{Focus: focus == C.YES}) w.w.event(key.FocusEvent{Focus: focus == C.YES})
} }
func (w *window) draw(sync bool) { func (w *window) draw(sync bool) {
@@ -144,7 +144,7 @@ func (w *window) draw(sync bool) {
cfg := getConfig() cfg := getConfig()
cfg.Now = time.Now() cfg.Now = time.Now()
w.setStage(StageRunning) w.setStage(StageRunning)
w.w.event(Draw{ w.w.event(DrawEvent{
Size: image.Point{ Size: image.Point{
X: width, X: width,
Y: height, Y: height,
+6 -6
View File
@@ -644,14 +644,14 @@ func gio_onKeyboardEnter(data unsafe.Pointer, keyboard *C.struct_wl_keyboard, se
conn.repeat.Stop(0) conn.repeat.Stop(0)
w := winMap[surf] w := winMap[surf]
winMap[keyboard] = w winMap[keyboard] = w
w.w.event(key.Focus{Focus: true}) w.w.event(key.FocusEvent{Focus: true})
} }
//export gio_onKeyboardLeave //export gio_onKeyboardLeave
func gio_onKeyboardLeave(data unsafe.Pointer, keyboard *C.struct_wl_keyboard, serial C.uint32_t, surf *C.struct_wl_surface) { func gio_onKeyboardLeave(data unsafe.Pointer, keyboard *C.struct_wl_keyboard, serial C.uint32_t, surf *C.struct_wl_surface) {
conn.repeat.Stop(0) conn.repeat.Stop(0)
w := winMap[keyboard] w := winMap[keyboard]
w.w.event(key.Focus{Focus: false}) w.w.event(key.FocusEvent{Focus: false})
} }
//export gio_onKeyboardKey //export gio_onKeyboardKey
@@ -852,7 +852,7 @@ func (w *window) dispatchKey(keyCode C.uint32_t) {
} }
sym := C.xkb_state_key_get_one_sym(conn.xkbState, C.xkb_keycode_t(keyCode)) sym := C.xkb_state_key_get_one_sym(conn.xkbState, C.xkb_keycode_t(keyCode))
if n, ok := convertKeysym(sym); ok { if n, ok := convertKeysym(sym); ok {
cmd := key.Chord{Name: n} cmd := key.ChordEvent{Name: n}
if C.xkb_state_mod_name_is_active(conn.xkbState, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 { if C.xkb_state_mod_name_is_active(conn.xkbState, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
cmd.Modifiers |= key.ModCommand cmd.Modifiers |= key.ModCommand
} }
@@ -893,7 +893,7 @@ func (w *window) dispatchKey(keyCode C.uint32_t) {
} }
} }
if len(str) > 0 { if len(str) > 0 {
w.w.event(key.Edit{Text: string(str)}) w.w.event(key.EditEvent{Text: string(str)})
} }
} }
@@ -1045,7 +1045,7 @@ func (w *window) draw(sync bool) {
C.gio_wl_callback_add_listener(w.lastFrameCallback, unsafe.Pointer(w.surf)) C.gio_wl_callback_add_listener(w.lastFrameCallback, unsafe.Pointer(w.surf))
} }
cfg.Now = time.Now() cfg.Now = time.Now()
w.w.event(Draw{ w.w.event(DrawEvent{
Size: image.Point{ Size: image.Point{
X: width, X: width,
Y: height, Y: height,
@@ -1060,7 +1060,7 @@ func (w *window) setStage(s Stage) {
return return
} }
w.stage = s w.stage = s
w.w.event(ChangeStage{s}) w.w.event(StageEvent{s})
} }
func (w *window) display() unsafe.Pointer { func (w *window) display() unsafe.Pointer {
+6 -6
View File
@@ -264,13 +264,13 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
fallthrough fallthrough
case _WM_CHAR: case _WM_CHAR:
if r := rune(wParam); unicode.IsPrint(r) { if r := rune(wParam); unicode.IsPrint(r) {
w.w.event(key.Edit{Text: string(r)}) w.w.event(key.EditEvent{Text: string(r)})
} }
// The message is processed. // The message is processed.
return 1 return 1
case _WM_KEYDOWN, _WM_SYSKEYDOWN: case _WM_KEYDOWN, _WM_SYSKEYDOWN:
if n, ok := convertKeyCode(wParam); ok { if n, ok := convertKeyCode(wParam); ok {
cmd := key.Chord{Name: n} cmd := key.ChordEvent{Name: n}
if getKeyState(_VK_CONTROL)&0x1000 != 0 { if getKeyState(_VK_CONTROL)&0x1000 != 0 {
cmd.Modifiers |= key.ModCommand cmd.Modifiers |= key.ModCommand
} }
@@ -294,9 +294,9 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
Type: pointer.Cancel, Type: pointer.Cancel,
}) })
case _WM_SETFOCUS: case _WM_SETFOCUS:
w.w.event(key.Focus{Focus: true}) w.w.event(key.FocusEvent{Focus: true})
case _WM_KILLFOCUS: case _WM_KILLFOCUS:
w.w.event(key.Focus{Focus: false}) w.w.event(key.FocusEvent{Focus: false})
case _WM_LBUTTONUP: case _WM_LBUTTONUP:
releaseCapture() releaseCapture()
x, y := coordsFromlParam(lParam) x, y := coordsFromlParam(lParam)
@@ -410,7 +410,7 @@ func (w *window) postRedraw() {
func (w *window) setStage(s Stage) { func (w *window) setStage(s Stage) {
w.stage = s w.stage = s
w.w.event(ChangeStage{s}) w.w.event(StageEvent{s})
} }
func (w *window) draw(sync bool) { func (w *window) draw(sync bool) {
@@ -420,7 +420,7 @@ func (w *window) draw(sync bool) {
w.height = int(r.bottom - r.top) w.height = int(r.bottom - r.top)
cfg := configForDC(w.hdc) cfg := configForDC(w.hdc)
cfg.Now = time.Now() cfg.Now = time.Now()
w.w.event(Draw{ w.w.event(DrawEvent{
Size: image.Point{ Size: image.Point{
X: w.width, X: w.width,
Y: w.height, Y: w.height,
+3 -3
View File
@@ -240,16 +240,16 @@ func (w *Window) event(e Event) {
switch e := e.(type) { switch e := e.(type) {
case input.Event: case input.Event:
needRedraw = true needRedraw = true
case *Command: case *CommandEvent:
needAck = true needAck = true
needRedraw = true needRedraw = true
case ChangeStage: case StageEvent:
w.stage = e.Stage w.stage = e.Stage
if w.stage > StageDead { if w.stage > StageDead {
needAck = true needAck = true
w.syncGPU = true w.syncGPU = true
} }
case Draw: case DrawEvent:
if e.Size == (image.Point{}) { if e.Size == (image.Point{}) {
panic(errors.New("internal error: zero-sized Draw")) panic(errors.New("internal error: zero-sized Draw"))
} }
+3 -3
View File
@@ -54,11 +54,11 @@ func (q *keyQueue) Frame(root *ui.Ops, events handlerEvents) {
changed := focus != nil && focus != q.focus changed := focus != nil && focus != q.focus
if focus != q.focus { if focus != q.focus {
if q.focus != nil { if q.focus != nil {
events[q.focus] = append(events[q.focus], key.Focus{Focus: false}) events[q.focus] = append(events[q.focus], key.FocusEvent{Focus: false})
} }
q.focus = focus q.focus = focus
if q.focus != nil { if q.focus != nil {
events[q.focus] = append(events[q.focus], key.Focus{Focus: true}) events[q.focus] = append(events[q.focus], key.FocusEvent{Focus: true})
} }
} }
switch { switch {
@@ -111,7 +111,7 @@ loop:
h = new(keyHandler) h = new(keyHandler)
q.handlers[op.Key] = h q.handlers[op.Key] = h
// Reset the handler on (each) first appearance. // Reset the handler on (each) first appearance.
events[op.Key] = []Event{key.Focus{Focus: false}} events[op.Key] = []Event{key.FocusEvent{Focus: false}}
} }
h.active = true h.active = true
case ops.TypeHideInput: case ops.TypeHideInput:
+1 -1
View File
@@ -43,7 +43,7 @@ func (q *Queue) Add(e Event) {
switch e := e.(type) { switch e := e.(type) {
case pointer.Event: case pointer.Event:
q.pqueue.Push(e, q.handlers) q.pqueue.Push(e, q.handlers)
case key.Edit, key.Chord, key.Focus: case key.EditEvent, key.ChordEvent, key.FocusEvent:
q.kqueue.Push(e, q.handlers) q.kqueue.Push(e, q.handlers)
} }
} }
+9 -9
View File
@@ -16,16 +16,16 @@ type HideInputOp struct{}
type Key interface{} type Key interface{}
type Focus struct { type FocusEvent struct {
Focus bool Focus bool
} }
type Chord struct { type ChordEvent struct {
Name rune Name rune
Modifiers Modifiers Modifiers Modifiers
} }
type Edit struct { type EditEvent struct {
Text string Text string
} }
@@ -90,9 +90,9 @@ func (h HideInputOp) Add(o *ui.Ops) {
o.Write(data) o.Write(data)
} }
func (Edit) ImplementsEvent() {} func (EditEvent) ImplementsEvent() {}
func (Chord) ImplementsEvent() {} func (ChordEvent) ImplementsEvent() {}
func (Focus) ImplementsEvent() {} func (FocusEvent) ImplementsEvent() {}
func (Edit) ImplementsInputEvent() {} func (EditEvent) ImplementsInputEvent() {}
func (Chord) ImplementsInputEvent() {} func (ChordEvent) ImplementsInputEvent() {}
func (Focus) ImplementsInputEvent() {} func (FocusEvent) ImplementsInputEvent() {}
+4 -4
View File
@@ -111,9 +111,9 @@ func (e *Editor) Next() (EditorEvent, bool) {
} }
e.blinkStart = e.Config.Now e.blinkStart = e.Config.Now
switch ke := ke.(type) { switch ke := ke.(type) {
case key.Focus: case key.FocusEvent:
e.focused = ke.Focus e.focused = ke.Focus
case key.Chord: case key.ChordEvent:
if !e.focused { if !e.focused {
break break
} }
@@ -126,7 +126,7 @@ func (e *Editor) Next() (EditorEvent, bool) {
stop = true stop = true
scrollTo = true scrollTo = true
} }
case key.Edit: case key.EditEvent:
stop = true stop = true
scrollTo = true scrollTo = true
e.append(ke.Text) e.append(ke.Text)
@@ -529,7 +529,7 @@ func (e *Editor) scrollToCaret() {
} }
} }
func (e *Editor) command(k key.Chord) bool { func (e *Editor) command(k key.ChordEvent) bool {
switch k.Name { switch k.Name {
case key.NameReturn, key.NameEnter: case key.NameReturn, key.NameEnter:
if !e.SingleLine { if !e.SingleLine {