tmus

TUI Music Player
git clone https://git.sinitax.com/sinitax/tmus
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

pane.c (1059B)


      1#define _XOPEN_SOURCE
      2
      3#include "pane.h"
      4
      5#include "util.h"
      6#include "strbuf.h"
      7
      8#include <stdlib.h>
      9#include <string.h>
     10#include <wchar.h>
     11
     12void
     13pane_init(struct pane *pane, pane_handler handle, pane_updater update)
     14{
     15	pane->win = newwin(1, 1, 0, 0);
     16	ASSERT(pane->win != NULL);
     17	pane->handle = handle;
     18	pane->update = update;
     19}
     20
     21void
     22pane_deinit(struct pane *pane)
     23{
     24	delwin(pane->win);
     25}
     26
     27void
     28pane_resize(struct pane *pane, int sx, int sy, int ex, int ey)
     29{
     30	pane->sx = sx;
     31	pane->sy = sy;
     32	pane->ex = ex;
     33	pane->ey = ey;
     34	pane->w = pane->ex - pane->sx;
     35	pane->h = pane->ey - pane->sy;
     36
     37	pane->active = (pane->w > 0 && pane->h > 0);
     38	if (pane->active) {
     39		wresize(pane->win, pane->h, pane->w);
     40		mvwin(pane->win, pane->sy, pane->sx);
     41		redrawwin(pane->win);
     42	}
     43}
     44
     45void
     46pane_clearln(struct pane *pane, int row)
     47{
     48	int i;
     49
     50	wmove(pane->win, row, 0);
     51	for (i = 0; i < pane->w; i++)
     52		waddch(pane->win, ' ');
     53}
     54
     55void
     56pane_writeln(struct pane *pane, int row, const char *str)
     57{
     58	pane_clearln(pane, row);
     59	wmove(pane->win, row, 0);
     60	waddstr(pane->win, str);
     61}
     62