diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index eff18f39..635bf3e6 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -258,10 +258,10 @@ iBool isFinished_SmoothScroll(const iSmoothScroll *d) { | |||
258 | return isFinished_Anim(&d->pos); | 258 | return isFinished_Anim(&d->pos); |
259 | } | 259 | } |
260 | 260 | ||
261 | void move_SmoothScroll(iSmoothScroll *d, int offset, uint32_t duration) { | 261 | void moveSpan_SmoothScroll(iSmoothScroll *d, int offset, uint32_t span) { |
262 | #if !defined (iPlatformMobile) | 262 | #if !defined (iPlatformMobile) |
263 | if (!prefs_App()->smoothScrolling) { | 263 | if (!prefs_App()->smoothScrolling) { |
264 | duration = 0; /* always instant */ | 264 | span = 0; /* always instant */ |
265 | } | 265 | } |
266 | #endif | 266 | #endif |
267 | int destY = targetValue_Anim(&d->pos) + offset; | 267 | int destY = targetValue_Anim(&d->pos) + offset; |
@@ -276,8 +276,8 @@ void move_SmoothScroll(iSmoothScroll *d, int offset, uint32_t duration) { | |||
276 | else { | 276 | else { |
277 | destY = 0; | 277 | destY = 0; |
278 | } | 278 | } |
279 | if (duration) { | 279 | if (span) { |
280 | setValueEased_Anim(&d->pos, destY, duration); | 280 | setValueEased_Anim(&d->pos, destY, span); |
281 | } | 281 | } |
282 | else { | 282 | else { |
283 | setValue_Anim(&d->pos, destY, 0); | 283 | setValue_Anim(&d->pos, destY, 0); |
@@ -286,8 +286,8 @@ void move_SmoothScroll(iSmoothScroll *d, int offset, uint32_t duration) { | |||
286 | const int osDelta = overscroll_SmoothScroll_(d); | 286 | const int osDelta = overscroll_SmoothScroll_(d); |
287 | if (osDelta) { | 287 | if (osDelta) { |
288 | const float remaining = stopWidgetMomentum_Touch(d->widget); | 288 | const float remaining = stopWidgetMomentum_Touch(d->widget); |
289 | duration = iMini(1000, 50 * sqrt(remaining / gap_UI)); | 289 | span = iMini(1000, 50 * sqrt(remaining / gap_UI)); |
290 | setValue_Anim(&d->pos, osDelta < 0 ? 0 : d->max, duration); | 290 | setValue_Anim(&d->pos, osDelta < 0 ? 0 : d->max, span); |
291 | d->pos.flags = bounce_AnimFlag | easeOut_AnimFlag | softer_AnimFlag; | 291 | d->pos.flags = bounce_AnimFlag | easeOut_AnimFlag | softer_AnimFlag; |
292 | // printf("remaining: %f dur: %d\n", remaining, duration); | 292 | // printf("remaining: %f dur: %d\n", remaining, duration); |
293 | d->pos.bounce = (osDelta < 0 ? -1 : 1) * | 293 | d->pos.bounce = (osDelta < 0 ? -1 : 1) * |
@@ -295,15 +295,19 @@ void move_SmoothScroll(iSmoothScroll *d, int offset, uint32_t duration) { | |||
295 | } | 295 | } |
296 | } | 296 | } |
297 | if (d->notify) { | 297 | if (d->notify) { |
298 | d->notify(d->widget, offset, duration); | 298 | d->notify(d->widget, offset, span); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | 301 | ||
302 | void move_SmoothScroll(iSmoothScroll *d, int offset) { | ||
303 | moveSpan_SmoothScroll(d, offset, 0 /* instantly */); | ||
304 | } | ||
305 | |||
302 | iBool processEvent_SmoothScroll(iSmoothScroll *d, const SDL_Event *ev) { | 306 | iBool processEvent_SmoothScroll(iSmoothScroll *d, const SDL_Event *ev) { |
303 | if (ev->type == SDL_USEREVENT && ev->user.code == widgetTouchEnds_UserEventCode) { | 307 | if (ev->type == SDL_USEREVENT && ev->user.code == widgetTouchEnds_UserEventCode) { |
304 | const int osDelta = overscroll_SmoothScroll_(d); | 308 | const int osDelta = overscroll_SmoothScroll_(d); |
305 | if (osDelta) { | 309 | if (osDelta) { |
306 | move_SmoothScroll(d, -osDelta, 100 * sqrt(iAbs(osDelta) / gap_UI)); | 310 | moveSpan_SmoothScroll(d, -osDelta, 100 * sqrt(iAbs(osDelta) / gap_UI)); |
307 | d->pos.flags = easeOut_AnimFlag | muchSofter_AnimFlag; | 311 | d->pos.flags = easeOut_AnimFlag | muchSofter_AnimFlag; |
308 | } | 312 | } |
309 | return iTrue; | 313 | return iTrue; |
@@ -1345,7 +1349,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { | |||
1345 | updateSideOpacity_DocumentWidget_(d, iFalse); | 1349 | updateSideOpacity_DocumentWidget_(d, iFalse); |
1346 | d->drawBufs->flags |= updateSideBuf_DrawBufsFlag; | 1350 | d->drawBufs->flags |= updateSideBuf_DrawBufsFlag; |
1347 | updateVisible_DocumentWidget_(d); | 1351 | updateVisible_DocumentWidget_(d); |
1348 | move_SmoothScroll(&d->scrollY, 0, 0); /* clamp position to new max */ | 1352 | moveSpan_SmoothScroll(&d->scrollY, 0, 0); /* clamp position to new max */ |
1349 | cacheDocumentGlyphs_DocumentWidget_(d); | 1353 | cacheDocumentGlyphs_DocumentWidget_(d); |
1350 | postCommandf_App("document.changed doc:%p url:%s", d, cstr_String(d->mod.url)); | 1354 | postCommandf_App("document.changed doc:%p url:%s", d, cstr_String(d->mod.url)); |
1351 | return iTrue; | 1355 | return iTrue; |
@@ -1394,29 +1398,16 @@ static void scrollBegan_DocumentWidget_(iAnyObject *any, int offset, uint32_t du | |||
1394 | } | 1398 | } |
1395 | } | 1399 | } |
1396 | 1400 | ||
1401 | static void clampScroll_DocumentWidget_(iDocumentWidget *d) { | ||
1402 | move_SmoothScroll(&d->scrollY, 0); | ||
1403 | } | ||
1404 | |||
1405 | static void immediateScroll_DocumentWidget_(iDocumentWidget *d, int offset) { | ||
1406 | move_SmoothScroll(&d->scrollY, offset); | ||
1407 | } | ||
1408 | |||
1397 | static void smoothScroll_DocumentWidget_(iDocumentWidget *d, int offset, int duration) { | 1409 | static void smoothScroll_DocumentWidget_(iDocumentWidget *d, int offset, int duration) { |
1398 | // /* Get rid of link numbers when scrolling. */ | 1410 | moveSpan_SmoothScroll(&d->scrollY, offset, duration); |
1399 | // if (offset && d->flags & showLinkNumbers_DocumentWidgetFlag) { | ||
1400 | // setLinkNumberMode_DocumentWidget_(d, iFalse); | ||
1401 | // invalidateVisibleLinks_DocumentWidget_(d); | ||
1402 | // } | ||
1403 | // /* Show and hide toolbar on scroll. */ | ||
1404 | // if (deviceType_App() == phone_AppDeviceType) { | ||
1405 | // if (prefs_App()->hideToolbarOnScroll && iAbs(offset) > 5) { | ||
1406 | // showToolbars_Window(get_Window(), offset < 0); | ||
1407 | // } | ||
1408 | // } | ||
1409 | move_SmoothScroll(&d->scrollY, offset, duration); | ||
1410 | // updateVisible_DocumentWidget_(d); | ||
1411 | // refresh_Widget(as_Widget(d)); | ||
1412 | // if (duration > 0) { | ||
1413 | // iChangeFlags(d->flags, noHoverWhileScrolling_DocumentWidgetFlag, iTrue); | ||
1414 | // addTicker_App(refreshWhileScrolling_DocumentWidget_, d); | ||
1415 | // } | ||
1416 | } | ||
1417 | |||
1418 | static void scroll_DocumentWidget_(iDocumentWidget *d, int offset) { | ||
1419 | smoothScroll_DocumentWidget_(d, offset, 0 /* instantly */); | ||
1420 | } | 1411 | } |
1421 | 1412 | ||
1422 | static void scrollTo_DocumentWidget_(iDocumentWidget *d, int documentY, iBool centered) { | 1413 | static void scrollTo_DocumentWidget_(iDocumentWidget *d, int documentY, iBool centered) { |
@@ -1426,7 +1417,7 @@ static void scrollTo_DocumentWidget_(iDocumentWidget *d, int documentY, iBool ce | |||
1426 | init_Anim(&d->scrollY.pos, | 1417 | init_Anim(&d->scrollY.pos, |
1427 | documentY - (centered ? documentBounds_DocumentWidget_(d).size.y / 2 | 1418 | documentY - (centered ? documentBounds_DocumentWidget_(d).size.y / 2 |
1428 | : lineHeight_Text(paragraph_FontId))); | 1419 | : lineHeight_Text(paragraph_FontId))); |
1429 | scroll_DocumentWidget_(d, 0); /* clamp it */ | 1420 | clampScroll_DocumentWidget_(d); |
1430 | } | 1421 | } |
1431 | 1422 | ||
1432 | static void scrollToHeading_DocumentWidget_(iDocumentWidget *d, const char *heading) { | 1423 | static void scrollToHeading_DocumentWidget_(iDocumentWidget *d, const char *heading) { |
@@ -1494,7 +1485,7 @@ static void togglePreFold_DocumentWidget_(iDocumentWidget *d, uint16_t preId) { | |||
1494 | d->selectMark = iNullRange; | 1485 | d->selectMark = iNullRange; |
1495 | foldPre_GmDocument(d->doc, preId); | 1486 | foldPre_GmDocument(d->doc, preId); |
1496 | redoLayout_GmDocument(d->doc); | 1487 | redoLayout_GmDocument(d->doc); |
1497 | scroll_DocumentWidget_(d, 0); | 1488 | clampScroll_DocumentWidget_(d); |
1498 | updateHover_DocumentWidget_(d, mouseCoord_Window(get_Window())); | 1489 | updateHover_DocumentWidget_(d, mouseCoord_Window(get_Window())); |
1499 | invalidate_DocumentWidget_(d); | 1490 | invalidate_DocumentWidget_(d); |
1500 | refresh_Widget(as_Widget(d)); | 1491 | refresh_Widget(as_Widget(d)); |
@@ -2357,7 +2348,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2357 | else if (equal_Command(cmd, "scroll.top") && document_App() == d) { | 2348 | else if (equal_Command(cmd, "scroll.top") && document_App() == d) { |
2358 | init_Anim(&d->scrollY.pos, 0); | 2349 | init_Anim(&d->scrollY.pos, 0); |
2359 | invalidate_VisBuf(d->visBuf); | 2350 | invalidate_VisBuf(d->visBuf); |
2360 | scroll_DocumentWidget_(d, 0); | 2351 | clampScroll_DocumentWidget_(d); |
2361 | updateVisible_DocumentWidget_(d); | 2352 | updateVisible_DocumentWidget_(d); |
2362 | refresh_Widget(w); | 2353 | refresh_Widget(w); |
2363 | return iTrue; | 2354 | return iTrue; |
@@ -2365,7 +2356,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2365 | else if (equal_Command(cmd, "scroll.bottom") && document_App() == d) { | 2356 | else if (equal_Command(cmd, "scroll.bottom") && document_App() == d) { |
2366 | init_Anim(&d->scrollY.pos, d->scrollY.max); | 2357 | init_Anim(&d->scrollY.pos, d->scrollY.max); |
2367 | invalidate_VisBuf(d->visBuf); | 2358 | invalidate_VisBuf(d->visBuf); |
2368 | scroll_DocumentWidget_(d, 0); | 2359 | clampScroll_DocumentWidget_(d); |
2369 | updateVisible_DocumentWidget_(d); | 2360 | updateVisible_DocumentWidget_(d); |
2370 | refresh_Widget(w); | 2361 | refresh_Widget(w); |
2371 | return iTrue; | 2362 | return iTrue; |
@@ -2800,7 +2791,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
2800 | if (isPerPixel_MouseWheelEvent(&ev->wheel)) { | 2791 | if (isPerPixel_MouseWheelEvent(&ev->wheel)) { |
2801 | const iInt2 wheel = init_I2(ev->wheel.x, ev->wheel.y); | 2792 | const iInt2 wheel = init_I2(ev->wheel.x, ev->wheel.y); |
2802 | stop_Anim(&d->scrollY.pos); | 2793 | stop_Anim(&d->scrollY.pos); |
2803 | scroll_DocumentWidget_(d, -wheel.y); | 2794 | immediateScroll_DocumentWidget_(d, -wheel.y); |
2804 | scrollWideBlock_DocumentWidget_(d, mouseCoord, -wheel.x, 0); | 2795 | scrollWideBlock_DocumentWidget_(d, mouseCoord, -wheel.x, 0); |
2805 | } | 2796 | } |
2806 | else { | 2797 | else { |
@@ -3195,7 +3186,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
3195 | } | 3186 | } |
3196 | redoLayout_GmDocument(d->doc); | 3187 | redoLayout_GmDocument(d->doc); |
3197 | d->hoverLink = NULL; | 3188 | d->hoverLink = NULL; |
3198 | scroll_DocumentWidget_(d, 0); | 3189 | clampScroll_DocumentWidget_(d); |
3199 | updateVisible_DocumentWidget_(d); | 3190 | updateVisible_DocumentWidget_(d); |
3200 | invalidate_DocumentWidget_(d); | 3191 | invalidate_DocumentWidget_(d); |
3201 | refresh_Widget(w); | 3192 | refresh_Widget(w); |