Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow circler progress to draw arc #239

Merged
merged 6 commits into from
Jan 8, 2024
Merged

allow circler progress to draw arc #239

merged 6 commits into from
Jan 8, 2024

Conversation

AhmedSaadi0
Copy link
Contributor

Allow drawing arc instead of a full circle by defining startDraw, endDraw

example

const progress = Widget.CircularProgress({
    className: "desktop-cpu-circle",
    child: Widget.Label({
        className: "desktop-cpu-circle-icon",
        label: ""
    }),
    startDraw: 0.25,
    endDraw: 0.5,
}).poll(1000, self => {
    Utils.execAsync(`/home/${Utils.USER}/.config/ags/scripts/cpu.sh`)
        .then(val => {
            progress.value = val / 100;
        }).catch(print);
});

2024-01-04-035744_hyprshot

if used without startDraw, endDraw it will draw a normal circle as it used to

@kotontrion
Copy link
Contributor

+1
But why differentiate between arc and full circle? Instead of adding start-draw and end-draw, I think it would be better to add end-at, which defaults to start-at + 2* pi to get the full circle by default.

@AhmedSaadi0
Copy link
Contributor Author

Sounds great. I changed it

const cpu = Widget.CircularProgress({
    className: "desktop-core-6-circle",
    startAt: 0.75,
    endAt: 1,
}).poll(3 * 1000, self => {
    Utils.execAsync(`/home/${Utils.USER}/.config/ags/scripts/cpu.sh`)
        .then(val => {
            const data = JSON.parse(val);
            cpu.value = data[6] / 100;
        }).catch(print);
});

@Aylur
Copy link
Owner

Aylur commented Jan 6, 2024

Sounds useful, but why not just halve the value?

@AhmedSaadi0
Copy link
Contributor Author

To be able to make something like this

2024-01-05-165047_hyprshot

@Aylur
Copy link
Owner

Aylur commented Jan 7, 2024

inverted doesn't work as expected with this
I don't know much cairo, but maybe doing 1 - value would work?

@AhmedSaadi0
Copy link
Contributor Author

I changed it
now it works but the logic changed
0.25 now in inverted starts inverted which means it will start from the top not the bottom
and there is no need to invert the css styling it will draw as normal

2024-01-08-000244_hyprshot
2024-01-08-000326_hyprshot

@Aylur
Copy link
Owner

Aylur commented Jan 8, 2024

That is not how inverted is supposed to work.
Let's say our value is 0.6, then the bar should be filled 6/10 and 4/10 empty

███░░

With inverted, the bar should be empty 6/10 and filled 4/10

░░░██

@kotontrion
Copy link
Contributor

kotontrion commented Jan 8, 2024

Let's say our value is 0.6, then the bar should be filled 6/10 and 4/10 empty
With inverted, the bar should be empty 6/10 and filled 4/10

This is not how it is supposed to work.

From the gtk docs:

Ranges normally move from lower to higher values as the slider moves from top to bottom or left to right. Inverted ranges have higher values at the top or on the right rather than on the bottom or left.

so a value of 0.6 should behave like that:
███░░ for inverted false
░░███ for inverted true
and you can easily confirm this by creating two scales: (the bottom is inverted, both have a value of 0.6)

2024-01-08T14:49:08,050053579+01:00

That said, the currently implemented behavior should be correct regarding the fill of the progress bar, but not for the placement. changing the value of inverted should not change how it is placed. (I did not try this myself, I'm just going off of the screenshots posted here).

Edit:
Again, didn't try this but this might be a way to solve this:

if (this.inverted) {
    startProgress = calculatedEndAngle - rangedValue;
    endProgress = calculatedEndAngle;
} else {
    startProgress = calculatedStartAngle;
    endProgress = calculatedStartAngle + rangedValue;
}

the background draw is not changed by setting inverted.

@Aylur
Copy link
Owner

Aylur commented Jan 8, 2024

███░░ for inverted false
░░███ for inverted true

yeah, you are right, mb

@AhmedSaadi0
Copy link
Contributor Author

I don't know; I felt that as a circle, it should also adjust the starting position accordingly. Anyway, I made the changes as @kotontrion suggested.

inverted = true

2024-01-08-215901_hyprshot

inverted = false

2024-01-08-215920_hyprshot

@Aylur Aylur merged commit a8c34c4 into Aylur:main Jan 8, 2024
gorsbart pushed a commit to gorsbart/ags that referenced this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants