tui: add nmt_newt_text_width()

We were using g_utf8_strlen() to measure strings for layout, but that
counts combining marks too, and also fails to deal with "fullwidth"
(ie, double-width) CJK characters.

Add a new utility function to do a better job of this (based on code
from vte), and use it everywhere.
This commit is contained in:
Dan Winship
2014-01-06 13:34:30 -05:00
parent 1d40b9f872
commit 64cb43b3b2
7 changed files with 54 additions and 21 deletions

View File

@@ -436,7 +436,7 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
for (citer = nmtdev->conns; citer; citer = citer->next) {
nmtconn = citer->data;
max_width = MAX (max_width, g_utf8_strlen (nmtconn->name, -1));
max_width = MAX (max_width, nmt_newt_text_width (nmtconn->name));
}
}
@@ -477,7 +477,7 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
row = g_strdup_printf ("%c %s%-*s%s",
active_col,
nmtconn->name,
(int)(max_width - g_utf8_strlen (nmtconn->name, -1)), "",
(int)(max_width - nmt_newt_text_width (nmtconn->name)), "",
strength_col);
nmt_newt_listbox_append (listbox, row, nmtconn);