+
+static int __obj_scroll_xy(int* position, int move, int thumb, int track, int content_out)
+{
+ int range = track - thumb;
+ int min = thumb / 2;
+ int max = track - min;
+
+ if (*position < min)
+ *position = min;
+ if (*position > max)
+ *position = max;
+
+ if (move < min - *position)
+ move = min - *position;
+ if (move > max - *position)
+ move = max - *position;
+
+ assert(move >= -range && move <= range);
+
+ *position += move;
+
+ int diff = -(*position - min) * content_out / range;
+ return diff;
+}
+
+int abc_obj_scroll_y(abc_obj_t* obj, int thumb, int track, int move)
+{
+ int content_out = obj->content_h - obj->h;
+
+ return __obj_scroll_xy(&obj->scroll_y, move, thumb, track, content_out);
+}
+
+int abc_obj_scroll_x(abc_obj_t* obj, int thumb, int track, int move)
+{
+ int content_out = obj->content_w - obj->w;
+
+ return __obj_scroll_xy(&obj->scroll_x, move, thumb, track, content_out);
+}