PR fixes. Removed all keyboard callback code as it can be accomplished with nk_edit flags
This commit is contained in:
parent
e6798bc1b4
commit
7dbd9f910e
@ -12,12 +12,21 @@ You must link with image, font, ttf, and primitives Allegro addons. See the `Mak
|
|||||||
Like every nuklear backend, handling many different resolutions and resolution densities can be tricky. 14px font on a desktop may be perfect, but extremely small on a retina iPad. I recommend writing a middleware that will detect what kind of screen is being used, and modify the sizes of widgets accordingly.
|
Like every nuklear backend, handling many different resolutions and resolution densities can be tricky. 14px font on a desktop may be perfect, but extremely small on a retina iPad. I recommend writing a middleware that will detect what kind of screen is being used, and modify the sizes of widgets accordingly.
|
||||||
|
|
||||||
## Soft Keyboard for Touch Screen Devices
|
## Soft Keyboard for Touch Screen Devices
|
||||||
For keyboard support on devices without hardware keyboards (iOS, Android, etc.) you should define `NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD` and pass open and close keyboard functions to `nk_allegro5_init()`. See the `main.c` demo for more information.
|
|
||||||
|
|
||||||
Information on how to implement soft keyboard callbacks for Android can be on the Allegro community wiki: https://wiki.allegro.cc/index.php?title=Running_Allegro_applications_on_Android#Displaying_the_Android_keyboard
|
Information on how to implement soft keyboard callbacks for Android can be on the Allegro community wiki: https://wiki.allegro.cc/index.php?title=Running_Allegro_applications_on_Android#Displaying_the_Android_keyboard
|
||||||
|
|
||||||
To display a soft keyboard on iOS, you must create a `UIView` subclass that implements the `UIKeyInput` interface. See `KeyboardHandleriOS.h` and `KeyboardHandleriOS.m` Objective-C source code files for an example on how to do this. As the Allegro keyboard driver does not currently listen for iOS events, we use a custom event emitter to emit keyboard events, which is passed in after initialization with `(void)setCustomKeyboardEventSource:(ALLEGRO_EVENT_SOURCE *)ev_src`. This causes normal keyboard events to be emitted and properly caught by the nuklear backend. The provided `main.c` demo file does not implement this, but with the provided source code files it is not difficult to do. See this Allegro community forum thread for more information: https://www.allegro.cc/forums/thread/616672
|
To display a soft keyboard on iOS, you must create a `UIView` subclass that implements the `UIKeyInput` interface. See `KeyboardHandleriOS.h` and `KeyboardHandleriOS.m` Objective-C source code files for an example on how to do this. As the Allegro keyboard driver does not currently listen for iOS events, we use a custom event emitter to emit keyboard events, which is passed in after initialization with `(void)setCustomKeyboardEventSource:(ALLEGRO_EVENT_SOURCE *)ev_src`. This causes normal keyboard events to be emitted and properly caught by the nuklear backend. The provided `main.c` demo file does not implement this, but with the provided source code files it is not difficult to do. See this Allegro community forum thread for more information: https://www.allegro.cc/forums/thread/616672
|
||||||
|
|
||||||
|
To know when nuklear wants to open and close the keyboard, you can check edit widget flags:
|
||||||
|
|
||||||
|
```
|
||||||
|
nk_flags ed_flags = nk_edit_string(ctx, NK_EDIT_FIELD, field_buffer, &field_len, 64, nk_filter_default);
|
||||||
|
if (ed_flags & NK_EDIT_ACTIVATED)
|
||||||
|
open_ios_soft_keyboard();
|
||||||
|
if (ed_flags & NK_EDIT_DEACTIVATED)
|
||||||
|
close_ios_soft_keyboard();
|
||||||
|
```
|
||||||
|
|
||||||
### Manual Soft Keyboard Dismissal
|
### Manual Soft Keyboard Dismissal
|
||||||
As the user can dismiss a keyboard manually, nuklear will not be aware when this occurs, and the text edit cursor will think the entry field is still active. I recommend catching the dismiss event, then emitting `ALLEGRO_EVENT_TOUCH_BEGIN` and `ALLEGRO_EVENT_TOUCH_END` events in an unused portion of the screen (like the bottom-right corner). This will simulate the user touching outside of the text entry widget, which will make the edit field inactive.
|
As the user can dismiss a keyboard manually, nuklear will not be aware when this occurs, and the text edit cursor will think the entry field is still active. I recommend catching the dismiss event, then emitting `ALLEGRO_EVENT_TOUCH_BEGIN` and `ALLEGRO_EVENT_TOUCH_END` events in an unused portion of the screen (like the bottom-right corner). This will simulate the user touching outside of the text entry widget, which will make the edit field inactive.
|
||||||
|
|
||||||
|
@ -19,9 +19,6 @@
|
|||||||
#define NK_INCLUDE_STANDARD_IO
|
#define NK_INCLUDE_STANDARD_IO
|
||||||
#define NK_INCLUDE_STANDARD_VARARGS
|
#define NK_INCLUDE_STANDARD_VARARGS
|
||||||
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
||||||
/* Uncomment this for iOS / Android keyboard support
|
|
||||||
#define NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD
|
|
||||||
*/
|
|
||||||
#define NK_IMPLEMENTATION
|
#define NK_IMPLEMENTATION
|
||||||
#define NK_ALLEGRO5_IMPLEMENTATION
|
#define NK_ALLEGRO5_IMPLEMENTATION
|
||||||
#include "../../nuklear.h"
|
#include "../../nuklear.h"
|
||||||
@ -54,20 +51,6 @@
|
|||||||
static void error_callback(int e, const char *d)
|
static void error_callback(int e, const char *d)
|
||||||
{printf("Error %d: %s\n", e, d);}
|
{printf("Error %d: %s\n", e, d);}
|
||||||
|
|
||||||
/* If NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD is enabled, implement these
|
|
||||||
two methods and pass them as the last 2 arguments to nk_allegro5_init()
|
|
||||||
to have nuklear call them when appropriate.
|
|
||||||
|
|
||||||
void open_soft_keyboard()
|
|
||||||
{
|
|
||||||
[implement opening keyboard code]
|
|
||||||
}
|
|
||||||
void close_soft_keyboard()
|
|
||||||
{
|
|
||||||
[implement close keyboard code]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* Platform */
|
/* Platform */
|
||||||
@ -107,10 +90,7 @@ int main(void)
|
|||||||
font = nk_allegro5_font_create_from_file("../../../extra_font/Roboto-Regular.ttf", 12, 0);
|
font = nk_allegro5_font_create_from_file("../../../extra_font/Roboto-Regular.ttf", 12, 0);
|
||||||
struct nk_context *ctx;
|
struct nk_context *ctx;
|
||||||
|
|
||||||
/* If NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD is enabled, pass open_soft_keyboard and
|
ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
close_soft_keyboard as the last 2 arguments to nk_allegro5_init() instead
|
|
||||||
of NULL, NULL */
|
|
||||||
ctx = nk_allegro5_init(font, display, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL);
|
|
||||||
|
|
||||||
/* style.c */
|
/* style.c */
|
||||||
/*set_style(ctx, THEME_WHITE);*/
|
/*set_style(ctx, THEME_WHITE);*/
|
||||||
|
@ -22,9 +22,7 @@
|
|||||||
|
|
||||||
typedef struct NkAllegro5Font NkAllegro5Font;
|
typedef struct NkAllegro5Font NkAllegro5Font;
|
||||||
NK_API struct nk_context* nk_allegro5_init(NkAllegro5Font *font, ALLEGRO_DISPLAY *dsp,
|
NK_API struct nk_context* nk_allegro5_init(NkAllegro5Font *font, ALLEGRO_DISPLAY *dsp,
|
||||||
unsigned int width, unsigned int height,
|
unsigned int width, unsigned int height);
|
||||||
void (*open_keyboard_func)(void),
|
|
||||||
void (*close_keyboard_func)(void));
|
|
||||||
NK_API void nk_allegro5_handle_event(ALLEGRO_EVENT *ev);
|
NK_API void nk_allegro5_handle_event(ALLEGRO_EVENT *ev);
|
||||||
NK_API void nk_allegro5_shutdown(void);
|
NK_API void nk_allegro5_shutdown(void);
|
||||||
NK_API void nk_allegro5_render(void);
|
NK_API void nk_allegro5_render(void);
|
||||||
@ -431,8 +429,7 @@ nk_allegro5_clipboard_copy(nk_handle usr, const char *text, int len)
|
|||||||
|
|
||||||
NK_API struct nk_context*
|
NK_API struct nk_context*
|
||||||
nk_allegro5_init(NkAllegro5Font *allegro5font, ALLEGRO_DISPLAY *dsp,
|
nk_allegro5_init(NkAllegro5Font *allegro5font, ALLEGRO_DISPLAY *dsp,
|
||||||
unsigned int width, unsigned int height,
|
unsigned int width, unsigned int height)
|
||||||
void (*open_keyboard_func)(void), void (*close_keyboard_func)(void))
|
|
||||||
{
|
{
|
||||||
if (!al_init_primitives_addon()) {
|
if (!al_init_primitives_addon()) {
|
||||||
fprintf(stdout, "Unable to initialize required allegro5 primitives addon\n");
|
fprintf(stdout, "Unable to initialize required allegro5 primitives addon\n");
|
||||||
@ -454,10 +451,6 @@ nk_allegro5_init(NkAllegro5Font *allegro5font, ALLEGRO_DISPLAY *dsp,
|
|||||||
allegro5.ctx.clip.copy = nk_allegro5_clipboard_copy;
|
allegro5.ctx.clip.copy = nk_allegro5_clipboard_copy;
|
||||||
allegro5.ctx.clip.paste = nk_allegro5_clipboard_paste;
|
allegro5.ctx.clip.paste = nk_allegro5_clipboard_paste;
|
||||||
allegro5.ctx.clip.userdata = nk_handle_ptr(0);
|
allegro5.ctx.clip.userdata = nk_handle_ptr(0);
|
||||||
#ifdef NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD
|
|
||||||
allegro5.ctx.open_keyboard = open_keyboard_func;
|
|
||||||
allegro5.ctx.close_keyboard = close_keyboard_func;
|
|
||||||
#endif
|
|
||||||
return &allegro5.ctx;
|
return &allegro5.ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user