mirror of
https://github.com/vivier/EMILE.git
synced 2025-03-31 12:32:36 +00:00
Add scroll list
This commit is contained in:
parent
70be974956
commit
8d02f4dac4
@ -10,7 +10,7 @@ CPPFLAGS = -I$(TOP) -DARCH_M68K
|
||||
|
||||
LIBRARY = libui.a
|
||||
|
||||
SOURCES = window.c progressbar.c
|
||||
SOURCES = window.c progressbar.c scrolllist.c
|
||||
|
||||
HEADERS =
|
||||
|
||||
|
@ -15,12 +15,21 @@ typedef struct emile_progressbar {
|
||||
int current;
|
||||
} emile_progressbar_t;
|
||||
|
||||
typedef struct emile_list {
|
||||
char** item;
|
||||
int nb;
|
||||
int current;
|
||||
} emile_list_t;
|
||||
|
||||
|
||||
extern void console_set_cursor_position(int l, int c);
|
||||
extern void console_video_inverse(void);
|
||||
extern void console_video_normal(void);
|
||||
extern void console_select_charset(char c);
|
||||
extern void console_cursor_off();
|
||||
|
||||
extern void emile_window(emile_window_t *win);
|
||||
extern emile_progressbar_t* emile_progressbar_create(emile_window_t *win, int max);
|
||||
extern void emile_progressbar_value(emile_progressbar_t* bar, int value);
|
||||
extern void emile_progressbar_delete(emile_progressbar_t* bar);
|
||||
extern int emile_scrolllist(emile_window_t *win, emile_list_t *list);
|
||||
|
77
libui/scrolllist.c
Normal file
77
libui/scrolllist.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
*
|
||||
* (c) 2007 Laurent Vivier <Laurent@lvivier.info>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "libui.h"
|
||||
|
||||
static int display_list(emile_window_t *win, emile_list_t *list, int base)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < win->h; i++)
|
||||
{
|
||||
console_set_cursor_position(win->l + i, win->c);
|
||||
if (i + base < list->nb)
|
||||
{
|
||||
char* current = list->item[i + base];
|
||||
int len = strlen(current);
|
||||
if ( (i + base) == list->current)
|
||||
console_video_inverse();
|
||||
for (j = 0; j < win->w; j++)
|
||||
{
|
||||
if (j < len)
|
||||
putchar(current[j]);
|
||||
else
|
||||
putchar(' ');
|
||||
}
|
||||
console_video_normal();
|
||||
}
|
||||
else
|
||||
for (j = 0; j < win->w; j++)
|
||||
putchar(' ');
|
||||
}
|
||||
|
||||
return list->current;
|
||||
}
|
||||
|
||||
int emile_scrolllist(emile_window_t *win, emile_list_t *list)
|
||||
{
|
||||
char c;
|
||||
int base = 0;
|
||||
|
||||
console_cursor_off();
|
||||
emile_window(win);
|
||||
display_list(win, list, base);
|
||||
|
||||
while((c = getchar()) != -1)
|
||||
{
|
||||
if (c == '\033')
|
||||
{
|
||||
c = getchar();
|
||||
if (c != '[')
|
||||
continue;
|
||||
c = getchar();
|
||||
if ( (c == 'B') && (list->current < list->nb - 1) )
|
||||
{
|
||||
list->current++;
|
||||
if (list->current > win->h - 1)
|
||||
base = list->current - win->h + 1;
|
||||
}
|
||||
else if ( (c == 'A') && (list->current > 0) )
|
||||
{
|
||||
list->current--;
|
||||
if (list->current < base)
|
||||
base--;
|
||||
}
|
||||
|
||||
display_list(win, list, base);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return c;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user