[gnome-builder/wip/libide-merge] reintroduce animations, but be less annoying than GtkTextView defaults
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide-merge] reintroduce animations, but be less annoying than GtkTextView defaults
- Date: Sat, 21 Mar 2015 21:44:23 +0000 (UTC)
commit 6c035416dbcfc913d1383c97edf554d08da7ea97
Author: Christian Hergert <christian hergert me>
Date: Sat Mar 21 14:44:11 2015 -0700
reintroduce animations, but be less annoying than GtkTextView defaults
This uses different animation times based on how far we are scrolling.
Additionally, we sync to the frame clock of the source view.
We also ignore animations if it's going just be really annoying (like a
1 line movement at the top/bottom of the screen, common during key
repeat).
libide/ide-source-view-movements.c | 6 ++--
libide/ide-source-view.c | 59 ++++++++++++++++++++++++++++++++----
libide/ide-source-view.h | 6 ++-
src/editor/gb-editor-view.c | 2 +-
4 files changed, 61 insertions(+), 12 deletions(-)
---
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index 60232cb..6beed2a 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -852,15 +852,15 @@ ide_source_view_movements_scroll_center (Movement *mv)
switch ((int)mv->type)
{
case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_BOTTOM:
- ide_source_view_scroll_to_mark (mv->self, insert, 0.0, TRUE, 1.0, 1.0);
+ ide_source_view_scroll_to_mark (mv->self, insert, 0.0, TRUE, 1.0, 1.0, TRUE);
break;
case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_TOP:
- ide_source_view_scroll_to_mark (mv->self, insert, 0.0, TRUE, 1.0, 0.0);
+ ide_source_view_scroll_to_mark (mv->self, insert, 0.0, TRUE, 1.0, 0.0, TRUE);
break;
case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_CENTER:
- ide_source_view_scroll_to_mark (mv->self, insert, 0.0, TRUE, 1.0, 0.5);
+ ide_source_view_scroll_to_mark (mv->self, insert, 0.0, TRUE, 1.0, 0.5, TRUE);
break;
default:
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 2fce0e6..9a50043 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -59,6 +59,8 @@
#define DEFAULT_FONT_DESC "Monospace 11"
#define ANIMATION_X_GROW 50
#define ANIMATION_Y_GROW 30
+#define SMALL_SCROLL_DURATION_MSEC 100
+#define LARGE_SCROLL_DURATION_MSEC 250
#define _GDK_RECTANGLE_X2(rect) ((rect)->x + (rect)->width)
#define _GDK_RECTANGLE_Y2(rect) ((rect)->y + (rect)->height)
@@ -5831,7 +5833,7 @@ ide_source_view_scroll_mark_onscreen (IdeSourceView *self,
gtk_text_view_get_iter_location (text_view, &iter, &mark_rect);
if (!_GDK_RECTANGLE_CONTAINS (&visible_rect, &mark_rect))
- ide_source_view_scroll_to_mark (self, mark, 0.0, FALSE, 0.0, 0.0);
+ ide_source_view_scroll_to_mark (self, mark, 0.0, FALSE, 0.0, 0.0, TRUE);
IDE_EXIT;
}
@@ -5883,12 +5885,14 @@ ide_source_view_scroll_to_iter (IdeSourceView *self,
gdouble within_margin,
gboolean use_align,
gdouble xalign,
- gdouble yalign)
+ gdouble yalign,
+ gboolean animate_scroll)
{
IdeSourceViewPrivate *priv = ide_source_view_get_instance_private (self);
GtkTextView *text_view = (GtkTextView *)self;
GtkAdjustment *hadj;
GtkAdjustment *vadj;
+ GdkFrameClock *frame_clock;
GdkRectangle real_visible_rect;
GdkRectangle visible_rect;
GdkRectangle iter_rect;
@@ -5964,8 +5968,49 @@ ide_source_view_scroll_to_iter (IdeSourceView *self,
yvalue = iter_rect.y - (yalign * real_visible_rect.height);
xvalue = iter_rect.x - (xalign * real_visible_rect.width);
- gtk_adjustment_set_value (hadj, xvalue);
- gtk_adjustment_set_value (vadj, yvalue);
+ frame_clock = gtk_widget_get_frame_clock (GTK_WIDGET (self));
+
+ if (animate_scroll)
+ {
+ guint duration_msec = LARGE_SCROLL_DURATION_MSEC;
+ gdouble difference;
+ gdouble page_size;
+ gdouble current;
+
+ current = gtk_adjustment_get_value (vadj);
+ page_size = gtk_adjustment_get_page_size (vadj);
+ difference = ABS (current - yvalue);
+
+ /*
+ * Ignore animations if we are scrolling less than two full lines. This
+ * helps when pressing up/down for key repeat. Also, if it's a partial
+ * page scroll (less than page size), use less time to animate, so it
+ * isn't so annoying.
+ */
+ if (difference < (priv->cached_char_height * 2))
+ goto ignore_animation;
+ else if (difference <= page_size)
+ duration_msec = SMALL_SCROLL_DURATION_MSEC;
+
+ ide_object_animate (hadj,
+ IDE_ANIMATION_EASE_IN_CUBIC,
+ duration_msec,
+ frame_clock,
+ "value", xvalue,
+ NULL);
+ ide_object_animate (vadj,
+ IDE_ANIMATION_EASE_IN_CUBIC,
+ duration_msec,
+ frame_clock,
+ "value", yvalue,
+ NULL);
+ }
+ else
+ {
+ignore_animation:
+ gtk_adjustment_set_value (hadj, xvalue);
+ gtk_adjustment_set_value (vadj, yvalue);
+ }
IDE_EXIT;
}
@@ -5976,7 +6021,8 @@ ide_source_view_scroll_to_mark (IdeSourceView *self,
gdouble within_margin,
gboolean use_align,
gdouble xalign,
- gdouble yalign)
+ gdouble yalign,
+ gboolean animate_scroll)
{
GtkTextBuffer *buffer;
GtkTextIter iter;
@@ -5990,7 +6036,8 @@ ide_source_view_scroll_to_mark (IdeSourceView *self,
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
- ide_source_view_scroll_to_iter (self, &iter, within_margin, use_align, xalign, yalign);
+ ide_source_view_scroll_to_iter (self, &iter, within_margin, use_align, xalign, yalign,
+ animate_scroll);
}
gboolean
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index 2374408..9fa78b4 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -340,13 +340,15 @@ void ide_source_view_scroll_to_mark (IdeSource
gdouble
within_margin,
gboolean use_align,
gdouble xalign,
- gdouble yalign);
+ gdouble yalign,
+ gboolean
animate_scroll);
void ide_source_view_scroll_to_iter (IdeSourceView *self,
const GtkTextIter *iter,
gdouble
within_margin,
gboolean use_align,
gdouble xalign,
- gdouble yalign);
+ gdouble yalign,
+ gboolean
animate_scroll);
G_END_DECLS
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index bf2a6e9..e02a596 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -79,7 +79,7 @@ gb_editor_view_navigate_to (GbView *view,
break;
gtk_text_buffer_select_range (buffer, &iter, &iter);
- ide_source_view_scroll_to_iter (frame->source_view, &iter, 0.0, TRUE, 1.0, 0.5);
+ ide_source_view_scroll_to_iter (frame->source_view, &iter, 0.0, TRUE, 1.0, 0.5, TRUE);
IDE_EXIT;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]