From e0983beb2c63b0b1d067ff8e89831ea26a47ac2d Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 25 Mar 2017 19:12:18 -0400 Subject: [PATCH] added optional column ruler --- TODO.md | 3 -- inc/win.h | 113 +++++++++++++++++++++++++++--------------------------- lib/win.c | 7 ++++ xedit.c | 1 + 4 files changed, 65 insertions(+), 59 deletions(-) diff --git a/TODO.md b/TODO.md index 2efdf12..30e410d 100644 --- a/TODO.md +++ b/TODO.md @@ -2,10 +2,7 @@ Up Next: -* picker should only draw visible lines * ctrl+d on last line segfaults/asserts - -* Tweak the scrollbar for use with the picker * check for file changes on save * check for file changes when window regains focus * Right click in tags region should search edit region diff --git a/inc/win.h b/inc/win.h index 4b59f67..6128114 100644 --- a/inc/win.h +++ b/inc/win.h @@ -1,56 +1,57 @@ -typedef enum { - STATUS = 0, - TAGS = 1, - EDIT = 2, - SCROLL = 3, - NREGIONS = 4, - FOCUSED = 4 -} WinRegion; - -typedef struct { - int mods; - Rune key; - void (*action)(void); -} KeyBinding; - -typedef struct { - size_t x; - size_t y; - size_t height; - size_t width; - size_t csrx; - size_t csry; - bool warp_ptr; - View view; -} Region; - -typedef void (*MouseFunc)(WinRegion id, size_t count, size_t row, size_t col); - -typedef struct { - MouseFunc left; - MouseFunc middle; - MouseFunc right; -} MouseConfig; - -void win_init(char* name); -void win_loop(void); -void win_settext(WinRegion id, char* text); -void win_setkeys(KeyBinding* bindings); -void win_setmouse(MouseConfig* mconfig); -void win_warpptr(WinRegion id); -View* win_view(WinRegion id); -Buf* win_buf(WinRegion id); -Sel* win_sel(WinRegion id); -bool win_btnpressed(MouseBtn btn); -WinRegion win_getregion(void); -void win_setregion(WinRegion id); -void win_setscroll(double offset, double visible); - -/* These functions must be implemented by any appliation that wishes - to use this module */ -void onupdate(void); -void onscroll(double percent); -void onmouseleft(WinRegion id, size_t count, size_t row, size_t col); -void onmousemiddle(WinRegion id, size_t count, size_t row, size_t col); -void onmouseright(WinRegion id, size_t count, size_t row, size_t col); - +typedef enum { + STATUS = 0, + TAGS = 1, + EDIT = 2, + SCROLL = 3, + NREGIONS = 4, + FOCUSED = 4 +} WinRegion; + +typedef struct { + int mods; + Rune key; + void (*action)(void); +} KeyBinding; + +typedef struct { + size_t x; + size_t y; + size_t height; + size_t width; + size_t csrx; + size_t csry; + bool warp_ptr; + View view; +} Region; + +typedef void (*MouseFunc)(WinRegion id, size_t count, size_t row, size_t col); + +typedef struct { + MouseFunc left; + MouseFunc middle; + MouseFunc right; +} MouseConfig; + +void win_init(char* name); +void win_loop(void); +void win_settext(WinRegion id, char* text); +void win_setruler(size_t ruler); +void win_setkeys(KeyBinding* bindings); +void win_setmouse(MouseConfig* mconfig); +void win_warpptr(WinRegion id); +View* win_view(WinRegion id); +Buf* win_buf(WinRegion id); +Sel* win_sel(WinRegion id); +bool win_btnpressed(MouseBtn btn); +WinRegion win_getregion(void); +void win_setregion(WinRegion id); +void win_setscroll(double offset, double visible); + +/* These functions must be implemented by any appliation that wishes + to use this module */ +void onupdate(void); +void onscroll(double percent); +void onmouseleft(WinRegion id, size_t count, size_t row, size_t col); +void onmousemiddle(WinRegion id, size_t count, size_t row, size_t col); +void onmouseright(WinRegion id, size_t count, size_t row, size_t col); + diff --git a/lib/win.c b/lib/win.c index 165a806..74d4299 100644 --- a/lib/win.c +++ b/lib/win.c @@ -21,6 +21,7 @@ static void onshutdown(void); static void onwheelup(WinRegion id, size_t count, size_t row, size_t col); static void onwheeldn(WinRegion id, size_t count, size_t row, size_t col); +static size_t Ruler = 0; static double ScrollOffset = 0.0; static double ScrollVisible = 1.0; static XFont Font; @@ -68,6 +69,10 @@ void win_settext(WinRegion id, char* text) { buf_logclear(&(view->buffer)); } +void win_setruler(size_t ruler) { + Ruler = ruler; +} + void win_setkeys(KeyBinding* bindings) { Keys = bindings; } @@ -164,6 +169,8 @@ static void onredraw(int width, int height) { x11_draw_rect((i == TAGS ? CLR_BASE02 : CLR_BASE03), 0, Regions[i].y - 3, width, Regions[i].height + 8); x11_draw_rect(CLR_BASE01, 0, Regions[i].y - 3, width, 1); + if ((i == EDIT) && (Ruler != 0)) + x11_draw_rect(CLR_BASE02, (Ruler+1) * fwidth, Regions[i].y-2, 1, Regions[i].height+7); for (size_t y = 0; y < view->nrows; y++) { Row* row = view_getrow(view, y); draw_glyphs(Regions[i].x, Regions[i].y + ((y+1) * fheight), row->cols, row->rlen, row->len); diff --git a/xedit.c b/xedit.c index 79831af..d82c8a3 100644 --- a/xedit.c +++ b/xedit.c @@ -544,6 +544,7 @@ int main(int argc, char** argv) { win_init("edit"); char* tags = getenv("EDITTAGS"); win_settext(TAGS, (tags ? tags : DEFAULT_TAGS)); + win_setruler(80); view_init(win_view(EDIT), (argc > 1 ? argv[1] : NULL)); win_setkeys(Bindings); //win_setmouse(&MouseHandlers); -- 2.49.0