Scroll the input pad
This commit is contained in:
		
							parent
							
								
									f8e5648a9a
								
							
						
					
					
						commit
						ea23dcec3b
					
				
							
								
								
									
										22
									
								
								ui.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								ui.c
									
									
									
									
									
								
							@ -33,6 +33,8 @@
 | 
				
			|||||||
#define A_ITALIC A_NORMAL
 | 
					#define A_ITALIC A_NORMAL
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MAX(a, b) ((a) > (b) ? (a) : (b))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const int TOPIC_COLS = 512;
 | 
					static const int TOPIC_COLS = 512;
 | 
				
			||||||
static const int CHAT_LINES = 100;
 | 
					static const int CHAT_LINES = 100;
 | 
				
			||||||
static const int INPUT_COLS = 512;
 | 
					static const int INPUT_COLS = 512;
 | 
				
			||||||
@ -41,6 +43,7 @@ static struct {
 | 
				
			|||||||
	WINDOW *topic;
 | 
						WINDOW *topic;
 | 
				
			||||||
	WINDOW *chat;
 | 
						WINDOW *chat;
 | 
				
			||||||
	WINDOW *input;
 | 
						WINDOW *input;
 | 
				
			||||||
 | 
						size_t cursor;
 | 
				
			||||||
} ui;
 | 
					} ui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void uiInit(void) {
 | 
					void uiInit(void) {
 | 
				
			||||||
@ -70,7 +73,7 @@ void uiInit(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	ui.input = newpad(2, INPUT_COLS);
 | 
						ui.input = newpad(2, INPUT_COLS);
 | 
				
			||||||
	mvwhline(ui.input, 0, 0, ACS_HLINE, INPUT_COLS);
 | 
						mvwhline(ui.input, 0, 0, ACS_HLINE, INPUT_COLS);
 | 
				
			||||||
	wmove(ui.input, 1, 0);
 | 
						wmove(ui.input, 1, ui.cursor);
 | 
				
			||||||
	nodelay(ui.input, true);
 | 
						nodelay(ui.input, true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -84,17 +87,20 @@ void uiHide(void) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void uiDraw(void) {
 | 
					void uiDraw(void) {
 | 
				
			||||||
	pnoutrefresh(ui.topic, 0, 0, 0, 0, 1, COLS - 1);
 | 
						int lastCol = COLS - 1;
 | 
				
			||||||
 | 
						int lastLine = LINES - 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pnoutrefresh(ui.topic, 0, 0, 0, 0, 1, lastCol);
 | 
				
			||||||
	pnoutrefresh(
 | 
						pnoutrefresh(
 | 
				
			||||||
		ui.chat,
 | 
							ui.chat,
 | 
				
			||||||
		CHAT_LINES - (LINES - 4), 0,
 | 
							CHAT_LINES - (lastLine - 4), 0,
 | 
				
			||||||
		2, 0, LINES - 1, COLS - 1
 | 
							2, 0, lastLine, lastCol
 | 
				
			||||||
	);
 | 
						);
 | 
				
			||||||
	pnoutrefresh(
 | 
						pnoutrefresh(
 | 
				
			||||||
		ui.input,
 | 
							ui.input,
 | 
				
			||||||
		0, 0,
 | 
							0, MAX(0, ui.cursor - lastCol),
 | 
				
			||||||
		LINES - 2, 0,
 | 
							lastLine - 1, 0,
 | 
				
			||||||
		LINES - 1, COLS - 1
 | 
							lastLine, lastCol
 | 
				
			||||||
	);
 | 
						);
 | 
				
			||||||
	doupdate();
 | 
						doupdate();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -213,6 +219,7 @@ void uiRead(void) {
 | 
				
			|||||||
				len = 0;
 | 
									len = 0;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break; default: {
 | 
								break; default: {
 | 
				
			||||||
 | 
									// TODO: Check overflow
 | 
				
			||||||
				if (iswprint(ch)) buf[len++] = ch;
 | 
									if (iswprint(ch)) buf[len++] = ch;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -220,4 +227,5 @@ void uiRead(void) {
 | 
				
			|||||||
	wmove(ui.input, 1, 0);
 | 
						wmove(ui.input, 1, 0);
 | 
				
			||||||
	waddnwstr(ui.input, buf, len);
 | 
						waddnwstr(ui.input, buf, len);
 | 
				
			||||||
	wclrtoeol(ui.input);
 | 
						wclrtoeol(ui.input);
 | 
				
			||||||
 | 
						ui.cursor = len;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user