From f314b56da42e1ead200e2373e9b214f77290d03b Mon Sep 17 00:00:00 2001 From: physick Date: Sun, 12 Jul 2026 13:08:33 +0500 Subject: fun popup animation --- src/scenes/resultView.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'src/scenes/resultView.c') diff --git a/src/scenes/resultView.c b/src/scenes/resultView.c index 9985319..b433bd0 100644 --- a/src/scenes/resultView.c +++ b/src/scenes/resultView.c @@ -6,37 +6,56 @@ #include "../ui_elements/UI.h" #include "../resources/resources.h" -static const int PADDING = 10; +static const int PADDING = 20; static const int BORDER = 2; +static const int SCROLL_SPEED = 10; typedef struct { char *value; int scroll; + /// For the fun popping up effect + float scroll_up; + bool isClosing; } ResultViewData; -Rectangle GetResultViewBodyRect() { +Rectangle GetResultViewBodyRect(float scroll_up) { int HeaderOffset = PADDING * 2; + int height = GetScreenHeight(); Rectangle outp = { .x = PADDING, - .y = HeaderOffset, + .y = HeaderOffset + (height * scroll_up), .width = GetScreenWidth() - PADDING * 2, - .height = GetScreenHeight() - HeaderOffset - PADDING * 3, + .height = height - HeaderOffset - PADDING * 3, }; + return outp; } bool updateResultView(void *self) { - if (IsKeyDown(KEY_ESCAPE)) { - DeleteSceneFromStack(); + ResultViewData *data = ((Scene *)self)->data; + + if (data->isClosing) { + data->scroll_up += SCROLL_SPEED * GetFrameTime(); + if (data->scroll_up > 1) DeleteSceneFromStack(); return true; } + + if (data->scroll_up != 0) { + data->scroll_up -= SCROLL_SPEED * GetFrameTime(); + if (data->scroll_up < 0) data->scroll_up = 0; + } + + if (IsKeyPressed(KEY_ESCAPE)) { + data->isClosing = true; + } + return true; } bool drawResultView(void *self) { ResultViewData *data = ((Scene *)self)->data; - DrawBackground(); - Rectangle body = GetResultViewBodyRect(); + // DrawBackground(); + Rectangle body = GetResultViewBodyRect(data->scroll_up); DrawRecBordered(body, WHITE, COLORSCHEME_ORANGE, BORDER); DrawTextInRec(body, data->value, GetMainFont(), 20, COLORSCHEME_BROWN, 3, &data->scroll); @@ -54,6 +73,7 @@ Scene *CreateResultView(char *result) { outp->Draw = drawResultView; outp->Update = updateResultView; outp->Deint = deinitResultView; + outp->IsTransparent = true; ResultViewData *data = malloc(sizeof(ResultViewData)); if (data == NULL) { @@ -62,6 +82,8 @@ Scene *CreateResultView(char *result) { } data->value = result; data->scroll = 0; + data->scroll_up = 1; + data->isClosing = false; outp->data = data; return outp; -- cgit v1.3