From 4108d5b0154775e2bf2c3af5003cf840675d789a Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 22 May 2021 08:19:00 +0300 Subject: DocumentWidget: Working on footer button positioning --- src/ui/documentwidget.c | 14 +++++++++++--- src/ui/widget.c | 4 ++++ src/ui/widget.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index e13f8da9..b6f9298c 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -503,7 +503,7 @@ static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { rect.size.y -= margin; } if (d->flags & centerVertically_DocumentWidgetFlag) { - const iInt2 docSize = size_GmDocument(d->doc); + const iInt2 docSize = addY_I2(size_GmDocument(d->doc), height_Widget(d->footerButtons)); if (docSize.y < rect.size.y) { /* Center vertically if short. There is one empty paragraph line's worth of margin between the banner and the page contents. */ @@ -583,7 +583,8 @@ static float normScrollPos_DocumentWidget_(const iDocumentWidget *d) { static int scrollMax_DocumentWidget_(const iDocumentWidget *d) { const iWidget *w = constAs_Widget(d); int sm = size_GmDocument(d->doc).y - height_Rect(bounds_Widget(w)) + - (hasSiteBanner_GmDocument(d->doc) ? 1 : 2) * d->pageMargin * gap_UI; + (hasSiteBanner_GmDocument(d->doc) ? 1 : 2) * d->pageMargin * gap_UI + + height_Widget(d->footerButtons); if (d->phoneToolbar) { sm += size_Root(w->root).y - top_Rect(boundsWithoutVisualOffset_Widget(d->phoneToolbar)); @@ -1040,10 +1041,12 @@ static void makeFooterButtons_DocumentWidget_(iDocumentWidget *d, const iMenuIte return; } d->footerButtons = new_Widget(); + d->footerButtons->animOffsetRef = &d->scrollY.pos; setFlags_Widget(d->footerButtons, unhittable_WidgetFlag | arrangeVertical_WidgetFlag | resizeWidthOfChildren_WidgetFlag | arrangeHeight_WidgetFlag | - fixedPosition_WidgetFlag | resizeToParentWidth_WidgetFlag, + fixedPosition_WidgetFlag | resizeToParentWidth_WidgetFlag | + moveToParentBottomEdge_WidgetFlag, iTrue); setBackgroundColor_Widget(d->footerButtons, tmBannerBackground_ColorId); const iRect bounds = bounds_Widget(w); @@ -1061,6 +1064,7 @@ static void makeFooterButtons_DocumentWidget_(iDocumentWidget *d, const iMenuIte } addChild_Widget(as_Widget(d), iClob(d->footerButtons)); arrange_Widget(d->footerButtons); + arrange_Widget(w); } static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode code, @@ -1440,6 +1444,8 @@ static void updateFromCachedResponse_DocumentWidget_(iDocumentWidget *d, float n delete_Gempub(d->sourceGempub); d->sourceGempub = NULL; reset_GmDocument(d->doc); + destroy_Widget(d->footerButtons); + d->footerButtons = NULL; resetWideRuns_DocumentWidget_(d); d->state = fetching_RequestState; /* Do the fetch. */ { @@ -1718,6 +1724,8 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) { reset_GmDocument(d->doc); /* new content incoming */ delete_Gempub(d->sourceGempub); d->sourceGempub = NULL; + destroy_Widget(d->footerButtons); + d->footerButtons = NULL; resetWideRuns_DocumentWidget_(d); updateDocument_DocumentWidget_(d, resp, iTrue); break; diff --git a/src/ui/widget.c b/src/ui/widget.c index 5502cb8e..8d9c6f3b 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -59,6 +59,7 @@ void init_Widget(iWidget *d) { d->minSize = zero_I2(); d->sizeRef = NULL; d->offsetRef = NULL; + d->animOffsetRef = NULL; d->bgColor = none_ColorId; d->frameColor = none_ColorId; init_Anim(&d->visualOffset, 0.0f); @@ -769,6 +770,9 @@ static void applyVisualOffset_Widget_(const iWidget *d, iInt2 *pos) { pos->y += off; } } + if (d->animOffsetRef) { + pos->y -= value_Anim(d->animOffsetRef); + } if (d->flags & refChildrenOffset_WidgetFlag) { iConstForEach(ObjectList, i, children_Widget(d->offsetRef)) { const iWidget *child = i.object; diff --git a/src/ui/widget.h b/src/ui/widget.h index 79d45f23..8de62b7a 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -139,6 +139,7 @@ struct Impl_Widget { iInt2 minSize; iWidget * sizeRef; iWidget * offsetRef; + const iAnim *animOffsetRef; int padding[4]; /* left, top, right, bottom */ iAnim visualOffset; int bgColor; -- cgit v1.2.3