Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
9d4027e3
Commit
9d4027e3
authored
Aug 25, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
menu: Scrollable, if too long to be displayed on one screen.
parent
5cdbe574
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
menu.c
sw/freertos/src/apps/menu.c
+23
-6
menu_struct.c
sw/freertos/src/apps/menu_struct.c
+12
-0
No files found.
sw/freertos/src/apps/menu.c
View file @
9d4027e3
...
...
@@ -30,23 +30,30 @@
#include "widgets/status_bar.h"
static
int
selected_item
=
0
;
static
int
offset
=
0
;
static
int
menu_size
=
0
;
#define LINE_HEIGHT 17
#define LEFT_MARGIN 17
#define MENU_SCREEN_HEIGHT 107
#define MAX_ENTRIES (MENU_SCREEN_HEIGHT / LINE_HEIGHT)
// store menu states to navigate between menus
static
menu_list
*
menu_stack
[
8
]
=
{
&
main_menu
,
NULL
,
};
static
menu_list
**
current_menu
=
&
menu_stack
[
0
];
static
void
menu_screen_redraw
(
struct
ui_widget
*
w
)
{
const
int
LINE_HEIGHT
=
17
;
const
int
LEFT_MARGIN
=
17
;
int
i
;
int
menu_limit
=
(
menu_size
<
MAX_ENTRIES
?
menu_size
:
MAX_ENTRIES
);
gfx_clear
(
&
w
->
dc
,
0
);
for
(
i
=
0
;
i
<
menu_
size
;
++
i
)
for
(
i
=
0
;
i
<
menu_
limit
;
++
i
)
{
int
pos
=
offset
+
i
;
// draw a white background for the selected entry
if
(
i
==
selected_item
)
{
if
(
pos
==
selected_item
)
{
gfx_box
(
&
w
->
dc
,
LEFT_MARGIN
,
i
*
LINE_HEIGHT
,
127
,
(
i
+
1
)
*
LINE_HEIGHT
,
1
);
}
...
...
@@ -54,7 +61,7 @@ static void menu_screen_redraw(struct ui_widget *w)
// TODO draw icon
// display label (either app or submenu)
menu_entry
*
ent
=
&
(
*
current_menu
)
->
entries
[
i
];
menu_entry
*
ent
=
&
(
*
current_menu
)
->
entries
[
pos
];
if
(
ent
->
type
==
APP
)
{
application
*
a
=
ent
->
data
.
app
;
...
...
@@ -76,11 +83,19 @@ static void menu_screen_event(struct ui_widget *w, const struct event *evt)
if
(
evt
->
data
.
button
==
BUT_BR
)
{
if
(
selected_item
<
menu_size
-
1
)
{
++
selected_item
;
if
(
selected_item
>=
MAX_ENTRIES
)
offset
=
selected_item
-
MAX_ENTRIES
+
1
;
w
->
flags
|=
WF_DIRTY
;
}
}
else
if
(
evt
->
data
.
button
==
BUT_BL
)
{
if
(
selected_item
>
0
)
{
--
selected_item
;
if
(
selected_item
<
offset
)
offset
=
selected_item
;
w
->
flags
|=
WF_DIRTY
;
}
}
...
...
@@ -90,7 +105,7 @@ static void menu_screen_event(struct ui_widget *w, const struct event *evt)
struct
ui_widget
menu_screen
=
{
menu_screen_redraw
,
menu_screen_event
,
{
0
,
20
,
127
,
107
},
{
0
,
20
,
127
,
20
+
MENU_SCREEN_HEIGHT
},
0
,
WF_ACTIVE
|
WF_VISIBLE
};
...
...
@@ -112,6 +127,7 @@ static void run(menu_entry *entry) {
entry
->
data
.
app
->
main
(
NULL
);
}
else
if
(
entry
->
type
==
SUBMENU
)
{
selected_item
=
0
;
offset
=
0
;
menu_size
=
0
;
// keep the operation separate to avoid crashes
// when an interrupt goes off between the two following lines
...
...
@@ -129,6 +145,7 @@ static void go_back() {
}
else
{
menu_size
=
0
;
selected_item
=
0
;
offset
=
0
;
--
current_menu
;
menu_size
=
get_menu_size
(
*
current_menu
);
}
...
...
sw/freertos/src/apps/menu_struct.c
View file @
9d4027e3
...
...
@@ -55,6 +55,18 @@ menu_list main_menu = {
{
SUBMENU
,
{
.
submenu
=
&
sub_menu
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
SUBMENU
,
{
.
submenu
=
&
sub_menu
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
SUBMENU
,
{
.
submenu
=
&
sub_menu
}
},
{
SUBMENU
,
{
.
submenu
=
&
sub_menu
}
},
{
SUBMENU
,
{
.
submenu
=
&
sub_menu
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
APP
,
{
.
app
=
&
clock
}
},
{
END
,
{
NULL
}
}
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment