blob: 0098cf198f7f8499295d09c32dd64835cac6559c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2005 by Kevin Ferrare
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "option_select.h"
#include "sprintf.h"
#include "kernel.h"
#include "lang.h"
void option_select_init_items(struct option_select * opt,
const char * title,
int selected,
const struct opt_items * items,
int nb_items)
{
opt->title=title;
opt->min_value=0;
opt->max_value=nb_items;
opt->option=selected;
opt->items=items;
}
void option_select_next(struct option_select * opt)
{
if(opt->option + 1 >= opt->max_value)
{
if(opt->option==opt->max_value-1)
opt->option=opt->min_value;
else
opt->option=opt->max_value-1;
}
else
opt->option+=1;
}
void option_select_prev(struct option_select * opt)
{
if(opt->option - 1 < opt->min_value)
{
/* the dissimilarity to option_select_next() arises from the
* sleep timer problem (bug #5000 and #5001):
* there we have min=0, step = 5 but the value itself might
* not be a multiple of 5 -- as time elapsed;
* We need to be able to set timer to 0 (= Off) nevertheless. */
if(opt->option!=opt->min_value)
opt->option=opt->min_value;
else
opt->option=opt->max_value-1;
}
else
opt->option-=1;
}
const char * option_select_get_text(struct option_select * opt)
{
return(P2STR(opt->items[opt->option].string));
}
|