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
=== modified file 'os/os-scrollbar.c'
--- os/os-scrollbar.c 2011-10-12 17:12:29 +0000
+++ os/os-scrollbar.c 2011-10-18 15:02:32 +0000
@@ -2182,16 +2182,109 @@
2182 if (priv->orientation == GTK_ORIENTATION_VERTICAL)2182 if (priv->orientation == GTK_ORIENTATION_VERTICAL)
2183 {2183 {
2184 x = priv->thumb_all.x;2184 x = priv->thumb_all.x;
2185 y = CLAMP (event_y - priv->slider.height / 2,2185
2186 priv->thumb_all.y,2186 if (priv->overlay.height > priv->slider.height)
2187 priv->thumb_all.y + priv->thumb_all.height - priv->slider.height);2187 {
2188 /* Overlay (bar) is longer than the slider (thumb).
2189 * The thumb is locked within the overlay,
2190 * until the mouse is on the middle of page up or page down buttons. */
2191
2192 if (event_y < priv->thumb_all.y + priv->overlay.y + priv->slider.height / 4)
2193 {
2194 /* Align to page up. */
2195 y = event_y - priv->slider.height / 4;
2196 }
2197 else if (event_y > priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height / 4)
2198 {
2199 /* Align to page down. */
2200 y = event_y - priv->slider.height * 3 / 4;
2201 }
2202 else
2203 {
2204 /* Lock within the overlay. */
2205 y = CLAMP (event_y - priv->slider.height / 2,
2206 priv->thumb_all.y + priv->overlay.y,
2207 priv->thumb_all.y + priv->overlay.y + priv->overlay.height - priv->slider.height);
2208 }
2209 }
2210 else
2211 {
2212 /* Slider (thumb) is longer than (or equal) the overlay (bar).
2213 * The thumb is locked to its natural position (priv->slider.y),
2214 * until the mouse is on the middle of page up or page down buttons. */
2215
2216 if (event_y < priv->thumb_all.y + priv->slider.y + priv->slider.height / 4)
2217 {
2218 /* Align to page up. */
2219 y = event_y - priv->slider.height / 4;
2220 }
2221 else if (event_y > priv->thumb_all.y + priv->slider.y + priv->slider.height - priv->slider.height / 4)
2222 {
2223 /* Align to page down. */
2224 y = event_y - priv->slider.height * 3 / 4;
2225 }
2226 else
2227 {
2228 /* Lock to its natural position. */
2229 y = priv->thumb_all.y + priv->slider.y;
2230 }
2231 }
2232 /* Restrict y within the thumb allocation. */
2233 y = CLAMP (y, priv->thumb_all.y, priv->thumb_all.y + priv->thumb_all.height - priv->slider.height);
2188 }2234 }
2189 else2235 else
2190 {2236 {
2191 x = CLAMP (event_x - priv->slider.width / 2,
2192 priv->thumb_all.x,
2193 priv->thumb_all.x + priv->thumb_all.width - priv->slider.width);
2194 y = priv->thumb_all.y;2237 y = priv->thumb_all.y;
2238
2239 if (priv->overlay.width > priv->slider.width)
2240 {
2241 /* Overlay (bar) is longer than the slider (thumb).
2242 * The thumb is locked within the overlay,
2243 * until the mouse is on the middle of page up or page down buttons. */
2244
2245 if (event_x < priv->thumb_all.x + priv->overlay.x + priv->slider.width / 4)
2246 {
2247 /* Align to page up. */
2248 x = event_x - priv->slider.width / 4;
2249 }
2250 else if (event_x > priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width / 4)
2251 {
2252 /* Align to page down. */
2253 x = event_x - priv->slider.width * 3 / 4;
2254 }
2255 else
2256 {
2257 /* Lock within the overlay. */
2258 x = CLAMP (event_x - priv->slider.width / 2,
2259 priv->thumb_all.x + priv->overlay.x,
2260 priv->thumb_all.x + priv->overlay.x + priv->overlay.width - priv->slider.width);
2261 }
2262
2263 }
2264 else
2265 {
2266 /* Slider (thumb) is longer than (or equal) the overlay (bar).
2267 * The thumb is locked to its natural position (priv->slider.x),
2268 * until the mouse is on the middle of page up or page down buttons. */
2269
2270 if (event_x < priv->thumb_all.x + priv->slider.x + priv->slider.width / 4)
2271 {
2272 /* Align to page up. */
2273 x = event_x - priv->slider.width / 4;
2274 }
2275 else if (event_x > priv->thumb_all.x + priv->slider.x + priv->slider.width - priv->slider.width / 4)
2276 {
2277 /* Align to page down. */
2278 x = event_x - priv->slider.width * 3 / 4;
2279 }
2280 else
2281 {
2282 /* Lock to its natural position. */
2283 x = priv->thumb_all.x + priv->slider.x;
2284 }
2285 }
2286 /* Restrict x within the thumb allocation. */
2287 x = CLAMP (x, priv->thumb_all.x, priv->thumb_all.x + priv->thumb_all.width - priv->slider.width);
2195 }2288 }
21962289
2197 move_thumb (scrollbar, x_pos + x, y_pos + y);2290 move_thumb (scrollbar, x_pos + x, y_pos + y);

Subscribers

People subscribed via source and target branches