[shotwell] Extract function to scroll to item
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell] Extract function to scroll to item
- Date: Sat, 23 Feb 2019 19:03:50 +0000 (UTC)
commit 83d11b3a95e177170f1b2cf5fbcf7a4d5f4639c0
Author: Jens Georg <mail jensge org>
Date: Sat Feb 23 19:39:14 2019 +0100
Extract function to scroll to item
Code was copied into three places. Time to make it a function
src/MapWidget.vala | 21 ++------------------
src/Page.vala | 57 +++++++++++++++++++++---------------------------------
2 files changed, 24 insertions(+), 54 deletions(-)
---
diff --git a/src/MapWidget.vala b/src/MapWidget.vala
index 3b41a5f5..3959649f 100644
--- a/src/MapWidget.vala
+++ b/src/MapWidget.vala
@@ -509,25 +509,8 @@ private class MapWidget : Gtk.Bin {
CheckerboardItem item = m.view as CheckerboardItem;
- if (!did_adjust_view) {
- // if first item is in any way out of view, scroll to it
- Gtk.Adjustment vadj = page.get_vadjustment();
-
- if (!(get_adjustment_relation(vadj, item.allocation.y) == AdjustmentRelation.IN_RANGE
- && (get_adjustment_relation(vadj, item.allocation.y + item.allocation.height) ==
AdjustmentRelation.IN_RANGE))) {
-
- // scroll to see the new item
- int top = 0;
- if (item.allocation.y < vadj.get_value()) {
- top = item.allocation.y;
- top -= CheckerboardLayout.ROW_GUTTER_PADDING / 2;
- } else {
- top = item.allocation.y + item.allocation.height - (int) vadj.get_page_size();
- top += CheckerboardLayout.ROW_GUTTER_PADDING / 2;
- }
-
- vadj.set_value(top);
- }
+ if (!did_adjust_view && page is CheckerboardPage) {
+ (page as CheckerboardPage).scroll_to_item(item);
did_adjust_view = true;
}
item.brighten();
diff --git a/src/Page.vala b/src/Page.vala
index 666dbdf1..59cbfb8b 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -1384,6 +1384,26 @@ public abstract class CheckerboardPage : Page {
base.switching_from();
}
+
+ public void scroll_to_item(CheckerboardItem item) {
+ Gtk.Adjustment vadj = get_vadjustment();
+ if (!(get_adjustment_relation(vadj, item.allocation.y) == AdjustmentRelation.IN_RANGE
+ && (get_adjustment_relation(vadj, item.allocation.y + item.allocation.height) ==
AdjustmentRelation.IN_RANGE))) {
+
+ // scroll to see the new item
+ int top = 0;
+ if (item.allocation.y < vadj.get_value()) {
+ top = item.allocation.y;
+ top -= CheckerboardLayout.ROW_GUTTER_PADDING / 2;
+ } else {
+ top = item.allocation.y + item.allocation.height - (int) vadj.get_page_size();
+ top += CheckerboardLayout.ROW_GUTTER_PADDING / 2;
+ }
+
+ vadj.set_value(top);
+
+ }
+ }
public override void switched_to() {
layout.set_in_view(true);
@@ -1394,23 +1414,7 @@ public abstract class CheckerboardPage : Page {
CheckerboardItem? item = (CheckerboardItem?) get_view().get_selected_at(0);
// if item is in any way out of view, scroll to it
- Gtk.Adjustment vadj = get_vadjustment();
- if (!(get_adjustment_relation(vadj, item.allocation.y) == AdjustmentRelation.IN_RANGE
- && (get_adjustment_relation(vadj, item.allocation.y + item.allocation.height) ==
AdjustmentRelation.IN_RANGE))) {
-
- // scroll to see the new item
- int top = 0;
- if (item.allocation.y < vadj.get_value()) {
- top = item.allocation.y;
- top -= CheckerboardLayout.ROW_GUTTER_PADDING / 2;
- } else {
- top = item.allocation.y + item.allocation.height - (int) vadj.get_page_size();
- top += CheckerboardLayout.ROW_GUTTER_PADDING / 2;
- }
-
- vadj.set_value(top);
-
- }
+ scroll_to_item(item);
}
base.switched_to();
@@ -1891,24 +1895,7 @@ public abstract class CheckerboardPage : Page {
get_view().select_marked(marker);
}
layout.set_cursor(item);
-
- // if item is in any way out of view, scroll to it
- Gtk.Adjustment vadj = get_vadjustment();
- if (get_adjustment_relation(vadj, item.allocation.y) == AdjustmentRelation.IN_RANGE
- && (get_adjustment_relation(vadj, item.allocation.y + item.allocation.height) ==
AdjustmentRelation.IN_RANGE))
- return;
-
- // scroll to see the new item
- int top = 0;
- if (item.allocation.y < vadj.get_value()) {
- top = item.allocation.y;
- top -= CheckerboardLayout.ROW_GUTTER_PADDING / 2;
- } else {
- top = item.allocation.y + item.allocation.height - (int) vadj.get_page_size();
- top += CheckerboardLayout.ROW_GUTTER_PADDING / 2;
- }
-
- vadj.set_value(top);
+ scroll_to_item(item);
}
public void move_cursor(CompassPoint point) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]