diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2016-09-28 05:27:53 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2016-09-28 05:27:53 +0200 |
commit | b3458d84a06f6ca891f4ae3ae15d035817c83418 (patch) | |
tree | e2191271e5455b79761908f66aba22e4957b2e7f /src/sdtui.c | |
parent | 1f60d096ea3ce54c0a31107c6b8be34b3c42f11f (diff) | |
download | tdv-b3458d84a06f6ca891f4ae3ae15d035817c83418.tar.gz tdv-b3458d84a06f6ca891f4ae3ae15d035817c83418.tar.xz tdv-b3458d84a06f6ca891f4ae3ae15d035817c83418.zip |
Handle mouse clicks on dictionary names
Diffstat (limited to 'src/sdtui.c')
-rw-r--r-- | src/sdtui.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/sdtui.c b/src/sdtui.c index f14b920..05b161c 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -52,6 +52,7 @@ #define CTRL_KEY(x) ((x) - 'A' + 1) #define TOP_BAR_CUTOFF 2 ///< How many lines are reserved on top +#define APP_TITLE PROJECT_NAME " " ///< Left top corner // --- Utilities --------------------------------------------------------------- @@ -873,7 +874,7 @@ app_redraw_top (Application *self) { attrset (APP_ATTR (HEADER)); mvwhline (stdscr, 0, 0, APP_ATTR (HEADER), COLS); - gsize indent = app_add_utf8_string (self, PROJECT_NAME " ", A_BOLD, -1); + gsize indent = app_add_utf8_string (self, APP_TITLE, A_BOLD, -1); attrset (0); for (guint i = 0; i < self->dictionaries->len; i++) @@ -1280,14 +1281,6 @@ app_goto_dictionary (Application *self, guint n) return TRUE; } -#define SAVE_CURSOR \ - int last_x, last_y; \ - getyx (stdscr, last_y, last_x); - -#define RESTORE_CURSOR \ - move (last_y, last_x); \ - refresh (); - /// The terminal has been resized, make appropriate changes. static gboolean app_process_resize (Application *self) @@ -1345,6 +1338,14 @@ enum user_action USER_ACTION_COUNT }; +#define SAVE_CURSOR \ + int last_x, last_y; \ + getyx (stdscr, last_y, last_x); + +#define RESTORE_CURSOR \ + move (last_y, last_x); \ + refresh (); + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static gboolean @@ -1668,7 +1669,21 @@ app_process_left_mouse_click (Application *self, int line, int column) { SAVE_CURSOR if (line == 0) - ; // At the moment there's nothing useful for us to do + { + int indent = strlen (APP_TITLE); + if (column < indent) + return; + + Dictionary *dicts = (Dictionary *) self->dictionaries->data; + for (guint i = 0; i < self->dictionaries->len; i++) + { + if (column < (indent += dicts[i].name_width)) + { + app_goto_dictionary (self, i); + return; + } + } + } else if (line == 1) { // FIXME: this is only an approximation |