Merge lp:~cimi/overlay-scrollbar/align-thumb-position into lp:overlay-scrollbar

Proposed by Andrea Cimitan
Status: Merged
Approved by: Andrea Cimitan
Approved revision: 330
Merged at revision: 313
Proposed branch: lp:~cimi/overlay-scrollbar/align-thumb-position
Merge into: lp:overlay-scrollbar
Diff against target: 119 lines (+99/-6)
1 file modified
os/os-scrollbar.c (+99/-6)
To merge this branch: bzr merge lp:~cimi/overlay-scrollbar/align-thumb-position
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+79701@code.launchpad.net

Description of the change

Align the thumb to the pageup when you're revealing it at top, pagedown at bottom

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

The code looks fine, but it would be best in future revisions to start de-duplicating the code using inline functions. It would increase the maintainability of the code.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'os/os-scrollbar.c'
2--- os/os-scrollbar.c 2011-10-12 17:12:29 +0000
3+++ os/os-scrollbar.c 2011-10-18 15:02:32 +0000
4@@ -2182,16 +2182,109 @@
5 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
6 {
7 x = priv->thumb_all.x;
8- y = CLAMP (event_y - priv->slider.height / 2,
9- priv->thumb_all.y,
10- priv->thumb_all.y + priv->thumb_all.height - priv->slider.height);
11+
12+ if (priv->overlay.height > priv->slider.height)
13+ {
14+ /* Overlay (bar) is longer than the slider (thumb).
15+ * The thumb is locked within the overlay,
16+ * until the mouse is on the middle of page up or page down buttons. */
17+
18+ if (event_y < priv->thumb_all.y + priv->overlay.y + priv->slider.height / 4)
19+ {
20+ /* Align to page up. */
21+ y = event_y - priv->slider.height / 4;
22+ }
23+ else if (event_y > priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height / 4)
24+ {
25+ /* Align to page down. */
26+ y = event_y - priv->slider.height * 3 / 4;
27+ }
28+ else
29+ {
30+ /* Lock within the overlay. */
31+ y = CLAMP (event_y - priv->slider.height / 2,
32+ priv->thumb_all.y + priv->overlay.y,
33+ priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height);
34+ }
35+ }
36+ else
37+ {
38+ /* Slider (thumb) is longer than (or equal) the overlay (bar).
39+ * The thumb is locked to its natural position (priv->slider.y),
40+ * until the mouse is on the middle of page up or page down buttons. */
41+
42+ if (event_y < priv->thumb_all.y + priv->slider.y + priv->slider.height / 4)
43+ {
44+ /* Align to page up. */
45+ y = event_y - priv->slider.height / 4;
46+ }
47+ else if (event_y > priv->thumb_all.y + priv->slider.y + priv->slider.height - priv->slider.height / 4)
48+ {
49+ /* Align to page down. */
50+ y = event_y - priv->slider.height * 3 / 4;
51+ }
52+ else
53+ {
54+ /* Lock to its natural position. */
55+ y = priv->thumb_all.y + priv->slider.y;
56+ }
57+ }
58+ /* Restrict y within the thumb allocation. */
59+ y = CLAMP (y, priv->thumb_all.y, priv->thumb_all.y + priv->thumb_all.height - priv->slider.height);
60 }
61 else
62 {
63- x = CLAMP (event_x - priv->slider.width / 2,
64- priv->thumb_all.x,
65- priv->thumb_all.x + priv->thumb_all.width - priv->slider.width);
66 y = priv->thumb_all.y;
67+
68+ if (priv->overlay.width > priv->slider.width)
69+ {
70+ /* Overlay (bar) is longer than the slider (thumb).
71+ * The thumb is locked within the overlay,
72+ * until the mouse is on the middle of page up or page down buttons. */
73+
74+ if (event_x < priv->thumb_all.x + priv->overlay.x + priv->slider.width / 4)
75+ {
76+ /* Align to page up. */
77+ x = event_x - priv->slider.width / 4;
78+ }
79+ else if (event_x > priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width / 4)
80+ {
81+ /* Align to page down. */
82+ x = event_x - priv->slider.width * 3 / 4;
83+ }
84+ else
85+ {
86+ /* Lock within the overlay. */
87+ x = CLAMP (event_x - priv->slider.width / 2,
88+ priv->thumb_all.x + priv->overlay.x,
89+ priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width);
90+ }
91+
92+ }
93+ else
94+ {
95+ /* Slider (thumb) is longer than (or equal) the overlay (bar).
96+ * The thumb is locked to its natural position (priv->slider.x),
97+ * until the mouse is on the middle of page up or page down buttons. */
98+
99+ if (event_x < priv->thumb_all.x + priv->slider.x + priv->slider.width / 4)
100+ {
101+ /* Align to page up. */
102+ x = event_x - priv->slider.width / 4;
103+ }
104+ else if (event_x > priv->thumb_all.x + priv->slider.x + priv->slider.width - priv->slider.width / 4)
105+ {
106+ /* Align to page down. */
107+ x = event_x - priv->slider.width * 3 / 4;
108+ }
109+ else
110+ {
111+ /* Lock to its natural position. */
112+ x = priv->thumb_all.x + priv->slider.x;
113+ }
114+ }
115+ /* Restrict x within the thumb allocation. */
116+ x = CLAMP (x, priv->thumb_all.x, priv->thumb_all.x + priv->thumb_all.width - priv->slider.width);
117 }
118
119 move_thumb (scrollbar, x_pos + x, y_pos + y);

Subscribers

People subscribed via source and target branches