From 388eef02ae83afde2813339f7662cfa0c9a9bb1d Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Wed, 23 Apr 2025 22:06:19 +0200 Subject: [PATCH] render bullet points --- application/gtk-text.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/application/gtk-text.c b/application/gtk-text.c index 816da35..e6839c8 100644 --- a/application/gtk-text.c +++ b/application/gtk-text.c @@ -1179,6 +1179,34 @@ void editor_set_paragraph_style(UiText *text, const char *style) { } } + +static void draw_bulletlist( + GtkDrawingArea *area, + cairo_t *cr, + int width, + int height, + gpointer data) +{ + GtkWidget *parent = gtk_widget_get_parent(GTK_WIDGET(area)); + PangoContext *context = gtk_widget_get_pango_context(parent); + PangoFontDescription *font = pango_context_get_font_description(context); + + PangoLayout *layout = pango_cairo_create_layout(cr); + pango_layout_set_text (layout, "•", -1); + pango_layout_set_font_description (layout, font); + + int textwidth; + int textheight; + pango_layout_get_size (layout, &textwidth, &textheight); + textwidth /= PANGO_SCALE; + textheight /= PANGO_SCALE; + + int x = (width - textwidth) / 2; + + cairo_move_to(cr, x, 0); + pango_cairo_show_layout(cr, layout); +} + void editor_insert_list(UiText *text, UiBool oredered) { GtkTextBuffer *buffer = text->data1; NoteEditor *editor = g_object_get_data(text->obj, "editor"); @@ -1203,8 +1231,10 @@ void editor_insert_list(UiText *text, UiBool oredered) { //GtkWidget *widget = gtk_label_new("•"); GtkWidget *widget = gtk_drawing_area_new(); // • + gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(widget), draw_bulletlist, NULL, NULL); + gtk_widget_set_size_request(widget, 40, height); - gtk_widget_add_css_class(widget, "ui_test"); + //gtk_widget_add_css_class(widget, "ui_test"); gtk_widget_set_margin_bottom(widget, -descent); gtk_widget_set_margin_start(widget, -40); -- 2.43.5