forked from joejulian/gio
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:
+7
-7
@@ -14,7 +14,7 @@ type Event interface {
|
||||
ImplementsEvent()
|
||||
}
|
||||
|
||||
type Draw struct {
|
||||
type DrawEvent struct {
|
||||
Config ui.Config
|
||||
Size image.Point
|
||||
// Whether this draw is system generated
|
||||
@@ -23,12 +23,12 @@ type Draw struct {
|
||||
sync bool
|
||||
}
|
||||
|
||||
type ChangeStage struct {
|
||||
type StageEvent struct {
|
||||
Stage Stage
|
||||
}
|
||||
|
||||
// Command is a system event.
|
||||
type Command struct {
|
||||
// CommandEvent is a system event.
|
||||
type CommandEvent struct {
|
||||
Type CommandType
|
||||
// Suppress the default action of the command.
|
||||
Cancel bool
|
||||
@@ -110,9 +110,9 @@ func (l Stage) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (_ Draw) ImplementsEvent() {}
|
||||
func (_ ChangeStage) ImplementsEvent() {}
|
||||
func (_ *Command) ImplementsEvent() {}
|
||||
func (_ DrawEvent) ImplementsEvent() {}
|
||||
func (_ StageEvent) ImplementsEvent() {}
|
||||
func (_ *CommandEvent) ImplementsEvent() {}
|
||||
|
||||
func init() {
|
||||
args := strings.Split(extraArgs, "|")
|
||||
|
||||
@@ -183,7 +183,7 @@ func onFrameCallback(env *C.JNIEnv, class C.jclass, view C.jlong, nanos C.jlong)
|
||||
//export onBack
|
||||
func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean {
|
||||
w := views[view]
|
||||
ev := &Command{Type: CommandBack}
|
||||
ev := &CommandEvent{Type: CommandBack}
|
||||
w.event(ev)
|
||||
if ev.Cancel {
|
||||
return C.JNI_TRUE
|
||||
@@ -194,7 +194,7 @@ func onBack(env *C.JNIEnv, class C.jclass, view C.jlong) C.jboolean {
|
||||
//export onFocusChange
|
||||
func onFocusChange(env *C.JNIEnv, class C.jclass, view C.jlong, focus C.jboolean) {
|
||||
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() {
|
||||
@@ -212,7 +212,7 @@ func (w *window) setStage(stage Stage) {
|
||||
return
|
||||
}
|
||||
w.stage = stage
|
||||
w.event(ChangeStage{stage})
|
||||
w.event(StageEvent{stage})
|
||||
}
|
||||
|
||||
func (w *window) display() unsafe.Pointer {
|
||||
@@ -270,7 +270,7 @@ func (w *window) draw(sync bool) {
|
||||
return
|
||||
}
|
||||
ppdp := float32(w.dpi) * inchPrDp
|
||||
w.event(Draw{
|
||||
w.event(DrawEvent{
|
||||
Size: image.Point{
|
||||
X: int(width),
|
||||
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) {
|
||||
w := views[handle]
|
||||
if n, ok := convertKeyCode(keyCode); ok {
|
||||
w.event(key.Chord{Name: n})
|
||||
w.event(key.ChordEvent{Name: n})
|
||||
}
|
||||
if r != 0 {
|
||||
w.event(key.Edit{Text: string(rune(r))})
|
||||
w.event(key.EditEvent{Text: string(rune(r))})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -59,7 +59,7 @@ func onCreate(view C.CFTypeRef) {
|
||||
C.gio_addLayerToView(view, w.layer)
|
||||
views[view] = w
|
||||
windows <- ow
|
||||
w.w.event(ChangeStage{StagePaused})
|
||||
w.w.event(StageEvent{StagePaused})
|
||||
}
|
||||
|
||||
//export onDraw
|
||||
@@ -72,13 +72,13 @@ func onDraw(view C.CFTypeRef, dpi, sdpi, width, height C.CGFloat, sync C.int) {
|
||||
w.visible.Store(true)
|
||||
C.gio_updateView(view, w.layer)
|
||||
if !wasVisible {
|
||||
w.w.event(ChangeStage{StageRunning})
|
||||
w.w.event(StageEvent{StageRunning})
|
||||
}
|
||||
isSync := false
|
||||
if sync != 0 {
|
||||
isSync = true
|
||||
}
|
||||
w.w.event(Draw{
|
||||
w.w.event(DrawEvent{
|
||||
Size: image.Point{
|
||||
X: int(width + .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) {
|
||||
w := views[view]
|
||||
w.visible.Store(false)
|
||||
w.w.event(ChangeStage{StagePaused})
|
||||
w.w.event(StageEvent{StagePaused})
|
||||
}
|
||||
|
||||
//export onDestroy
|
||||
func onDestroy(view C.CFTypeRef) {
|
||||
w := views[view]
|
||||
delete(views, view)
|
||||
w.w.event(ChangeStage{StageDead})
|
||||
w.w.event(StageEvent{StageDead})
|
||||
C.gio_removeLayer(w.layer)
|
||||
C.CFRelease(w.layer)
|
||||
w.layer = 0
|
||||
@@ -113,7 +113,7 @@ func onDestroy(view C.CFTypeRef) {
|
||||
//export onFocus
|
||||
func onFocus(view C.CFTypeRef, focus int) {
|
||||
w := views[view]
|
||||
w.w.event(key.Focus{Focus: focus != 0})
|
||||
w.w.event(key.FocusEvent{Focus: focus != 0})
|
||||
}
|
||||
|
||||
//export onLowMemory
|
||||
@@ -150,7 +150,7 @@ func onDeleteBackward(view C.CFTypeRef) {
|
||||
//export onText
|
||||
func onText(view C.CFTypeRef, str *C.char) {
|
||||
w := views[view]
|
||||
w.w.event(key.Edit{
|
||||
w.w.event(key.EditEvent{
|
||||
Text: C.GoString(str),
|
||||
})
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func (w *window) setAnimating(anim bool) {
|
||||
}
|
||||
|
||||
func (w *window) onKeyCommand(name rune) {
|
||||
w.w.event(key.Chord{
|
||||
w.w.event(key.ChordEvent{
|
||||
Name: name,
|
||||
})
|
||||
}
|
||||
|
||||
+6
-6
@@ -57,7 +57,7 @@ func createWindow(opts *WindowOptions) error {
|
||||
go func() {
|
||||
windows <- w.w
|
||||
w.focus()
|
||||
w.w.event(ChangeStage{StageRunning})
|
||||
w.w.event(StageEvent{StageRunning})
|
||||
w.draw(true)
|
||||
select {}
|
||||
w.cleanup()
|
||||
@@ -156,11 +156,11 @@ func (w *window) addEventListeners() {
|
||||
return nil
|
||||
})
|
||||
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
|
||||
})
|
||||
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
|
||||
})
|
||||
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() {
|
||||
val := w.tarea.Get("value").String()
|
||||
w.tarea.Set("value", "")
|
||||
w.w.event(key.Edit{Text: string(val)})
|
||||
w.w.event(key.EditEvent{Text: string(val)})
|
||||
}
|
||||
|
||||
func (w *window) blur() {
|
||||
@@ -202,7 +202,7 @@ func (w *window) focus() {
|
||||
func (w *window) keyEvent(e js.Value) {
|
||||
k := e.Get("key").String()
|
||||
if n, ok := translateKey(k); ok {
|
||||
cmd := key.Chord{Name: n}
|
||||
cmd := key.ChordEvent{Name: n}
|
||||
if e.Call("getModifierState", "Control").Bool() {
|
||||
cmd.Modifiers |= key.ModCommand
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func (w *window) draw(sync bool) {
|
||||
w.scale = float32(scale)
|
||||
w.mu.Unlock()
|
||||
cfg.Now = time.Now()
|
||||
w.w.event(Draw{
|
||||
w.w.event(DrawEvent{
|
||||
Size: image.Point{
|
||||
X: width,
|
||||
Y: height,
|
||||
|
||||
+5
-5
@@ -66,7 +66,7 @@ func (w *window) setStage(stage Stage) {
|
||||
return
|
||||
}
|
||||
w.stage = stage
|
||||
w.w.event(ChangeStage{stage})
|
||||
w.w.event(StageEvent{stage})
|
||||
}
|
||||
|
||||
//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]
|
||||
for _, k := range str {
|
||||
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) {
|
||||
str := C.GoString(cstr)
|
||||
w := views[view]
|
||||
w.w.event(key.Edit{Text: str})
|
||||
w.w.event(key.EditEvent{Text: str})
|
||||
}
|
||||
|
||||
//export gio_onMouse
|
||||
@@ -133,7 +133,7 @@ func gio_onDraw(view C.CFTypeRef) {
|
||||
//export gio_onFocus
|
||||
func gio_onFocus(view C.CFTypeRef, focus C.BOOL) {
|
||||
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) {
|
||||
@@ -144,7 +144,7 @@ func (w *window) draw(sync bool) {
|
||||
cfg := getConfig()
|
||||
cfg.Now = time.Now()
|
||||
w.setStage(StageRunning)
|
||||
w.w.event(Draw{
|
||||
w.w.event(DrawEvent{
|
||||
Size: image.Point{
|
||||
X: width,
|
||||
Y: height,
|
||||
|
||||
@@ -644,14 +644,14 @@ func gio_onKeyboardEnter(data unsafe.Pointer, keyboard *C.struct_wl_keyboard, se
|
||||
conn.repeat.Stop(0)
|
||||
w := winMap[surf]
|
||||
winMap[keyboard] = w
|
||||
w.w.event(key.Focus{Focus: true})
|
||||
w.w.event(key.FocusEvent{Focus: true})
|
||||
}
|
||||
|
||||
//export gio_onKeyboardLeave
|
||||
func gio_onKeyboardLeave(data unsafe.Pointer, keyboard *C.struct_wl_keyboard, serial C.uint32_t, surf *C.struct_wl_surface) {
|
||||
conn.repeat.Stop(0)
|
||||
w := winMap[keyboard]
|
||||
w.w.event(key.Focus{Focus: false})
|
||||
w.w.event(key.FocusEvent{Focus: false})
|
||||
}
|
||||
|
||||
//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))
|
||||
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 {
|
||||
cmd.Modifiers |= key.ModCommand
|
||||
}
|
||||
@@ -893,7 +893,7 @@ func (w *window) dispatchKey(keyCode C.uint32_t) {
|
||||
}
|
||||
}
|
||||
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))
|
||||
}
|
||||
cfg.Now = time.Now()
|
||||
w.w.event(Draw{
|
||||
w.w.event(DrawEvent{
|
||||
Size: image.Point{
|
||||
X: width,
|
||||
Y: height,
|
||||
@@ -1060,7 +1060,7 @@ func (w *window) setStage(s Stage) {
|
||||
return
|
||||
}
|
||||
w.stage = s
|
||||
w.w.event(ChangeStage{s})
|
||||
w.w.event(StageEvent{s})
|
||||
}
|
||||
|
||||
func (w *window) display() unsafe.Pointer {
|
||||
|
||||
@@ -264,13 +264,13 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
||||
fallthrough
|
||||
case _WM_CHAR:
|
||||
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.
|
||||
return 1
|
||||
case _WM_KEYDOWN, _WM_SYSKEYDOWN:
|
||||
if n, ok := convertKeyCode(wParam); ok {
|
||||
cmd := key.Chord{Name: n}
|
||||
cmd := key.ChordEvent{Name: n}
|
||||
if getKeyState(_VK_CONTROL)&0x1000 != 0 {
|
||||
cmd.Modifiers |= key.ModCommand
|
||||
}
|
||||
@@ -294,9 +294,9 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
||||
Type: pointer.Cancel,
|
||||
})
|
||||
case _WM_SETFOCUS:
|
||||
w.w.event(key.Focus{Focus: true})
|
||||
w.w.event(key.FocusEvent{Focus: true})
|
||||
case _WM_KILLFOCUS:
|
||||
w.w.event(key.Focus{Focus: false})
|
||||
w.w.event(key.FocusEvent{Focus: false})
|
||||
case _WM_LBUTTONUP:
|
||||
releaseCapture()
|
||||
x, y := coordsFromlParam(lParam)
|
||||
@@ -410,7 +410,7 @@ func (w *window) postRedraw() {
|
||||
|
||||
func (w *window) setStage(s Stage) {
|
||||
w.stage = s
|
||||
w.w.event(ChangeStage{s})
|
||||
w.w.event(StageEvent{s})
|
||||
}
|
||||
|
||||
func (w *window) draw(sync bool) {
|
||||
@@ -420,7 +420,7 @@ func (w *window) draw(sync bool) {
|
||||
w.height = int(r.bottom - r.top)
|
||||
cfg := configForDC(w.hdc)
|
||||
cfg.Now = time.Now()
|
||||
w.w.event(Draw{
|
||||
w.w.event(DrawEvent{
|
||||
Size: image.Point{
|
||||
X: w.width,
|
||||
Y: w.height,
|
||||
|
||||
+3
-3
@@ -240,16 +240,16 @@ func (w *Window) event(e Event) {
|
||||
switch e := e.(type) {
|
||||
case input.Event:
|
||||
needRedraw = true
|
||||
case *Command:
|
||||
case *CommandEvent:
|
||||
needAck = true
|
||||
needRedraw = true
|
||||
case ChangeStage:
|
||||
case StageEvent:
|
||||
w.stage = e.Stage
|
||||
if w.stage > StageDead {
|
||||
needAck = true
|
||||
w.syncGPU = true
|
||||
}
|
||||
case Draw:
|
||||
case DrawEvent:
|
||||
if e.Size == (image.Point{}) {
|
||||
panic(errors.New("internal error: zero-sized Draw"))
|
||||
}
|
||||
|
||||
+3
-3
@@ -54,11 +54,11 @@ func (q *keyQueue) Frame(root *ui.Ops, events handlerEvents) {
|
||||
changed := focus != nil && focus != q.focus
|
||||
if focus != q.focus {
|
||||
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
|
||||
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 {
|
||||
@@ -111,7 +111,7 @@ loop:
|
||||
h = new(keyHandler)
|
||||
q.handlers[op.Key] = h
|
||||
// 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
|
||||
case ops.TypeHideInput:
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ func (q *Queue) Add(e Event) {
|
||||
switch e := e.(type) {
|
||||
case pointer.Event:
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -16,16 +16,16 @@ type HideInputOp struct{}
|
||||
|
||||
type Key interface{}
|
||||
|
||||
type Focus struct {
|
||||
type FocusEvent struct {
|
||||
Focus bool
|
||||
}
|
||||
|
||||
type Chord struct {
|
||||
type ChordEvent struct {
|
||||
Name rune
|
||||
Modifiers Modifiers
|
||||
}
|
||||
|
||||
type Edit struct {
|
||||
type EditEvent struct {
|
||||
Text string
|
||||
}
|
||||
|
||||
@@ -90,9 +90,9 @@ func (h HideInputOp) Add(o *ui.Ops) {
|
||||
o.Write(data)
|
||||
}
|
||||
|
||||
func (Edit) ImplementsEvent() {}
|
||||
func (Chord) ImplementsEvent() {}
|
||||
func (Focus) ImplementsEvent() {}
|
||||
func (Edit) ImplementsInputEvent() {}
|
||||
func (Chord) ImplementsInputEvent() {}
|
||||
func (Focus) ImplementsInputEvent() {}
|
||||
func (EditEvent) ImplementsEvent() {}
|
||||
func (ChordEvent) ImplementsEvent() {}
|
||||
func (FocusEvent) ImplementsEvent() {}
|
||||
func (EditEvent) ImplementsInputEvent() {}
|
||||
func (ChordEvent) ImplementsInputEvent() {}
|
||||
func (FocusEvent) ImplementsInputEvent() {}
|
||||
|
||||
+4
-4
@@ -111,9 +111,9 @@ func (e *Editor) Next() (EditorEvent, bool) {
|
||||
}
|
||||
e.blinkStart = e.Config.Now
|
||||
switch ke := ke.(type) {
|
||||
case key.Focus:
|
||||
case key.FocusEvent:
|
||||
e.focused = ke.Focus
|
||||
case key.Chord:
|
||||
case key.ChordEvent:
|
||||
if !e.focused {
|
||||
break
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func (e *Editor) Next() (EditorEvent, bool) {
|
||||
stop = true
|
||||
scrollTo = true
|
||||
}
|
||||
case key.Edit:
|
||||
case key.EditEvent:
|
||||
stop = true
|
||||
scrollTo = true
|
||||
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 {
|
||||
case key.NameReturn, key.NameEnter:
|
||||
if !e.SingleLine {
|
||||
|
||||
Reference in New Issue
Block a user