For now in 1.1.0 you can use this pattern:
#include "stdlib.h"
#include "keyboard.h"
#include "platform.h"
#include "core.h"
#include "gui.h"
#include "gui_draw.h"
void gui_applet_draw_callback(int enforce_redraw);
void gui_applet_kbd_process();
void gui_applet_menu_kbd_process();
gui_handler GUI_MODE_APPLET =
{ gui_applet_draw_callback, gui_applet_kbd_process, gui_applet_menu_kbd_process, 0, GUI_MODE_MAGICNUM };
//-------------------------------------------------------------------
void gui_applet_init() {
gui_set_mode( (unsigned int)&GUI_MODE_APPLET );
applet_redraw = 2;
}
//-------------------------------------------------------------------
void gui_applet_draw_callback(int enforce_redraw) {
if ( applet_redraw )
{
if ( applet_redraw==2 )
some_initial_draws();
partial_draws()
applet_redraw=0;
}
}
//-------------------------------------------------------------------
static void gui_applet_run() {
somework();
applet_redraw=1;
somework();
applet_redraw=1;
}
//-------------------------------------------------------------------
void gui_applet_kbd_process() {
switch (kbd_get_autoclicked_key()) {
case KEY_SET:
gui_applet_run();
break;
}
}
void gui_applet_menu_kbd_process() {
if ()
your_action()
else
gui_default_kbd_process_menu_btn();
}
This sample is for case If applet is build-in into the core. For modules some additional code is required. I'll write manual how to make deal with modules later.
Simple description:
- gui_applet_init() set gui mode to this applet. and set flag to this applet that full redraw required.
- each 20msec gui_applet_draw_callback is called until this gui mode is active. it check what kind of redraw required and do it.
- if non-menu button pressed, gui_applet_kbd_process() is called. For our case we catch SET pressing and start long processing which could display something in progress by raised redraw flag
- to finish applet we need just switch gui_mode. Fselector for example store previous gui_mode and restore it right after/before callback call and so exit.
Here gui_applet_menu_kbd_process(), which is called when MENU pressed, we call in some condition gui_default_kbd_process_menu_btn() which just turn gui to menu.