[gnome-builder] editor: don't let GtkLabel ruin the performance party
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: don't let GtkLabel ruin the performance party
- Date: Fri, 22 Apr 2016 06:50:43 +0000 (UTC)
commit af4354aa74cac2a46229ff4d63e842d1a765e2f3
Author: Christian Hergert <chergert redhat com>
Date: Thu Apr 21 23:50:01 2016 -0700
editor: don't let GtkLabel ruin the performance party
At the top of the editor, we display the current cursor position from
the textview. This has the disastrous side-effect of calling
gtk_widget_queue_resize() every time the label contents changes. Which
as you can imagine, is pretty much every keystroke (unless it was an
accelerator that didn't move the cursor).
When performing the resize, the textview was getting in a situation that
caused it to either do a full redraw or an unnecessary damage.
By using our helper EggSimpleLabel, we can avoid resize cycles in most
circumstances. This results in no more resize events every keypress
while moving with j/k/up/down.
data/ui/ide-editor-view.ui | 52 +++++++++++++++++++++++++++++-
libide/editor/ide-editor-view-private.h | 5 ++-
libide/editor/ide-editor-view.c | 32 ++++++++++++-------
3 files changed, 74 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/ide-editor-view.ui b/data/ui/ide-editor-view.ui
index 1bd4e73..1f6772b 100644
--- a/data/ui/ide-editor-view.ui
+++ b/data/ui/ide-editor-view.ui
@@ -114,12 +114,60 @@
<property name="popover">goto_line_popover</property>
<property name="focus-on-click">false</property>
<property name="tooltip-text" translatable="yes">Go to line number</property>
+ <property name="valign">baseline</property>
<property name="visible">true</property>
<child>
- <object class="GtkLabel" id="cursor_label">
- <property name="label">1:1</property>
+ <object class="GtkBox">
+ <property name="margin-start">3</property>
+ <property name="margin-end">3</property>
<property name="valign">baseline</property>
<property name="visible">true</property>
+ <child type="center">
+ <object class="GtkLabel">
+ <property name="label">:</property>
+ <property name="visible">true</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="EggSimpleLabel" id="line_label">
+ <property name="label">1</property>
+ <property name="width-chars">3</property>
+ <property name="xalign">1.0</property>
+ <property name="valign">baseline</property>
+ <property name="visible">true</property>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="EggSimpleLabel" id="column_label">
+ <property name="label">1</property>
+ <property name="width-chars">3</property>
+ <property name="xalign">0.0</property>
+ <property name="valign">baseline</property>
+ <property name="visible">true</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="range_label">
+ <property name="valign">baseline</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="position">0</property>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/libide/editor/ide-editor-view-private.h b/libide/editor/ide-editor-view-private.h
index 0dde724..4a13687 100644
--- a/libide/editor/ide-editor-view-private.h
+++ b/libide/editor/ide-editor-view-private.h
@@ -22,6 +22,7 @@
#include <libpeas/peas.h>
#include <gtk/gtk.h>
+#include "egg-simple-label.h"
#include "egg-simple-popover.h"
#include "ide-buffer.h"
@@ -40,7 +41,9 @@ struct _IdeEditorView
GSettings *settings;
gchar *title;
- GtkLabel *cursor_label;
+ EggSimpleLabel *line_label;
+ EggSimpleLabel *column_label;
+ GtkLabel *range_label;
IdeEditorFrame *frame1;
IdeEditorFrame *frame2;
IdeEditorFrame *last_focused_frame;
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index 8c1917a..babb98e 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -291,7 +291,7 @@ ide_editor_view__buffer_cursor_moved (IdeEditorView *self,
{
GtkTextIter bounds;
GtkTextMark *mark;
- gchar *str;
+ gchar str[32];
guint line;
gint column;
gint column2;
@@ -305,24 +305,30 @@ ide_editor_view__buffer_cursor_moved (IdeEditorView *self,
mark = gtk_text_buffer_get_selection_bound (buffer);
gtk_text_buffer_get_iter_at_mark (buffer, &bounds, mark);
+ g_snprintf (str, sizeof str, "%d", line + 1);
+ egg_simple_label_set_label (self->line_label, str);
+
+ g_snprintf (str, sizeof str, "%d", column + 1);
+ egg_simple_label_set_label (self->column_label, str);
+
if (!gtk_widget_has_focus (GTK_WIDGET (self->frame1->source_view)) ||
gtk_text_iter_equal (&bounds, iter) ||
(gtk_text_iter_get_line (iter) != gtk_text_iter_get_line (&bounds)))
{
- str = g_strdup_printf ("%d:%d", line + 1, column + 1);
- gtk_label_set_text (self->cursor_label, str);
- g_free (str);
+ gtk_widget_set_visible (GTK_WIDGET (self->range_label), FALSE);
return;
}
/* We have a selection that is on the same line.
* Lets give some detail as to how long the selection is.
*/
- column2 = gtk_source_view_get_visual_column (GTK_SOURCE_VIEW (self->frame1->source_view),
- &bounds);
- str = g_strdup_printf ("%d:%d (%d)", line + 1, column + 1, ABS (column2 - column));
- gtk_label_set_text (self->cursor_label, str);
- g_free (str);
+ column2 = gtk_source_view_get_visual_column (
+ GTK_SOURCE_VIEW (self->frame1->source_view),
+ &bounds);
+
+ g_snprintf (str, sizeof str, "%d", ABS (column2 - column));
+ gtk_label_set_label (self->range_label, str);
+ gtk_widget_set_visible (GTK_WIDGET (self->range_label), TRUE);
}
static void
@@ -910,16 +916,18 @@ ide_editor_view_class_init (IdeEditorViewClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/ui/ide-editor-view.ui");
- gtk_widget_class_bind_template_child (widget_class, IdeEditorView, cursor_label);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorView, column_label);
gtk_widget_class_bind_template_child (widget_class, IdeEditorView, frame1);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorView, goto_line_button);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorView, goto_line_popover);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorView, line_label);
gtk_widget_class_bind_template_child (widget_class, IdeEditorView, modified_cancel_button);
gtk_widget_class_bind_template_child (widget_class, IdeEditorView, modified_revealer);
gtk_widget_class_bind_template_child (widget_class, IdeEditorView, paned);
gtk_widget_class_bind_template_child (widget_class, IdeEditorView, progress_bar);
+ gtk_widget_class_bind_template_child (widget_class, IdeEditorView, range_label);
gtk_widget_class_bind_template_child (widget_class, IdeEditorView, tweak_button);
gtk_widget_class_bind_template_child (widget_class, IdeEditorView, tweak_widget);
- gtk_widget_class_bind_template_child (widget_class, IdeEditorView, goto_line_button);
- gtk_widget_class_bind_template_child (widget_class, IdeEditorView, goto_line_popover);
gtk_widget_class_bind_template_child (widget_class, IdeEditorView, warning_button);
g_type_ensure (IDE_TYPE_EDITOR_FRAME);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]