]> git.mdlowis.com Git - projs/tide.git/commitdiff
added optional column ruler
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 25 Mar 2017 23:12:18 +0000 (19:12 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 25 Mar 2017 23:12:18 +0000 (19:12 -0400)
TODO.md
inc/win.h
lib/win.c
xedit.c

diff --git a/TODO.md b/TODO.md
index 2efdf12ae3dbd763c68002bc21b5a0c2b381b058..30e410d1435b86add8c45e13a0f466952713a945 100644 (file)
--- 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
index 4b59f67a726c554d5a5d003640af30d2fbc07f6c..61281144964ef0219f837dfa3c010191ef828a43 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -1,56 +1,57 @@
-typedef enum {\r
-    STATUS   = 0,\r
-    TAGS     = 1,\r
-    EDIT     = 2,\r
-    SCROLL   = 3,\r
-    NREGIONS = 4,\r
-    FOCUSED  = 4\r
-} WinRegion;\r
-\r
-typedef struct {\r
-    int mods;\r
-    Rune key;\r
-    void (*action)(void);\r
-} KeyBinding;\r
-\r
-typedef struct {\r
-    size_t x;\r
-    size_t y;\r
-    size_t height;\r
-    size_t width;\r
-    size_t csrx;\r
-    size_t csry;\r
-    bool warp_ptr;\r
-    View view;\r
-} Region;\r
-\r
-typedef void (*MouseFunc)(WinRegion id, size_t count, size_t row, size_t col);\r
-\r
-typedef struct {\r
-    MouseFunc left;\r
-    MouseFunc middle;\r
-    MouseFunc right;\r
-} MouseConfig;\r
-\r
-void win_init(char* name);\r
-void win_loop(void);\r
-void win_settext(WinRegion id, char* text);\r
-void win_setkeys(KeyBinding* bindings);\r
-void win_setmouse(MouseConfig* mconfig);\r
-void win_warpptr(WinRegion id);\r
-View* win_view(WinRegion id);\r
-Buf* win_buf(WinRegion id);\r
-Sel* win_sel(WinRegion id);\r
-bool win_btnpressed(MouseBtn btn);\r
-WinRegion win_getregion(void);\r
-void win_setregion(WinRegion id);\r
-void win_setscroll(double offset, double visible);\r
-\r
-/* These functions must be implemented by any appliation that wishes \r
-   to use this module */\r
-void onupdate(void);\r
-void onscroll(double percent);\r
-void onmouseleft(WinRegion id, size_t count, size_t row, size_t col);\r
-void onmousemiddle(WinRegion id, size_t count, size_t row, size_t col);\r
-void onmouseright(WinRegion id, size_t count, size_t row, size_t col);\r
-\r
+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);
+
index 165a80618a10da422124702b5d12cbfdee7c0870..74d429944977cc6a2d60d9635c4877a5bc321a19 100644 (file)
--- 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 79831af52f1cf211b9577ba136c8124016893ce5..d82c8a30bd89a391e839ae7a2a7cf25a4f37aa84 100644 (file)
--- 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);