Giter Site home page Giter Site logo

Comments (2)

scaramacai avatar scaramacai commented on June 2, 2024 1

I modified the progress bar code. Now it almost works, but I am not sure if the solution is the right one, because I have not studied AGAR's widget structure thoroughly. Also I still have some doubt that there may be ± 1 px problems.

I attach the diff so that you can take a look at it.

--- progress_bar.c.orig
+++ progress_bar.c
@@ -230,58 +230,56 @@
 static void
 Draw(void *_Nonnull obj)
 {
        AG_ProgressBar *pb = obj;
        AG_Rect rd = WIDGET(pb)->r;
        const int paddingLeft   = WIDGET(pb)->paddingLeft;
        const int paddingRight  = WIDGET(pb)->paddingRight;
        const int paddingTop    = WIDGET(pb)->paddingTop;
        const int paddingBottom = WIDGET(pb)->paddingBottom;
        int min, max, val;
 
        min = AG_GetInt(pb, "min");
        max = AG_GetInt(pb, "max");
        val = AG_GetInt(pb, "value");
        if (val < min) { val = min; }
        if (val > max) { val = max; }
 
        AG_DrawBoxSunk(pb, &rd, &WCOLOR(pb,BG_COLOR));
 
        if ((max - min) <= 0)
                return;
 
-       rd.x = paddingLeft;
-       rd.y = paddingTop;
+       rd.x = 0;
+       rd.y = 0;
 
        switch (pb->type) {
        case AG_PROGRESS_BAR_VERT:
-               rd.h -= (paddingTop + paddingBottom);
-               rd.y += rd.h - (val-min)*(rd.h)/(max-min) - 1;
-               rd.h = HEIGHT(pb) - paddingTop - rd.y + 1;
-               rd.w -= (paddingLeft + paddingRight);
+                rd.y += rd.h - (val-min)*(rd.h)/(max-min) - 1;
+                rd.h = HEIGHT(pb) - rd.y;
+               rd.w -= 1;
                break;
        case AG_PROGRESS_BAR_HORIZ:
        default:
-               rd.w = (val-min)*(rd.w - paddingLeft - paddingRight)/(max-min);
-               rd.h -= (paddingTop + paddingBottom);
+               rd.w = (val-min)*(rd.w - 1)/(max-min);
                break;
        }
        AG_DrawRect(pb, &rd, &WCOLOR(pb,SELECTION_COLOR));
 
        if (pb->flags & AG_PROGRESS_BAR_SHOW_PCT)
                DrawPercentText(pb);
 }
 
 AG_WidgetClass agProgressBarClass = {
        {
                "Agar(Widget:ProgressBar)",
                sizeof(AG_ProgressBar),
                { 1,0, AGC_PROGRESSBAR, 0xE032 },
                Init,
                NULL,           /* reset */
                Destroy,
                NULL,           /* load */
                NULL,           /* save */
                NULL            /* edit */
        },
        Draw,
        SizeRequest,

If you think I should submit a push request I will try to clone the repository and do it.

from libagar.

JulNadeauCA avatar JulNadeauCA commented on June 2, 2024

Looks good to me! Committed to: 1140aa6. Thank you very much!

from libagar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.