Define constants for window geometry
Also fixes uiDraw so that the split lines and marker don't overlap the main window, although that wasn't causing any real problems.master
parent
53f206f7e0
commit
b352f5965b
55
ui.c
55
ui.c
|
@ -46,9 +46,18 @@
|
||||||
#define A_ITALIC A_NORMAL
|
#define A_ITALIC A_NORMAL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum {
|
||||||
|
StatusLines = 1,
|
||||||
|
WindowLines = 1024,
|
||||||
|
MarkerLines = 1,
|
||||||
|
SplitLines = 5,
|
||||||
|
InputLines = 1,
|
||||||
|
InputCols = 1024,
|
||||||
|
};
|
||||||
|
|
||||||
#define BOTTOM (LINES - 1)
|
#define BOTTOM (LINES - 1)
|
||||||
#define RIGHT (COLS - 1)
|
#define RIGHT (COLS - 1)
|
||||||
#define PAGE_LINES (LINES - 2)
|
#define MAIN_LINES (LINES - StatusLines - InputLines)
|
||||||
|
|
||||||
static WINDOW *status;
|
static WINDOW *status;
|
||||||
static WINDOW *marker;
|
static WINDOW *marker;
|
||||||
|
@ -82,7 +91,6 @@ static struct Line bufferLine(const struct Buffer *buffer, size_t i) {
|
||||||
return buffer->lines[(buffer->len + i) % BufferCap];
|
return buffer->lines[(buffer->len + i) % BufferCap];
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { WindowLines = BufferCap };
|
|
||||||
struct Window {
|
struct Window {
|
||||||
uint id;
|
uint id;
|
||||||
WINDOW *pad;
|
WINDOW *pad;
|
||||||
|
@ -264,8 +272,6 @@ static void errExit(void) {
|
||||||
reset_shell_mode();
|
reset_shell_mode();
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { SplitLines = 5 };
|
|
||||||
|
|
||||||
void uiInit(void) {
|
void uiInit(void) {
|
||||||
initscr();
|
initscr();
|
||||||
cbreak();
|
cbreak();
|
||||||
|
@ -284,13 +290,16 @@ void uiInit(void) {
|
||||||
ENUM_KEY
|
ENUM_KEY
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
status = newwin(1, COLS, 0, 0);
|
status = newwin(StatusLines, COLS, 0, 0);
|
||||||
if (!status) err(EX_OSERR, "newwin");
|
if (!status) err(EX_OSERR, "newwin");
|
||||||
|
|
||||||
marker = newwin(1, COLS, BOTTOM - SplitLines - 1, 0);
|
marker = newwin(
|
||||||
|
MarkerLines, COLS,
|
||||||
|
LINES - InputLines - SplitLines - MarkerLines, 0
|
||||||
|
);
|
||||||
wbkgd(marker, ACS_BULLET);
|
wbkgd(marker, ACS_BULLET);
|
||||||
|
|
||||||
input = newpad(1, 1024);
|
input = newpad(InputLines, InputCols);
|
||||||
if (!input) err(EX_OSERR, "newpad");
|
if (!input) err(EX_OSERR, "newpad");
|
||||||
keypad(input, true);
|
keypad(input, true);
|
||||||
nodelay(input, true);
|
nodelay(input, true);
|
||||||
|
@ -309,20 +318,27 @@ void uiDraw(void) {
|
||||||
if (hidden) return;
|
if (hidden) return;
|
||||||
wnoutrefresh(status);
|
wnoutrefresh(status);
|
||||||
const struct Window *window = windows.ptrs[windows.show];
|
const struct Window *window = windows.ptrs[windows.show];
|
||||||
|
if (!window->scroll) {
|
||||||
pnoutrefresh(
|
pnoutrefresh(
|
||||||
window->pad,
|
window->pad,
|
||||||
WindowLines - window->scroll - PAGE_LINES + !!window->scroll, 0,
|
WindowLines - MAIN_LINES, 0,
|
||||||
1, 0,
|
StatusLines, 0,
|
||||||
BOTTOM - 1 - !!window->scroll, RIGHT
|
BOTTOM - InputLines, RIGHT
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
pnoutrefresh(
|
||||||
|
window->pad,
|
||||||
|
WindowLines - window->scroll - MAIN_LINES + MarkerLines, 0,
|
||||||
|
StatusLines, 0,
|
||||||
|
BOTTOM - InputLines - SplitLines - MarkerLines, RIGHT
|
||||||
);
|
);
|
||||||
if (window->scroll) {
|
|
||||||
touchwin(marker);
|
touchwin(marker);
|
||||||
wnoutrefresh(marker);
|
wnoutrefresh(marker);
|
||||||
pnoutrefresh(
|
pnoutrefresh(
|
||||||
window->pad,
|
window->pad,
|
||||||
WindowLines - SplitLines, 0,
|
WindowLines - SplitLines, 0,
|
||||||
BOTTOM - SplitLines, 0,
|
LINES - InputLines - SplitLines, 0,
|
||||||
BOTTOM - 1, RIGHT
|
BOTTOM - InputLines, RIGHT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
int y, x;
|
int y, x;
|
||||||
|
@ -330,7 +346,7 @@ void uiDraw(void) {
|
||||||
pnoutrefresh(
|
pnoutrefresh(
|
||||||
input,
|
input,
|
||||||
0, (x + 1 > RIGHT ? x + 1 - RIGHT : 0),
|
0, (x + 1 > RIGHT ? x + 1 - RIGHT : 0),
|
||||||
BOTTOM, 0,
|
LINES - InputLines, 0,
|
||||||
BOTTOM, RIGHT
|
BOTTOM, RIGHT
|
||||||
);
|
);
|
||||||
(void)y;
|
(void)y;
|
||||||
|
@ -517,21 +533,20 @@ void uiHide(void) {
|
||||||
static void windowScroll(struct Window *window, int n) {
|
static void windowScroll(struct Window *window, int n) {
|
||||||
mark(window);
|
mark(window);
|
||||||
window->scroll += n;
|
window->scroll += n;
|
||||||
if (window->scroll > WindowLines - PAGE_LINES) {
|
if (window->scroll > WindowLines - MAIN_LINES) {
|
||||||
window->scroll = WindowLines - PAGE_LINES;
|
window->scroll = WindowLines - MAIN_LINES;
|
||||||
}
|
}
|
||||||
if (window->scroll < 0) window->scroll = 0;
|
if (window->scroll < 0) window->scroll = 0;
|
||||||
unmark(window);
|
unmark(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void windowScrollPage(struct Window *window, int n) {
|
static void windowScrollPage(struct Window *window, int n) {
|
||||||
// -1 for split marker, -1 for line of overlap.
|
windowScroll(window, n * (MAIN_LINES - SplitLines - MarkerLines - 1));
|
||||||
windowScroll(window, n * (PAGE_LINES - SplitLines - 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void windowScrollUnread(struct Window *window) {
|
static void windowScrollUnread(struct Window *window) {
|
||||||
window->scroll = 0;
|
window->scroll = 0;
|
||||||
windowScroll(window, window->unreadSoft - PAGE_LINES + 1);
|
windowScroll(window, window->unreadSoft - MAIN_LINES);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wordWidth(const char *str) {
|
static int wordWidth(const char *str) {
|
||||||
|
@ -687,7 +702,7 @@ static void reflow(struct Window *window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resize(void) {
|
static void resize(void) {
|
||||||
mvwin(marker, BOTTOM - SplitLines - 1, 0);
|
mvwin(marker, LINES - InputLines - SplitLines - MarkerLines, 0);
|
||||||
int height, width;
|
int height, width;
|
||||||
getmaxyx(windows.ptrs[0]->pad, height, width);
|
getmaxyx(windows.ptrs[0]->pad, height, width);
|
||||||
if (width == COLS) return;
|
if (width == COLS) return;
|
||||||
|
|
Loading…
Reference in New Issue