Line up selectable items
This commit is contained in:
committed by
Pasi Kallinen
parent
ffb08d3be6
commit
84bf23640c
+1
-2
@@ -184,13 +184,12 @@ X11_set_column_widths(Widget w, const int *col_widths, unsigned num_cols)
|
|||||||
{
|
{
|
||||||
WidgetData *data = get_widget_data(w);
|
WidgetData *data = get_widget_data(w);
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
int col_spacing = X11_font_height(data->font[0]) * 2;
|
|
||||||
free(data->columns);
|
free(data->columns);
|
||||||
data->columns = (int *) alloc(sizeof(data->columns[0]) * num_cols);
|
data->columns = (int *) alloc(sizeof(data->columns[0]) * num_cols);
|
||||||
if (num_cols != 0) {
|
if (num_cols != 0) {
|
||||||
data->columns[0] = 0;
|
data->columns[0] = 0;
|
||||||
for (unsigned i = 1; i < num_cols; ++i) {
|
for (unsigned i = 1; i < num_cols; ++i) {
|
||||||
data->columns[i] = data->columns[i-1] + col_spacing + col_widths[i-1];
|
data->columns[i] = data->columns[i-1] + col_widths[i-1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data->num_cols = num_cols;
|
data->num_cols = num_cols;
|
||||||
|
|||||||
+37
-2
@@ -854,7 +854,7 @@ X11_add_menu(winid window,
|
|||||||
impossible("Menu item too long (%d).", len);
|
impossible("Menu item too long (%d).", len);
|
||||||
len = BUFSZ - 1;
|
len = BUFSZ - 1;
|
||||||
}
|
}
|
||||||
Sprintf(buf, "%c %c ", ch ? ch : ' ', preselected ? '+' : '-');
|
Sprintf(buf, "%c\t%c\t", ch ? ch : ' ', preselected ? '+' : '-');
|
||||||
(void) strncpy(buf + 4, str, len);
|
(void) strncpy(buf + 4, str, len);
|
||||||
buf[4 + len] = '\0';
|
buf[4 + len] = '\0';
|
||||||
item->str = copy_of(buf);
|
item->str = copy_of(buf);
|
||||||
@@ -1318,6 +1318,17 @@ menu_create_entries(struct xwindow *wp, struct menu *curr_menu)
|
|||||||
Cardinal num_args;
|
Cardinal num_args;
|
||||||
Dimension cwidth, maxwidth = 0;
|
Dimension cwidth, maxwidth = 0;
|
||||||
|
|
||||||
|
/* Does any line have a selector? */
|
||||||
|
boolean any_canpick = FALSE;
|
||||||
|
if (how != PICK_NONE) {
|
||||||
|
for (curr = curr_menu->base; curr; curr = curr->next) {
|
||||||
|
if (curr->identifier.a_void != NULL) {
|
||||||
|
any_canpick = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int *col_widths = NULL;
|
int *col_widths = NULL;
|
||||||
unsigned num_cols = 0;
|
unsigned num_cols = 0;
|
||||||
X11_Font *font;
|
X11_Font *font;
|
||||||
@@ -1333,6 +1344,23 @@ menu_create_entries(struct xwindow *wp, struct menu *curr_menu)
|
|||||||
int color = NO_COLOR;
|
int color = NO_COLOR;
|
||||||
boolean canpick = (how != PICK_NONE && curr->identifier.a_void);
|
boolean canpick = (how != PICK_NONE && curr->identifier.a_void);
|
||||||
|
|
||||||
|
/* Add tabs if needed to align non-selector lines with selector lines */
|
||||||
|
if (any_canpick && !canpick) {
|
||||||
|
char *buf;
|
||||||
|
if (strncmp(str, " ", 4) == 0) {
|
||||||
|
size_t buf_len = strlen(str);
|
||||||
|
buf = (char *) alloc(buf_len);
|
||||||
|
Snprintf(buf, buf_len, "\t\t%s", str + 4);
|
||||||
|
} else {
|
||||||
|
size_t buf_len = strlen(str) + 3;
|
||||||
|
buf = (char *) alloc(buf_len);
|
||||||
|
Snprintf(buf, buf_len, "\t\t%s", str);
|
||||||
|
}
|
||||||
|
free(curr->str);
|
||||||
|
curr->str = buf;
|
||||||
|
str = buf;
|
||||||
|
}
|
||||||
|
|
||||||
num_args = 0;
|
num_args = 0;
|
||||||
XtSetArg(args[num_args], nhStr(XtNlabel), str); num_args++;
|
XtSetArg(args[num_args], nhStr(XtNlabel), str); num_args++;
|
||||||
XtSetArg(args[num_args], nhStr(XtNjustify), XtJustifyLeft); num_args++;
|
XtSetArg(args[num_args], nhStr(XtNjustify), XtJustifyLeft); num_args++;
|
||||||
@@ -1446,6 +1474,8 @@ menu_create_entries(struct xwindow *wp, struct menu *curr_menu)
|
|||||||
static unsigned
|
static unsigned
|
||||||
get_col_widths(Widget w, X11_Font *font, const char *str, int **col_widths)
|
get_col_widths(Widget w, X11_Font *font, const char *str, int **col_widths)
|
||||||
{
|
{
|
||||||
|
int col_spacing = X11_column_width(XtDisplay(w), font, "# ", 2);
|
||||||
|
|
||||||
/* Determine the number of columns */
|
/* Determine the number of columns */
|
||||||
unsigned num_cols = 1;
|
unsigned num_cols = 1;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
@@ -1467,7 +1497,12 @@ get_col_widths(Widget w, X11_Font *font, const char *str, int **col_widths)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (str[i] != '\0') {
|
while (str[i] != '\0') {
|
||||||
size_t len = strcspn(str + i, "\t");
|
size_t len = strcspn(str + i, "\t");
|
||||||
cwidths[col++] = X11_column_width(XtDisplay(w), font, str + i, len);
|
cwidths[col] = X11_column_width(XtDisplay(w), font, str + i, len);
|
||||||
|
if (len > 1) {
|
||||||
|
col_spacing = X11_font_height(font) * 2;
|
||||||
|
}
|
||||||
|
cwidths[col] += col_spacing;
|
||||||
|
++col;
|
||||||
i += len;
|
i += len;
|
||||||
if (str[i] == '\t') {
|
if (str[i] == '\t') {
|
||||||
++i;
|
++i;
|
||||||
|
|||||||
Reference in New Issue
Block a user