Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Textbox] Draw text after cursor #1777

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions source/widgets/textbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,28 +518,6 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
}
}

// draw the text
cairo_save(draw);
cairo_reset_clip(draw);

gboolean show_outline =
rofi_theme_get_boolean(WIDGET(tb), "text-outline", FALSE);
if (tb->show_placeholder) {
rofi_theme_get_color(WIDGET(tb), "placeholder-color", draw);
show_outline = FALSE;
}
pango_cairo_show_layout(draw, tb->layout);

if (show_outline) {
rofi_theme_get_color(WIDGET(tb), "text-outline-color", draw);
double width = rofi_theme_get_double(WIDGET(tb), "text-outline-width", 0.5);
pango_cairo_layout_path(draw, tb->layout);
cairo_set_line_width(draw, width);
cairo_stroke(draw);
}

cairo_restore(draw);

// draw the cursor
if (tb->flags & TB_EDITABLE) {
// We want to place the cursor based on the text shown.
Expand All @@ -563,6 +541,7 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
if (tb->blink) {
// use text color as fallback for themes that don't specify the cursor
// color
cairo_save(draw);
rofi_theme_get_color(WIDGET(tb), "cursor-color", draw);
cairo_rectangle(draw, x + cursor_x, y + cursor_y, cursor_pixel_width,
cursor_height);
Expand All @@ -576,8 +555,31 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
} else {
cairo_fill(draw);
}
cairo_restore(draw);
}
}

// draw the text
cairo_save(draw);
cairo_reset_clip(draw);

gboolean show_outline =
rofi_theme_get_boolean(WIDGET(tb), "text-outline", FALSE);
if (tb->show_placeholder) {
rofi_theme_get_color(WIDGET(tb), "placeholder-color", draw);
show_outline = FALSE;
}
pango_cairo_show_layout(draw, tb->layout);

if (show_outline) {
rofi_theme_get_color(WIDGET(tb), "text-outline-color", draw);
double width = rofi_theme_get_double(WIDGET(tb), "text-outline-width", 0.5);
pango_cairo_layout_path(draw, tb->layout);
cairo_set_line_width(draw, width);
cairo_stroke(draw);
}

cairo_restore(draw);
}

// cursor handling for edit mode
Expand Down