- /* center str in a size-char buffer, but don't overrun */
- len = strlen(str);
- len = min(len, size);
- idx = (size - len) / 2;
+ /* Center str in the field. This depends on the number of columns used
+ * by the string, not the number of chars in str */
+ len = strncols(str);
+ if (len <= size) {
+ idx = (field_size - len) / 2;
+ } else {
+ idx = 1;
+ pb_log("Warning: '%s' %d columns wide "
+ "but button is %d columns wide\n",
+ str, len, size);
+ }
+
+ pad1 = max(idx - 1, 0);
+ pad2 = max(size - len - pad1, 0);
+ bufsz = 1 + pad1 + strlen(str) + pad2 + 2;