Commit b8878a5c authored by Projects's avatar Projects

menu: Menu is generated basing on data structures.

parent fe2dbbaa
......@@ -163,6 +163,7 @@ src/apps/widgets/status_bar.c \
src/apps/application.c \
src/apps/clock.c \
src/apps/menu.c \
src/apps/menu_struct.c \
src/main.c \
src/irq_dispatcher.c \
src/low_power_tick_management.c
......
......@@ -25,6 +25,7 @@
*/
#include "menu.h"
#include "menu_struct.h"
#include "clock.h"
#include "widgets/status_bar.h"
......@@ -37,15 +38,25 @@ static void menu_screen_redraw(struct ui_widget *w)
int i;
gfx_clear(&w->dc, 0);
for(i = 0; i < 5; ++i)
for(i = 0; i < get_length(&main_menu); ++i)
{
if(i == selected_item) {
gfx_box(&w->dc, LEFT_MARGIN, i * LINE_HEIGHT,
127, (i + 1) * LINE_HEIGHT, 1);
}
gfx_text(&w->dc, &font_helv17, LEFT_MARGIN,
i * LINE_HEIGHT, "Application", i != selected_item);
menu_entry *ent = &main_menu.entries[i];
if(ent->type == APP) {
application *a = ent->data.app;
gfx_text(&w->dc, &font_helv17, LEFT_MARGIN,
i * LINE_HEIGHT, a->name, i != selected_item);
} else if(ent->type == SUBMENU) {
menu_list *l = ent->data.submenu;
gfx_text(&w->dc, &font_helv17, LEFT_MARGIN,
i * LINE_HEIGHT, l->name, i != selected_item);
}
}
}
......
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* Menu structure.
*/
#include "menu_struct.h"
#include "clock.h"
int get_length(const menu_list *menu) {
int len = 0;
const menu_entry* ptr = menu->entries;
// Look for sentinel
while((*ptr++).type != END) ++len;
return len;
}
menu_list main_menu = {
"Main menu",
{
{ APP, { &clock } },
{ APP, { &clock } },
{ APP, { &clock } },
{ APP, { &clock } },
{ END, { NULL } }
}
};
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Menu data structures.
*/
#ifndef MENU_STRUCT_H
#define MENU_STRUCT_H
#include "application.h"
/**
* @brief Type of menu entry.
*/
enum entry_type {
APP,
SUBMENU,
END // sentinel, should be put as the last entry
};
/**
* @brief Structure that represents a single
* entry - either application or submenu.
*/
typedef struct menu_entry_t {
enum entry_type type;
union {
application *app;
struct menu_list_t *submenu;
} data;
} menu_entry;
/**
* @brief Structure that contains a list
* of menu entries (submenu).
*/
typedef struct menu_list_t {
char name[16];
menu_entry entries[];
} menu_list;
/**
* @brief Returns the number of entries for a given submenu.
* @param menu is the menu that length is returned.
*/
int get_length(const menu_list *menu);
/**
* @brief Stores the main menu structure.
*/
extern menu_list main_menu;
#endif /* MENU_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment