entry: handle onKeyEvent

- no x86 linux binary update. no build environment
This commit is contained in:
Rustam Gamidov 2020-03-03 11:57:10 +02:00
parent 867a9e5a49
commit da63c0f9de
8 changed files with 37 additions and 5 deletions

View File

@ -19,6 +19,7 @@ type Entry struct {
ControlBase ControlBase
e *C.uiEntry e *C.uiEntry
onChanged func(*Entry) onChanged func(*Entry)
onKeyEvent func(*Entry, *AreaKeyEvent) (handled bool)
} }
func finishNewEntry(ee *C.uiEntry) *Entry { func finishNewEntry(ee *C.uiEntry) *Entry {
@ -27,6 +28,7 @@ func finishNewEntry(ee *C.uiEntry) *Entry {
e.e = ee e.e = ee
C.pkguiEntryOnChanged(e.e) C.pkguiEntryOnChanged(e.e)
C.pkguiEntryOnKeyEvent(e.e)
e.ControlBase = NewControlBase(e, uintptr(unsafe.Pointer(e.e))) e.ControlBase = NewControlBase(e, uintptr(unsafe.Pointer(e.e)))
return e return e
@ -79,6 +81,28 @@ func pkguiDoEntryOnChanged(ee *C.uiEntry, data unsafe.Pointer) {
} }
} }
// OnKeyEvent registers f to be run when the user makes a change to
// the Entry. Only one function can be registered at a time.
func (e *Entry) OnKeyEvent(f func(*Entry, *AreaKeyEvent) (handled bool) ) {
e.onKeyEvent = f
}
//export pkguiDoEntryOnKeyEvent
func pkguiDoEntryOnKeyEvent(ee *C.uiEntry, uke *C.uiAreaKeyEvent) C.int {
ke := &AreaKeyEvent{
Key: rune(uke.Key),
ExtKey: ExtKey(uke.ExtKey),
Modifier: Modifiers(uke.Modifier),
Modifiers: Modifiers(uke.Modifiers),
Up: tobool(uke.Up),
}
e := ControlFromLibui(uintptr(unsafe.Pointer(ee))).(*Entry)
if e.onKeyEvent != nil {
return frombool(e.onKeyEvent(e, ke))
}
return frombool(false)
}
// ReadOnly returns whether the Entry can be changed. // ReadOnly returns whether the Entry can be changed.
func (e *Entry) ReadOnly() bool { func (e *Entry) ReadOnly() bool {
return tobool(C.uiEntryReadOnly(e.e)) return tobool(C.uiEntryReadOnly(e.e))

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -88,6 +88,11 @@ void pkguiEntryOnChanged(uiEntry *e)
uiEntryOnChanged(e, pkguiDoEntryOnChanged, NULL); uiEntryOnChanged(e, pkguiDoEntryOnChanged, NULL);
} }
void pkguiEntryOnKeyEvent(uiEntry *e)
{
uiEntryOnKeyEvent(e, pkguiDoEntryOnKeyEvent);
}
void pkguiFontButtonOnChanged(uiFontButton *b) void pkguiFontButtonOnChanged(uiFontButton *b)
{ {
uiFontButtonOnChanged(b, pkguiDoFontButtonOnChanged, NULL); uiFontButtonOnChanged(b, pkguiDoFontButtonOnChanged, NULL);

View File

@ -47,6 +47,7 @@ extern void pkguiEditableComboboxOnChanged(uiEditableCombobox *c);
// entry.go // entry.go
extern void pkguiEntryOnChanged(uiEntry *e); extern void pkguiEntryOnChanged(uiEntry *e);
extern void pkguiEntryOnKeyEvent(uiEntry *e);
// fontbutton.go // fontbutton.go
extern void pkguiFontButtonOnChanged(uiFontButton *b); extern void pkguiFontButtonOnChanged(uiFontButton *b);

12
ui.h
View File

@ -45,6 +45,12 @@ _UI_ENUM(uiForEach) {
uiForEachStop, uiForEachStop,
}; };
typedef struct uiArea uiArea;
typedef struct uiAreaHandler uiAreaHandler;
typedef struct uiAreaDrawParams uiAreaDrawParams;
typedef struct uiAreaMouseEvent uiAreaMouseEvent;
typedef struct uiAreaKeyEvent uiAreaKeyEvent;
typedef struct uiInitOptions uiInitOptions; typedef struct uiInitOptions uiInitOptions;
struct uiInitOptions { struct uiInitOptions {
@ -162,6 +168,7 @@ typedef struct uiEntry uiEntry;
_UI_EXTERN char *uiEntryText(uiEntry *e); _UI_EXTERN char *uiEntryText(uiEntry *e);
_UI_EXTERN void uiEntrySetText(uiEntry *e, const char *text); _UI_EXTERN void uiEntrySetText(uiEntry *e, const char *text);
_UI_EXTERN void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *e, void *data), void *data); _UI_EXTERN void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *e, void *data), void *data);
_UI_EXTERN void uiEntryOnKeyEvent(uiEntry *e, int (*f)(uiEntry *e, uiAreaKeyEvent *event));
_UI_EXTERN int uiEntryReadOnly(uiEntry *e); _UI_EXTERN int uiEntryReadOnly(uiEntry *e);
_UI_EXTERN void uiEntrySetReadOnly(uiEntry *e, int readonly); _UI_EXTERN void uiEntrySetReadOnly(uiEntry *e, int readonly);
_UI_EXTERN uiEntry *uiNewEntry(void); _UI_EXTERN uiEntry *uiNewEntry(void);
@ -297,11 +304,6 @@ _UI_EXTERN char *uiSaveFile(uiWindow *parent);
_UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description); _UI_EXTERN void uiMsgBox(uiWindow *parent, const char *title, const char *description);
_UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description); _UI_EXTERN void uiMsgBoxError(uiWindow *parent, const char *title, const char *description);
typedef struct uiArea uiArea;
typedef struct uiAreaHandler uiAreaHandler;
typedef struct uiAreaDrawParams uiAreaDrawParams;
typedef struct uiAreaMouseEvent uiAreaMouseEvent;
typedef struct uiAreaKeyEvent uiAreaKeyEvent;
typedef struct uiDrawContext uiDrawContext; typedef struct uiDrawContext uiDrawContext;