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

refactor: button component #1318

Merged
merged 20 commits into from
Jul 6, 2024
Merged

refactor: button component #1318

merged 20 commits into from
Jul 6, 2024

Conversation

afonsojramos
Copy link
Member

@afonsojramos afonsojramos commented Jun 28, 2024

This PR now aims to refactor the button component to make it more modular and reusable.

Work towards #1312.

image image

Let me know what do you think! 🧐

@setchy
Copy link
Member

setchy commented Jun 28, 2024

Looks really nice @afonsojramos - just played around with it locally.

A few small suggestions

  • should the labels include a % suffix?
  • the 75% | seems to have an off-by-one-pixel.

Really good stuff!

@setchy
Copy link
Member

setchy commented Jun 28, 2024

Was also just thinking of what this might look like using our existing RadioGroup component (used by Theme and Group By)

@setchy setchy changed the title feat: slider component feat: zoom slider component Jun 30, 2024
@afonsojramos
Copy link
Member Author

Was also just thinking of what this might look like using our existing RadioGroup component (used by Theme and Group By)

Unless that radio button is 5 buttons wide (which looks bad imo 😬) I don't see it as being a good alternative here.

should the labels include a % suffix?

That's fair, I'll add that!

the 75% | seems to have an off-by-one-pixel.

🤔 I'll check

@afonsojramos
Copy link
Member Author

image

Should be good now @setchy

@afonsojramos
Copy link
Member Author

@adufr does this serve your goals? Or do you need extra zoom to either side?

@setchy
Copy link
Member

setchy commented Jul 1, 2024

Should be good now @setchy

Looks great @afonsojramos, thank you!

What's your thoughts on if the slider should reflect the manually set zoom level via Cmd + - or Cmd + =?

@afonsojramos
Copy link
Member Author

What's your thoughts on if the slider should reflect the manually set zoom level via Cmd + - or Cmd + =?

It already does, just not "live" because the zoom doesn't trigger a rerender of react.

@afonsojramos
Copy link
Member Author

Managed to find a way to do it 🤓

@afonsojramos
Copy link
Member Author

Adds a bit of extra code though

image

@afonsojramos
Copy link
Member Author

image

Potential issue is the fact that CMD+ and CMD- do jumps in 50 points increments, so I've widened the range to make it more accommodating of these jumps. Thoughts?

@adufr
Copy link
Contributor

adufr commented Jul 1, 2024

Just checked, I really like how the control looks and feels, but I'm used to unzoom even more than the 0% setting 😅
(I just counted and I press Cmd - 3 times after hitting the 0%

Also, the setting doesn't seem to be preserved across restarts..?

@adufr
Copy link
Contributor

adufr commented Jul 1, 2024

Also, a while ago I introduced this related change: #1035

I'll let you check but it might not be required anymore, idk

@afonsojramos
Copy link
Member Author

Also, the setting doesn't seem to be preserved across restarts..?

@setchy @adufr I've been trying to set that up (even with the settings, with no success), but considering that that is supposed to be working, let's just say that it is a bug to be fixed separately.

I just counted and I press Cmd - 3 times after hitting the 0%

Regarding this, I'll try to adjust the scale to meet that

@setchy
Copy link
Member

setchy commented Jul 1, 2024

Also, the setting doesn't seem to be preserved across restarts..?

@setchy @adufr I've been trying to set that up (even with the settings, with no success), but considering that that is supposed to be working, let's just say that it is a bug to be fixed separately.

I'm away from my computer ATM, which check later, but I suspect you may need to add special handling when the settings are first loaded after opening, like we do for the "open on startup" setting.

@afonsojramos
Copy link
Member Author

afonsojramos commented Jul 1, 2024

Implemented a 1.85 multiplier so this should simplify the calculations and reach your zoom level @adufr.

PS: If you're asking why a 1.85 multiplier and not the 2... Because a 2x multiplier would make the 150% go out of bound a bit in the 150% zoom.

Edit: Nevermind, I want the 2x multiplier, so I reduced the max zoom to 120%. I doubt anyone is going to zoom in.

@setchy
Copy link
Member

setchy commented Jul 2, 2024

You made me think? Should we only allow zoom out?

@setchy
Copy link
Member

setchy commented Jul 2, 2024

I noticed some odd slider behavior under the following conditions:

  • click + hold the slider and move left or right. seems to glitch a fair bit for me.
  • clicking on the sliders uses the defined increments, while using the Cmd + / Cmd - hotkeys moves in different increments, which means you can get out of sync.

@adufr
Copy link
Contributor

adufr commented Jul 2, 2024

The zoom out now meets my needs 👍
But yeah I don't really see any use-case where zooming-in would be useful

click + hold the slider and move left or right. seems to glitch a fair bit for me.

It glitches because it's resizing instantaneously so the mouse gets out of the slider 😅

clicking on the sliders uses the defined increments, while using the Cmd + / Cmd - hotkeys moves in different increments, which means you can get out of sync

Well, it's visually annoying but I deem it acceptable

but I suspect you may need to add special handling when the settings are first loaded after opening, like we do for the "open on startup" setting

Yup that's why I pointed the PR #1035, I think the following line needs to be adjusted:

// Force the window to retrieve its previous zoom factor
mb.window.webContents.setZoomFactor(mb.window.webContents.getZoomFactor());

@afonsojramos
Copy link
Member Author

click + hold the slider and move left or right. seems to glitch a fair bit for me.

@setchy I fixed this by making the step smaller, which was more work than expected, wasted a couple of hours on this 💀 Hope you like it more like this 🔫 This does mean that keyboard navigation now only jumps steps of 1, BUT you can just press for longer I suppose, it isn't too bad.

means you can get out of sync.

It also solves this I suppose ✅

@setchy
Copy link
Member

setchy commented Jul 2, 2024

Appreciate the time spent @afonsojramos. 🙏

I hope this is user error on my part, but, I cannot get the zoom settings to load on app restart... Sometimes it works, but shows the zoom at 100% in the UI, other times it doesnt set the zoom level at all... I was also able to get the zoom out of sync quit easily with the 1% increments.

What if to simplify the whole impl it was:

  • use only fixed zoom increments: match those used in Chrome (100%, 90%, 80%, 75%, 66%, 50%, 33%, 25%)
  • fix the slider to these increments, or, use a different input component (ie: dropdow)
  • prevent zoom above 100% or below 25%
  • reliably load the zoom level on app start

Alternatively, what if we:

  • had a Zoom label in Appearance Settings
  • it had a simple zoom in, zoom out, reset zoom button combo
  • displayed the current zoom level as a read only value
  • had a tooltip explaining how power users can use hotkeys to perform the same action
  • this is then very similar to how Chrome managed user zoom

@afonsojramos
Copy link
Member Author

I cannot get the zoom settings to load on app restart

So, is this currently working? Because I can't get it to work outside of this PR either, so it feels like out of scope for the pr itself, as it is supposedly working (just not something that I had tested before)

I was also able to get the zoom out of sync quit easily with the 1% increments

Do you mean with the mouse? That's okay I'd say!

@afonsojramos
Copy link
Member Author

Alternatively, what if we:

  • had a Zoom label in Appearance Settings
  • it had a simple zoom in, zoom out, reset zoom button combo
  • displayed the current zoom level as a read only value
  • had a tooltip explaining how power users can use hotkeys to perform the same action
  • this is then very similar to how Chrome managed user zoom

To be honest I like this approach, but am sad to trash it all 😓

@setchy
Copy link
Member

setchy commented Jul 2, 2024

Alternatively, what if we:

  • had a Zoom label in Appearance Settings
  • it had a simple zoom in, zoom out, reset zoom button combo
  • displayed the current zoom level as a read only value
  • had a tooltip explaining how power users can use hotkeys to perform the same action
  • this is then very similar to how Chrome managed user zoom

To be honest I like this approach, but am sad to trash it all 😓

I'm right there with you. The life of a developer 🥹

@afonsojramos afonsojramos changed the title feat: zoom slider component refactor: button component Jul 5, 2024
@afonsojramos
Copy link
Member Author

@setchy updated this PR to be a refactor of the button component. Will do a stacked PR to add in the controls for the zoom.

@afonsojramos afonsojramos mentioned this pull request Jul 5, 2024
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
src/components/buttons/Button.tsx Show resolved Hide resolved
src/components/buttons/Button.tsx Show resolved Hide resolved
@setchy setchy added the refactor Refactoring of existing feature label Jul 5, 2024
@setchy setchy added this to the Release 5.10.0 milestone Jul 5, 2024
@setchy setchy self-requested a review July 6, 2024 03:41
@setchy setchy merged commit 65c3d10 into main Jul 6, 2024
8 checks passed
@setchy setchy deleted the feat/zoom-slider branch July 6, 2024 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactoring of existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants