Skip to content

Commit

Permalink
Use new array syntax for tab-stops
Browse files Browse the repository at this point in the history
  • Loading branch information
jirutka committed Jan 24, 2022
1 parent 9e95be7 commit a69ae09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
20 changes: 4 additions & 16 deletions doc/rofi-theme.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -452,21 +452,6 @@ style property.
> When no unit is specified, pixels are assumed.

## Tab Stops

* Format: `{Integer}`
* Format: `{Distance}`
* Format: `{Distance} {Distance}`
* Format: `{Distance} {Distance} {Distance}`
* Format: `{Distance} {Distance} {Distance} {Distance}`

You can specify location of up to four tab stops by their distance from the beginning of the line.
Each distance must be greater than the previous one.
The text appears to the right of the tab stop position (other alignments are not supported yet).

If no unit is specified, pixels are assumed.


## Position

Indicate a place on the window/monitor.
Expand Down Expand Up @@ -784,7 +769,10 @@ The following properties are currently supported:
* **placeholder-color**: Color of the placeholder text.
* **blink**: Enable/Disable blinking on an input textbox (Boolean).
* **markup**: Force markup on, beware that only valid pango markup strings are shown.
* **tab-stops**: Set the tab stops.
* **tab-stops**: array of distances
Set the location of tab stops by their distance from the beginning of the line.
Each distance should be greater than the previous one.
The text appears to the right of the tab stop position (other alignments are not supported yet).

### listview:
* **columns**: integer
Expand Down
19 changes: 11 additions & 8 deletions source/widgets/textbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,26 @@ static void textbox_initialize_font(textbox *tb) {
}

static void textbox_tab_stops(textbox *tb) {
RofiPadding def = WIDGET_PADDING_INIT;
RofiPadding pad = rofi_theme_get_padding(WIDGET(tb), "tab-stops", def);
GList *dists = rofi_theme_get_array_distance(WIDGET(tb), "tab-stops");

if (&pad != &def) {
PangoTabArray *tabs = pango_tab_array_new(4, TRUE);
RofiDistance distances[] = {pad.top, pad.right, pad.bottom, pad.left};
if (dists != NULL) {
PangoTabArray *tabs = pango_tab_array_new(g_list_length(dists), TRUE);

for (int i = 0, ppx = 0; i < 4; i++) {
int px = distance_get_pixel(distances[i], ROFI_ORIENTATION_HORIZONTAL);
int i = 0, ppx = 0;
for (const GList *iter = g_list_first(dists); iter != NULL; iter = g_list_next(iter), i++) {
const RofiDistance *dist = iter->data;

int px = distance_get_pixel(*dist, ROFI_ORIENTATION_HORIZONTAL);
if (px <= ppx) {
break;
continue;
}
pango_tab_array_set_tab(tabs, i, PANGO_TAB_LEFT, px);
ppx = px;
}
pango_layout_set_tabs(tb->layout, tabs);

pango_tab_array_free(tabs);
g_list_free_full(dists, g_free);
}
}

Expand Down

0 comments on commit a69ae09

Please sign in to comment.