From 06ec128632d51750bd0ea36436145759eda4765a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 28 Apr 2019 18:07:50 +0200 Subject: Defer re-wrapping until redraw This avoids repeatedly re-wrapping. --- libstorycode/gtk/gtknarrativeview.c | 9 +++++++-- libstorycode/gtk/gtknarrativeview.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c index 427b637..d45ae5d 100644 --- a/libstorycode/gtk/gtknarrativeview.c +++ b/libstorycode/gtk/gtknarrativeview.c @@ -606,6 +606,11 @@ static void draw_overlay(cairo_t *cr, GtkNarrativeView *e) static gboolean draw_sig(GtkWidget *da, cairo_t *cr, GtkNarrativeView *e) { + if ( e->rewrap_needed ) { + rewrap_range(e, 0, e->n->n_items); + e->rewrap_needed = 0; + } + /* Ultimate background */ cairo_set_source_rgba(cr, 0.8, 0.8, 1.0, 1.0); cairo_paint(cr); @@ -1120,7 +1125,7 @@ GtkWidget *gtk_narrative_view_new(Narrative *n) nview->h = 100; nview->scroll_pos = 0; nview->n = n; - + nview->rewrap_needed = 0; nview->para_highlight = 0; gtk_widget_set_size_request(GTK_WIDGET(nview), @@ -1228,7 +1233,7 @@ void gtk_narrative_view_add_slide_at_cursor(GtkNarrativeView *e) extern void gtk_narrative_view_redraw(GtkNarrativeView *e) { - rewrap_range(e, 0, e->n->n_items); + e->rewrap_needed = 1; emit_change_sig(e); redraw(e); } diff --git a/libstorycode/gtk/gtknarrativeview.h b/libstorycode/gtk/gtknarrativeview.h index fd589c5..910c60f 100644 --- a/libstorycode/gtk/gtknarrativeview.h +++ b/libstorycode/gtk/gtknarrativeview.h @@ -81,6 +81,7 @@ struct _gtknarrativeview double h_scroll_pos; int visible_height; int visible_width; + int rewrap_needed; /* Location of the cursor */ struct edit_pos cpos; -- cgit v1.2.3