]> uap-core.de Git - note.git/commitdiff
render bullet points
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 23 Apr 2025 20:06:19 +0000 (22:06 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 23 Apr 2025 20:06:19 +0000 (22:06 +0200)
application/gtk-text.c

index 816da351666255fbebea598395906a54c80dda9b..e6839c8253d683ce1c6a66ace3330046387978ee 100644 (file)
@@ -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);