summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Wildemann <metalstrolch@users.noreply.github.com>2019-01-30 15:25:04 +0100
committerGitHub <noreply@github.com>2019-01-30 15:25:04 +0100
commit94fccd71c7228ec2de548ae35d5d3cd12c6a100a (patch)
tree66c043dbde401b9a66a82141474732255a039413
parent13b6ea56b8218c52f01596fb1dca8a4b557020f2 (diff)
parentcaab2508adce05897c405477486158883cd65b85 (diff)
downloadnavit-94fccd71c7228ec2de548ae35d5d3cd12c6a100a.tar.gz
Merge pull request #682 from lains/fixing_resize
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...
-rw-r--r--navit/gui/internal/gui_internal.c47
-rw-r--r--navit/gui/internal/gui_internal_keyboard.c14
-rw-r--r--navit/gui/internal/gui_internal_menu.c257
-rw-r--r--navit/gui/internal/gui_internal_menu.h5
-rw-r--r--navit/gui/internal/gui_internal_widget.c123
-rw-r--r--navit/gui/internal/gui_internal_widget.h11
6 files changed, 376 insertions, 81 deletions
diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c
index 39e0b6d18..afae9a9f1 100644
--- a/navit/gui/internal/gui_internal.c
+++ b/navit/gui/internal/gui_internal.c
@@ -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.
@@ -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);
}
diff --git a/navit/gui/internal/gui_internal_keyboard.c b/navit/gui/internal/gui_internal_keyboard.c
index 4b2c64cd8..8e758de4f 100644
--- a/navit/gui/internal/gui_internal_keyboard.c
+++ b/navit/gui/internal/gui_internal_keyboard.c
@@ -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
*
@@ -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;
@@ -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;
diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c
index 9da7f2e4c..6a0d6a52b 100644
--- a/navit/gui/internal/gui_internal_menu.c
+++ b/navit/gui/internal/gui_internal_menu.c
@@ -17,7 +17,34 @@
extern char *version;
-static void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) {
+/**
+ * @brief Utility function to check if a menu widget is adapted to the display size or needs resizing (if so, the widget dimensions will be set to match those of the display
+ *
+ * @param this The GUI instance
+ * @param w The menu widget (top widget that should spawn over the entire display)
+ * @param wdisp The width of the display to check the widget against
+ * @param hdisp The width of the display to check the widget against
+ *
+ * @return true if widget w has the same size as the provided display dimensions
+ */
+
+int gui_internal_menu_needs_resizing(struct gui_priv *this, struct widget *w, int wdisp, int hdisp) {
+ if (w->w != wdisp || w->h != hdisp) {
+ w->w=wdisp;
+ w->h=hdisp;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * @brief destroy a menu widget and perform the associated cleanup in the menu & submenu list
+ *
+ * @param this The GUI instance
+ * @param w The menu widget to destroy
+ */
+void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) {
struct menu_data *menu_data=w->menu_data;
if (menu_data) {
if (menu_data->refresh_callback_obj.type) {
@@ -36,42 +63,99 @@ static void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w) {
this->root.children=g_list_remove(this->root.children, w);
}
+/**
+ * @brief Retrieve then html anchor (href) from a menu widger
+ *
+ * @param w A widget corresponding to a menu (this widget should be an html menu)
+ *
+ * @return the string for the href, or NULL if this menu has no href (or the widget is not a menu)
+ */
+static char *gui_internal_widget_get_href(struct widget *w) {
+ if (w && w->menu_data)
+ return w->menu_data->href;
+ else
+ return NULL;
+}
+
+/**
+ * @brief Reload a menu from its anchor (href)
+ *
+ * @param this The internal GUI context
+ * @param w A widget corresponding to the menu to redraw (this widget should be an html menu, thus it should have a href)
+ *
+ * @return 1 in case of success, 0 if no menu could be reloaded
+ * @note If the widget provided in @p w has no href, we will return 0
+ */
+int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w) {
+ char *ohref = gui_internal_widget_get_href(w);
+ if (ohref) {
+ char *href=g_strdup(ohref);
+ gui_internal_menu_destroy(this, w);
+ gui_internal_html_load_href(this, href, 0);
+ g_free(href);
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * @brief Destroy (discard) all menu screens that have been placed after widget @p w
+ *
+ * @param this The internal GUI instance
+ * @param w A widget corresponding to the last menu to keep (all subsequent menus in the list will be destroyed). NULL if all menus should be destroyed.
+ * @param render whether we should render the menu indicated by widget w (render!=0) or not (render==0)
+ */
static void gui_internal_prune_menu_do(struct gui_priv *this, struct widget *w, int render) {
GList *l;
struct widget *wr,*wd;
gui_internal_search_idle_end(this);
+ /* Destroy all menus, backwards, starting from the end until we reach widget w, and redraw widget w */
while ((l = g_list_last(this->root.children))) {
wd=l->data;
- if (wd == w) {
+ if (wd == w) { /* This is the widget we want to bring back to display (all subsequent widgets will be destroyed in the loop) */
void (*redisplay)(struct gui_priv *priv, struct widget *widget, void *data);
if (!render)
return;
gui_internal_say(this, w, 0);
redisplay=w->menu_data->redisplay;
- wr=w->menu_data->redisplay_widget;
- if (!w->menu_data->redisplay && !w->menu_data->href) {
- gui_internal_widget_render(this, w);
- return;
- }
if (redisplay) {
gui_internal_menu_destroy(this, w);
+ wr=w->menu_data->redisplay_widget;
redisplay(this, wr, wr->data);
} else {
- char *href=g_strdup(w->menu_data->href);
- gui_internal_menu_destroy(this, w);
- gui_internal_html_load_href(this, href, 0);
- g_free(href);
+ /* Make sure the new menu we are going to display spawns the whole display (in case there was a resize while a submenu was being displayed) */
+ w->w=this->root.w;
+ w->h=this->root.h;
+ /* If the foremost widget is a HTML menu, reload & redraw it from its href using gui_internal_widget_reload_href() */
+ if (!gui_internal_widget_reload_href(this,w)) {
+ /* If not, resize the foremost widget */
+ gui_internal_menu_resize(this, this->root.w, this->root.h);
+ }
+ gui_internal_menu_render(this);
}
return;
- }
- gui_internal_menu_destroy(this, wd);
+ } else
+ gui_internal_menu_destroy(this, wd);
}
}
+/**
+ * @brief Destroy (discard) all menu screens that have been placed after widget @p w and redraw the display, showing widget @w
+ *
+ * @param this The internal GUI instance
+ * @param w A widget corresponding to the last menu to keep, and to draw (all subsequent menus in the list will be destroyed). NULL if all menus should be destroyed.
+ */
void gui_internal_prune_menu(struct gui_priv *this, struct widget *w) {
gui_internal_prune_menu_do(this, w, 1);
}
+/**
+ * @brief Destroy (discard) the last @p count menu screens
+ *
+ * @param this The internal GUI instance
+ * @param count The number of menus to destroy at the tail of the menu/submenu stack (if <=0, no menu will be destroyed)
+ * @param render whether we should render the new last menu in the stack (render!=0) or not (render==0)
+ */
void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render) {
GList *l=g_list_last(this->root.children);
struct widget *w=NULL;
@@ -83,9 +167,47 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
}
}
+/**
+ * @brief Resize the box widget (and its children) corresponding to a menu
+ *
+ * Menus are stored in a main box (topbox) that spawn the entire screen, thus, once the topbox has been resized, it will in turn resize its children,
+ * effectively resizing the whole menu display size
+ *
+ * Note: once this function has been run, widget @p w and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller
+ *
+ * @param this The internal GUI instance
+ * @param w A box widget corresponding to the menu widget
+ * @param data Some data to pass to the box resize handler
+ * @param neww The new width of the display
+ * @param newh The new height of the display
+ */
+void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) {
+ struct padding *padding = NULL;
+
+ if (w->type != widget_box) {
+ dbg(lvl_warning, "Called on a non-box widget, ignoring");
+ return;
+ }
+ if (this->gra) {
+ padding = graphics_get_data(this->gra, "padding");
+ } else
+ dbg(lvl_warning, "cannot get padding: this->gra is NULL");
+ if (padding) {
+ w->p.x = padding->left;
+ w->p.y = padding->top;
+ w->w = neww - padding->left - padding->right;
+ w->h = newh - padding->top - padding->bottom;
+ } else {
+ w->p.x = 0;
+ w->p.y = 0;
+ w->w = neww;
+ w->h = newh;
+ }
+ gui_internal_box_resize(this, w, data, w->w, w->h);
+}
/**
- * @brief Initializes a GUI screen
+ * @brief Initializes a GUI menu screen
*
* This method initializes the internal GUI's screen on which all other elements (such as HTML menus,
* dialogs or others) are displayed.
@@ -101,31 +223,15 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
struct widget *
gui_internal_menu(struct gui_priv *this, const char *label) {
struct widget *menu,*w,*w1,*topbox;
- struct padding *padding = NULL;
-
- if (this->gra) {
- padding = graphics_get_data(this->gra, "padding");
- } else
- dbg(lvl_warning, "cannot get padding: this->gra is NULL");
gui_internal_search_idle_end(this);
topbox=gui_internal_box_new_with_label(this, 0, label);
- topbox->w=this->root.w;
- topbox->h=this->root.h;
gui_internal_widget_append(&this->root, topbox);
menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
-
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
+ menu->on_resize=gui_internal_menu_menu_resize;
+ topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h);
+ /* We also have to invoke onresize() handler on menu because it is not (yet) set as a child of topbox */
+ menu->on_resize(this, menu, NULL, topbox->w, topbox->h);
menu->background=this->background;
gui_internal_apply_config(this);
topbox->menu_data=g_new0(struct menu_data, 1);
@@ -156,17 +262,8 @@ gui_internal_menu(struct gui_priv *this, const char *label) {
}
if (this->flags & 192) {
menu=gui_internal_box_new(this, gravity_left_center|orientation_vertical);
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
+ menu->on_resize=gui_internal_menu_menu_resize;
+ menu->on_resize(this, menu, NULL, topbox->w, topbox->h);
w1=gui_internal_time_help(this);
gui_internal_widget_append(menu, w1);
w1=gui_internal_box_new(this, gravity_center|orientation_horizontal_vertical|flags_expand|flags_fill);
@@ -176,19 +273,8 @@ gui_internal_menu(struct gui_priv *this, const char *label) {
}
gui_internal_widget_pack(this, topbox);
gui_internal_widget_reset_pack(this, topbox);
- topbox->w=this->root.w;
- topbox->h=this->root.h;
- if (padding) {
- menu->p.x = padding->left;
- menu->p.y = padding->top;
- menu->w = topbox->w - padding->left - padding->right;
- menu->h = topbox->h - padding->top - padding->bottom;
- } else {
- menu->p.x = 0;
- menu->p.y = 0;
- menu->w = topbox->w;
- menu->h = topbox->h;
- }
+ if (topbox->on_resize)
+ topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h);
return w;
}
@@ -211,6 +297,14 @@ void gui_internal_menu_reset_pack(struct gui_priv *this) {
gui_internal_widget_reset_pack(this, top_box);
}
+/**
+ * @brief Renders a menu GUI on the display
+ *
+ * @note The whole sequence of menus is kept in this->root.children (when going back one page, we just move to the previous child in the list)
+ * Thus, only the last child of this->root.children is actually displayed
+ *
+ * @param this The internal GUI instance
+ */
void gui_internal_menu_render(struct gui_priv *this) {
GList *l;
struct widget *menu;
@@ -222,6 +316,52 @@ void gui_internal_menu_render(struct gui_priv *this) {
gui_internal_widget_render(this, menu);
}
+/**
+ * @brief Resize the currently displayed menu
+ *
+ * @param this The internal GUI instance
+ * @param w The new width of the display
+ * @param h the new height of the display
+ */
+void gui_internal_menu_resize(struct gui_priv *this, int w, int h) {
+ GList *l;
+ struct widget *menu_topwidget;
+
+ gui_internal_apply_config(this);
+ l=g_list_last(this->root.children);
+ menu_topwidget=l->data;
+ if (menu_topwidget->on_resize) {
+ dbg(lvl_debug, "Invoking resize handler for menu_topwidget at %p", menu_topwidget);
+ menu_topwidget->on_resize(this, menu_topwidget, NULL, this->root.w, this->root.h);
+ }
+}
+
+/**
+ * @brief Resize a top bar created using gui_internal_top_bar()
+ *
+ * @param this The internal GUI instance
+ * @param data Some data to pass to the box resize handler
+ * @param neww The new width of the display
+ * @param newh The new height of the display
+ */
+static void gui_internal_top_bar_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) {
+ struct widget *new_top_bar;
+
+ if (w->type != widget_box) {
+ dbg(lvl_warning, "Called on a non-box widget, ignoring");
+ return;
+ }
+ new_top_bar=gui_internal_top_bar(this);
+ gui_internal_widget_move(this, w, new_top_bar);
+}
+
+/**
+ * @brief Create an GUI top bar (containing the history of GUI menus and submenus)
+ *
+ * @param this The internal GUI instance
+ *
+ * @return The newly created top bar widget
+ */
struct widget *
gui_internal_top_bar(struct gui_priv *this) {
struct widget *w,*wm,*wh,*wc,*wcn;
@@ -256,6 +396,7 @@ gui_internal_top_bar(struct gui_priv *this) {
w->bt=6;
w->bb=6;
}
+ w->on_resize=gui_internal_top_bar_resize;
width=this->root.w-w->bl;
if (! (this->flags & 2)) {
wm=gui_internal_button_new_with_callback(this, NULL,
diff --git a/navit/gui/internal/gui_internal_menu.h b/navit/gui/internal/gui_internal_menu.h
index 57e37d91c..3906ed23c 100644
--- a/navit/gui/internal/gui_internal_menu.h
+++ b/navit/gui/internal/gui_internal_menu.h
@@ -2,11 +2,16 @@
struct gui_priv;
struct menu_data;
struct widget;
+int gui_internal_menu_needs_resizing(struct gui_priv *this, struct widget *w, int wdisp, int hdisp);
+void gui_internal_menu_destroy(struct gui_priv *this, struct widget *w);
+int gui_internal_widget_reload_href(struct gui_priv *this, struct widget *w);
void gui_internal_prune_menu(struct gui_priv *this, struct widget *w);
void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render);
+void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh);
struct widget *gui_internal_menu(struct gui_priv *this, const char *label);
struct menu_data *gui_internal_menu_data(struct gui_priv *this);
void gui_internal_menu_reset_pack(struct gui_priv *this);
void gui_internal_menu_render(struct gui_priv *this);
+void gui_internal_menu_resize(struct gui_priv *this, int w, int h);
struct widget *gui_internal_top_bar(struct gui_priv *this);
/* end of prototypes */
diff --git a/navit/gui/internal/gui_internal_widget.c b/navit/gui/internal/gui_internal_widget.c
index aa4c9eeef..0894be5aa 100644
--- a/navit/gui/internal/gui_internal_widget.c
+++ b/navit/gui/internal/gui_internal_widget.c
@@ -12,6 +12,63 @@
#include "gui_internal_menu.h"
static void gui_internal_scroll_buttons_init(struct gui_priv *this, struct widget *widget, struct scroll_buttons *sb);
+void gui_internal_box_pack(struct gui_priv *this, struct widget *w);
+
+/**
+ * @brief Transfer the content of one widget into another one (and optionally vice-versa)
+ *
+ * @param this The internal GUI instance
+ * @param[in,out] first The first widget
+ * @param[in,out] second The second widget
+ * @param move_only If non nul, transfer only the second widget into the first widget. The second widget is then deallocated and should be be used anymore (this is a move operation)
+ */
+static void gui_internal_widget_transfer_content(struct gui_priv *this, struct widget *first, struct widget *second,
+ int move_only) {
+ struct widget *temp;
+
+ if (!first) {
+ dbg(lvl_error, "Refusing copy: first argument is NULL");
+ return;
+ }
+ if (!second) {
+ dbg(lvl_error, "Refusing copy: second argument is NULL");
+ return;
+ }
+ temp=g_new0(struct widget, 1);
+ memcpy(temp, first, sizeof(struct widget));
+ memcpy(first, second, sizeof(struct widget));
+ if (move_only) {
+ gui_internal_widget_destroy(this, temp);
+ /* gui_internal_widget_destroy() will do a g_free(temp), but will also deallocate all children widgets */
+ /* Now, we also free the struct widget pointed to by second, so variable second should not be used anymore from this point */
+ g_free(second);
+ } else {
+ memcpy(second, temp, sizeof(struct widget));
+ g_free(temp);
+ }
+}
+
+/**
+ * @brief Swap two widgets
+ *
+ * @param this The internal GUI instance
+ * @param[in,out] first The first widget
+ * @param[in,out] second The second widget
+ */
+void gui_internal_widget_swap(struct gui_priv *this, struct widget *first, struct widget *second) {
+ gui_internal_widget_transfer_content(this, first, second, 0);
+}
+
+/**
+ * @brief Move the content of one widget into another one (the @p src widget is then deallocated and should be be used anymore)
+ *
+ * @param this The internal GUI instance
+ * @param[in,out] dst The destination widget
+ * @param[in,out] src The source widget
+ */
+void gui_internal_widget_move(struct gui_priv *this, struct widget *dst, struct widget *src) {
+ gui_internal_widget_transfer_content(this, dst, src, 1);
+}
static void gui_internal_background_render(struct gui_priv *this, struct widget *w) {
struct point pnt=w->p;
@@ -88,6 +145,12 @@ gui_internal_image_new(struct gui_priv *this, struct graphics_image *image) {
return widget;
}
+/**
+ * @brief Renders an image or icon, preparing it for drawing on the display
+ *
+ * @param this The internal GUI instance
+ * @param w The widget to render
+ */
static void gui_internal_image_render(struct gui_priv *this, struct widget *w) {
struct point pnt;
@@ -101,7 +164,7 @@ static void gui_internal_image_render(struct gui_priv *this, struct widget *w) {
}
/**
- * @brief Renders a label.
+ * @brief Renders a label, preparing it for drawing on the display
*
* @param this The internal GUI instance
* @param w The widget to render
@@ -286,6 +349,7 @@ gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const c
widget->text=g_strdup(label);
widget->type=widget_box;
widget->flags=flags;
+ widget->on_resize=gui_internal_box_resize;
return widget;
}
@@ -325,14 +389,13 @@ static void gui_internal_box_render(struct gui_priv *this, struct widget *w) {
gui_internal_widget_render(this, w->scroll_buttons->button_box);
}
-
/**
- * @brief Computes the size and location for the widget.
+ * @brief Computes the size and location for a box widget
*
* @param this The internal GUI instance
- * @param w The widget to render
+ * @param w The widget to pack
*/
-static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) {
+void gui_internal_box_pack(struct gui_priv *this, struct widget *w) {
struct widget *wc;
int x0,x=0,y=0,width=0,height=0,owidth=0,oheight=0,expand=0,expandd=1,count=0,rows=0,cols=w->cols ? w->cols : 0;
int hb=w->scroll_buttons?w->scroll_buttons->button_box->h:0;
@@ -599,6 +662,46 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) {
}
}
+/**
+ * @brief Resize a box widget.
+ *
+ * @param this The internal GUI instance
+ * @param w The widget to resize
+ * @param wnew The new width of the widget
+ * @param hnew THe new height of the widget
+ */
+void gui_internal_box_resize(struct gui_priv *this, struct widget *w, void *data, int wnew, int hnew) {
+ GList *l;
+ struct widget *wb;
+
+ w->w = wnew;
+ w->h = hnew;
+
+ l=w->children;
+ while (l) {
+ wb=l->data;
+ if (wb->on_resize) {
+ int orientation=w->flags & 0xffff0000;
+ switch(orientation) {
+ case orientation_horizontal:
+ case orientation_vertical:
+ case orientation_horizontal_vertical:
+ wb->h = 0;
+ wb->w = 0;
+ gui_internal_widget_pack(this, wb);
+ break;
+ default:
+ wb->w = w->w;
+ wb->h = w->h;
+ }
+ wb->on_resize(this, wb, NULL, wb->w, wb->h);
+ }
+ l=g_list_next(l);
+ }
+
+ /* Note: this widget and its children have been resized, a call to gui_internal_box_render() needs to be done by the caller */
+}
+
void gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w) {
struct widget *wc;
GList *l;
@@ -717,6 +820,14 @@ void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w) {
}
+/**
+ * @brief Renders widgets, preparing it for drawing on the display
+ *
+ * The appropriate render function will be called, depending on the type of widget
+ *
+ * @param this The internal GUI instance
+ * @param w The widget to render
+ */
void gui_internal_widget_render(struct gui_priv *this, struct widget *w) {
if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE)
return;
@@ -1344,8 +1455,6 @@ void gui_internal_table_button_next(struct gui_priv * this, struct widget * wm,
gui_internal_menu_render(this);
}
-
-
/**
* @brief Handles the 'previous page' table event.
*
diff --git a/navit/gui/internal/gui_internal_widget.h b/navit/gui/internal/gui_internal_widget.h
index c1cc030f8..cc24cb44e 100644
--- a/navit/gui/internal/gui_internal_widget.h
+++ b/navit/gui/internal/gui_internal_widget.h
@@ -18,10 +18,15 @@ struct widget {
struct graphics_image *img;
/**
* A function to be invoked on actions.
- * @li widget The widget that is receiving the button press.
+ * @param widget The widget that is receiving the button press.
*
*/
void (*func)(struct gui_priv *priv, struct widget *widget, void *data);
+ /**
+ * A function to be invoked on resize or move
+ * @param widget The widget that is resized
+ */
+ void (*on_resize)(struct gui_priv *priv, struct widget *widget, void *data, int neww, int newh);
enum gui_internal_reason reason;
int datai;
void *data;
@@ -151,6 +156,8 @@ struct gui_priv;
struct point;
struct table_data;
struct widget;
+void gui_internal_widget_swap(struct gui_priv *this, struct widget *first, struct widget *second);
+void gui_internal_widget_move(struct gui_priv *this, struct widget *dst, struct widget *src);
struct widget *gui_internal_label_font_new(struct gui_priv *this, const char *text, int font);
struct widget *gui_internal_label_new(struct gui_priv *this, const char *text);
struct widget *gui_internal_label_new_abbrev(struct gui_priv *this, const char *text, int maxwidth);
@@ -170,6 +177,7 @@ void gui_internal_highlight_do(struct gui_priv *this, struct widget *found);
void gui_internal_highlight(struct gui_priv *this);
struct widget *gui_internal_box_new_with_label(struct gui_priv *this, enum flags flags, const char *label);
struct widget *gui_internal_box_new(struct gui_priv *this, enum flags flags);
+void gui_internal_box_resize(struct gui_priv *this, struct widget *w, void *data, int wnew, int hnew);
void gui_internal_widget_reset_pack(struct gui_priv *this, struct widget *w);
void gui_internal_widget_append(struct widget *parent, struct widget *child);
void gui_internal_widget_prepend(struct widget *parent, struct widget *child);
@@ -177,6 +185,7 @@ void gui_internal_widget_insert_sorted(struct widget *parent, struct widget *chi
void gui_internal_widget_children_destroy(struct gui_priv *this, struct widget *w);
void gui_internal_widget_destroy(struct gui_priv *this, struct widget *w);
void gui_internal_widget_render(struct gui_priv *this, struct widget *w);
+void gui_internal_widget_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew);
void gui_internal_widget_pack(struct gui_priv *this, struct widget *w);
struct widget *gui_internal_button_label(struct gui_priv *this, const char *label, int mode);
struct widget *gui_internal_widget_table_new(struct gui_priv *this, enum flags flags, int buttons);