Show all dictionaries in the header

Make the style of the active dictionary's name configurable.
This commit is contained in:
Přemysl Eric Janouch 2016-09-28 05:05:24 +02:00
parent 4f0a47d5f7
commit 30345ec8d4
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 22 additions and 8 deletions

View File

@ -155,6 +155,7 @@ resolve_filename (const gchar *filename, gchar *(*relative_cb) (const char *))
#define ATTRIBUTE_TABLE(XX) \ #define ATTRIBUTE_TABLE(XX) \
XX( HEADER, "header", -1, -1, A_REVERSE ) \ XX( HEADER, "header", -1, -1, A_REVERSE ) \
XX( ACTIVE, "header-active", -1, -1, A_UNDERLINE ) \
XX( SEARCH, "search", -1, -1, A_UNDERLINE ) \ XX( SEARCH, "search", -1, -1, A_UNDERLINE ) \
XX( EVEN, "even", -1, -1, 0 ) \ XX( EVEN, "even", -1, -1, 0 ) \
XX( ODD, "odd", -1, -1, 0 ) XX( ODD, "odd", -1, -1, 0 )
@ -337,6 +338,11 @@ dictionary_load (Dictionary *self, GError **e)
(stardict_dict_get_info (self->dict))); (stardict_dict_get_info (self->dict)));
} }
// Add some padding for decorative purposes
gchar *tmp = g_strdup_printf (" %s ", self->name);
g_free (self->name);
self->name = tmp;
gunichar *ucs4 = g_utf8_to_ucs4_fast (self->name, -1, NULL); gunichar *ucs4 = g_utf8_to_ucs4_fast (self->name, -1, NULL);
for (gunichar *it = ucs4; *it; it++) for (gunichar *it = ucs4; *it; it++)
self->name_width += unichar_width (*it); self->name_width += unichar_width (*it);
@ -868,8 +874,16 @@ app_redraw_top (Application *self)
attrset (APP_ATTR (HEADER)); attrset (APP_ATTR (HEADER));
mvwhline (stdscr, 0, 0, APP_ATTR (HEADER), COLS); 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, PROJECT_NAME " ", A_BOLD, -1);
app_add_utf8_string (self, stardict_info_get_book_name
(stardict_dict_get_info (self->dict)), 0, COLS - indent); attrset (0);
for (guint i = 0; i < self->dictionaries->len; i++)
{
Dictionary *dict = &g_array_index (self->dictionaries, Dictionary, i);
indent += app_add_utf8_string (self, dict->name,
(self->dictionaries->len > 1 && self->dict == dict->dict)
? APP_ATTR (ACTIVE) : APP_ATTR (HEADER),
MIN (COLS - indent, dict->name_width));
}
attrset (APP_ATTR (SEARCH)); attrset (APP_ATTR (SEARCH));
mvwhline (stdscr, 1, 0, APP_ATTR (SEARCH), COLS); mvwhline (stdscr, 1, 0, APP_ATTR (SEARCH), COLS);