Skip to content

Commit

Permalink
Merge pull request #682 from lains/fixing_resize
Browse files Browse the repository at this point in the history
Fix:gui/internal:Handling resize/rotation

This fixes long standing problem that internal GUI gets reset when resizing the screen. Since rotating a handheld device triggers screen resize this was really annoying.
Now you can rotate your device while entering into town search...
  • Loading branch information
metalstrolch authored Jan 30, 2019
2 parents 13b6ea5 + caab250 commit 94fccd7
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 81 deletions.
47 changes: 32 additions & 15 deletions navit/gui/internal/gui_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ gui_internal_time_help(struct gui_priv *this) {
/**
* Applies the configuration values to this based on the settings
* specified in the configuration file (this->config) and
* the most approriate default profile based on screen resolution.
* the most appropriate default profile based on screen resolution.
*
* This function should be run after this->root is setup and could
* be rerun after the window is resized.
Expand Down Expand Up @@ -2679,33 +2679,50 @@ static void gui_internal_setup(struct gui_priv *this) {
g_free(gui_file);
}

//##############################################################################################################
//# Description:
//# Comment:
//# Authors: Martin Schaller (04/2008)
//##############################################################################################################
static void gui_internal_resize(void *data, int w, int h) {
/**
* @brief Callback function invoked when display area is resized
*
* @param data A generic argument structure pointer, here we use it to store the the internal GUI context (this)
* @param wnew The new width of the display area
* @param hnew The new height of the display area
*
* @author Martin Schaller
* @date 2008/04
*/
static void gui_internal_resize(void *data, int wnew, int hnew) {
GList *l;
struct widget *w;

struct gui_priv *this=data;
int changed=0;

gui_internal_setup(this);

if (this->root.w != w || this->root.h != h) {
this->root.w=w;
this->root.h=h;
changed=1;
}
changed=gui_internal_menu_needs_resizing(this, &(this->root), wnew, hnew);

/*
* If we're drawing behind system bars on Android, watching for actual size changes will not catch
* fullscreen toggle events. As a workaround, always assume a size change if padding is supplied.
*/
if (!changed && this->gra && graphics_get_data(this->gra, "padding"))
changed = 1;
dbg(lvl_debug,"w=%d h=%d children=%p", w, h, this->root.children);
navit_handle_resize(this->nav, w, h);
navit_handle_resize(this->nav, wnew, hnew);
if (this->root.children) {
if (changed) {
gui_internal_html_main_menu(this);
l = g_list_last(this->root.children);
if (l) {
w=l->data;
if (!gui_internal_widget_reload_href(this,
w)) { /* If the foremost widget is a HTML menu, reload & redraw it from its href */
/* If not, resize the foremost widget */
dbg(lvl_debug, "Current GUI displayed is not a menu");
dbg(lvl_debug, "Will call resize with w=%d, h=%d", wnew, hnew)
gui_internal_menu_resize(this, wnew, hnew);
gui_internal_menu_render(this);
} else {
dbg(lvl_debug,"Current GUI displayed is a menu");
}
}
} else {
gui_internal_menu_render(this);
}
Expand Down
14 changes: 14 additions & 0 deletions navit/gui/internal/gui_internal_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ struct gui_internal_keyb_mode {
-> datai = (mode & VKBD_MASK_7) | ((x) & VKBD_LAYOUT_MASK)
#define SWCASE() MODE(gui_internal_keyb_modes[mode/8].case_mode)
#define UMLAUT() MODE(gui_internal_keyb_modes[mode/8].umlaut_mode)


static void gui_internal_keyboard_topbox_resize(struct gui_priv *this, struct widget *w, void *data,
int neww, int newh) {
struct menu_data *md=gui_internal_menu_data(this);
struct widget *old_wkbdb = md->keyboard;

dbg(lvl_debug, "resize called for keyboard widget %p with w=%d, h=%d", w, neww, newh);
gui_internal_keyboard_do(this, old_wkbdb, md->keyboard_mode);
}

/**
* @brief Creates a new keyboard widget or switches the layout of an existing widget
*
Expand Down Expand Up @@ -167,6 +178,8 @@ gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
else
render=1;
gui_internal_widget_children_destroy(this, wkbdb);
gui_internal_widget_reset_pack(this, wkbdb);
gui_internal_widget_pack(this, wkbdb);
} else
wkbdb=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_fill);
md->keyboard=wkbdb;
Expand All @@ -176,6 +189,7 @@ gui_internal_keyboard_do(struct gui_priv *this, struct widget *wkbdb, int mode)
wkbd->cols=8;
wkbd->spx=0;
wkbd->spy=0;
wkbd->on_resize=gui_internal_keyboard_topbox_resize;
max_w=max_w/8;
max_h=max_h/8; // Allows 3 results in the list when searching for Towns
wkbd->p.y=max_h*2;
Expand Down
Loading

0 comments on commit 94fccd7

Please sign in to comment.