summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLionel AINS <lains@caramail.com>2018-10-05 17:49:20 +0200
committerLionel AINS <lains@caramail.com>2018-10-05 17:49:20 +0200
commit60804d6d0d6bff1af63efc8918c61edb0e30c820 (patch)
tree72ba7a6ed14319f8e89cd0866bfb2aab4bcccb02
parenta63a78aad9ded94cb2df88c0bae9cead09150c5e (diff)
downloadnavit-60804d6d0d6bff1af63efc8918c61edb0e30c820.tar.gz
Handling resize for boxes
-rw-r--r--navit/gui/internal/gui_internal.c15
-rw-r--r--navit/gui/internal/gui_internal_menu.c105
-rw-r--r--navit/gui/internal/gui_internal_menu.h1
-rw-r--r--navit/gui/internal/gui_internal_widget.c67
-rw-r--r--navit/gui/internal/gui_internal_widget.h8
5 files changed, 154 insertions, 42 deletions
diff --git a/navit/gui/internal/gui_internal.c b/navit/gui/internal/gui_internal.c
index e8ccaab1c..574d1fd90 100644
--- a/navit/gui/internal/gui_internal.c
+++ b/navit/gui/internal/gui_internal.c
@@ -474,7 +474,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.
@@ -2701,7 +2701,18 @@ static void gui_internal_resize(void *data, int w, int h) {
navit_handle_resize(this->nav, w, h);
if (this->root.children) {
if (changed) {
- gui_internal_html_main_menu(this);
+ char *href=g_strdup(this->href);
+ dbg(lvl_error,"href=%s",href);
+ /*if (*href != '\0') {
+ gui_internal_prune_menu(this, NULL);
+ gui_internal_html_load_href(this, href, 0);
+ }
+ else*/ {
+ dbg(lvl_error, "Called resize with w=%d, h=%d", w, h)
+ gui_internal_menu_resize(this, w, h); //Lionel!!!
+ gui_internal_menu_render(this);
+ }
+ g_free(href);
} else {
gui_internal_menu_render(this);
}
diff --git a/navit/gui/internal/gui_internal_menu.c b/navit/gui/internal/gui_internal_menu.c
index 9da7f2e4c..857e1e0b2 100644
--- a/navit/gui/internal/gui_internal_menu.c
+++ b/navit/gui/internal/gui_internal_menu.c
@@ -83,6 +83,30 @@ void gui_internal_prune_menu_count(struct gui_priv *this, int count, int render)
}
}
+void gui_internal_menu_topbox_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) {
+ w->w=neww;
+ w->h=newh;
+}
+
+void gui_internal_menu_menu_resize(struct gui_priv *this, struct widget *w, void *data, int neww, int newh) {
+ 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");
+ 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;
+ }
+}
/**
* @brief Initializes a GUI screen
@@ -110,22 +134,12 @@ gui_internal_menu(struct gui_priv *this, const char *label) {
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;
+ topbox->on_resize=gui_internal_menu_topbox_resize;
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);
+ 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 +170,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 +181,10 @@ 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);
+ if (menu->on_resize)
+ menu->on_resize(this, menu, NULL, topbox->w, topbox->h);
return w;
}
@@ -211,6 +207,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 context
+ */
void gui_internal_menu_render(struct gui_priv *this) {
GList *l;
struct widget *menu;
@@ -222,6 +226,31 @@ void gui_internal_menu_render(struct gui_priv *this) {
gui_internal_widget_render(this, menu);
}
+void gui_internal_menu_resize(struct gui_priv *this, int w, int h) {
+ GList *l;
+ struct widget *menu;
+ struct widget *topbox;
+ struct widget *wb;
+
+ gui_internal_apply_config(this);
+ l=g_list_last(this->root.children);
+ menu=l->data;
+ /* Search for the topbox widget */
+ l=g_list_first(menu->children);
+ topbox=l->data;
+ if (menu->on_resize)
+ menu->on_resize(this, menu, NULL, topbox->w, topbox->h);
+ if (topbox->on_resize)
+ topbox->on_resize(this, topbox, NULL, this->root.w, this->root.h);
+ l=topbox->children;
+ while (l) {
+ wb=l->data;
+ if (wb->on_resize)
+ wb->on_resize(this, wb, NULL, topbox->w, topbox->h);
+ l=g_list_next(l);
+ }
+}
+
struct widget *
gui_internal_top_bar(struct gui_priv *this) {
struct widget *w,*wm,*wh,*wc,*wcn;
diff --git a/navit/gui/internal/gui_internal_menu.h b/navit/gui/internal/gui_internal_menu.h
index 57e37d91c..6f020d1f1 100644
--- a/navit/gui/internal/gui_internal_menu.h
+++ b/navit/gui/internal/gui_internal_menu.h
@@ -8,5 +8,6 @@ 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..3e9d9e123 100644
--- a/navit/gui/internal/gui_internal_widget.c
+++ b/navit/gui/internal/gui_internal_widget.c
@@ -12,6 +12,7 @@
#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_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew);
static void gui_internal_background_render(struct gui_priv *this, struct widget *w) {
struct point pnt=w->p;
@@ -134,6 +135,15 @@ static void gui_internal_label_render(struct gui_priv *this, struct widget *w) {
}
/**
+ * @brief Resize a label.
+ *
+ * @param this The internal GUI instance
+ * @param w The widget to render
+ */
+static void gui_internal_label_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) {
+}
+
+/**
* @brief Creates a text box.
*
* A text box is a widget that renders a text string containing newlines.
@@ -325,7 +335,6 @@ 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.
*
@@ -599,6 +608,21 @@ static void gui_internal_box_pack(struct gui_priv *this, struct widget *w) {
}
}
+static void gui_internal_box_resize(struct gui_priv *this, struct widget *w, int wnew, int hnew) {
+ GList *l;
+
+ gui_internal_widget_reset_pack(this, w);
+ w->w = wnew;
+ w->h = hnew;
+ if (w->on_resize)
+ w->on_resize(this, w, NULL, wnew, hnew);
+
+ gui_internal_box_pack(this, w);
+ if (w->on_resize)
+ w->on_resize(this, w, NULL, wnew, hnew);
+ /* 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;
@@ -739,6 +763,31 @@ 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) {
+ if(w->p.x > this->root.w || w->p.y > this->root.h || w->state & STATE_INVISIBLE)
+ return;
+
+ switch (w->type) {
+ case widget_box:
+ dbg(lvl_error, "Resizing box at %p to w=%d, h=%d", w, wnew, hnew);
+ gui_internal_box_resize(this, w, wnew, hnew);
+ break;
+ case widget_label:
+ dbg(lvl_error, "Resizing label at %p to w=%d, h=%d (text=\"%s\")", w, wnew, hnew, w->text);
+ gui_internal_label_resize(this, w, wnew, hnew);
+ break;
+ case widget_image:
+ dbg(lvl_error, "resize not yet implemented for widget_image");
+ break;
+ case widget_table:
+ dbg(lvl_error, "Not resizing table at %p to w=%d, h=%d", w, wnew, hnew);
+ //gui_internal_table_resize(this, w, wnew, hnew);
+ break;
+ default:
+ break;
+ }
+}
+
void gui_internal_widget_pack(struct gui_priv *this, struct widget *w) {
switch (w->type) {
case widget_box:
@@ -1309,6 +1358,22 @@ void gui_internal_table_render(struct gui_priv * this, struct widget * w) {
}
/**
+ * @brief Resize a table widget.
+ *
+ * @param this The graphics context
+ * @param w The table widget to render.
+ */
+void gui_internal_table_resize(struct gui_priv * this, struct widget * w, int wnew, int hnew) {
+
+
+ w->w = wnew;
+ w->h = hnew;
+
+ gui_internal_widget_reset_pack(this, w);
+ gui_internal_table_pack(this, w);
+}
+
+/**
* @brief Handles the 'next page' table event.
*
* A callback function that is invoked when the 'next page' button is pressed
diff --git a/navit/gui/internal/gui_internal_widget.h b/navit/gui/internal/gui_internal_widget.h
index 33f03e478..9017b3741 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 widged 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;
@@ -174,6 +179,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);