-
Notifications
You must be signed in to change notification settings - Fork 784
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
Add a Grid Spacing option to the GridSettings #782
Conversation
Thanks for opening the PR! I'll have a look today. |
Works really nicely, great job! One comment about the feature itself: it would be nice to change computeGridWidthForDisplay_ so that it keeps displaying the grid a bit longer if grid spacing is enabled. If you use a big spacing with a 320x320 sprite for instance, the grid disapears very quickly when zooming out. The purpose of the computeGridWidthForDisplay_ method is to ensure that the grid doesn't become too dense or too thick. Right now it does that with a magical
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I think we can avoid creating a new widget but otherwise that's a really nice changeset, thanks for following the conventions in place, even though they're not written anywhere :)
src/css/settings-application.css
Outdated
@@ -60,13 +60,15 @@ | |||
} | |||
|
|||
.settings-item-grid-size, | |||
.settings-item-grid-color { | |||
.settings-item-grid-spacing, | |||
.settings-item-grid-color, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"," should be "{"
src/css/settings-application.css
Outdated
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.settings-item-grid-size > label, | ||
.settings-item-grid-color > label { | ||
.settings-item-grid-spacing > label, | ||
.settings-item-grid-color > label, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment
src/js/utils/UserSettings.js
Outdated
|
||
var storedGridSpacing = ns.UserSettings.readFromLocalStorage_('GRID_SPACING'); | ||
if (storedGridSpacing === 0) { | ||
ns.UserSettings.writeToLocalStorage_('GRID_SPACING', 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to add that, this was some migration code for version 12, because the GRID_WIDTH setting used to accept the "0" value. I should remove this method now :)
src/js/widgets/SpacingPicker.js
Outdated
(function () { | ||
var ns = $.namespace('pskl.widgets'); | ||
|
||
ns.SpacingPicker = function (onChange) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could reuse the SizePicker widget directly. The issue is mostly with the hardcoded "4" used in setSpacing. The goal was to represent the maximum value that can be represented via a [data-size] item.
Instead of doing that we can change the logic to do:
- get the element for the provided size
this.container.querySelector('[data-size="' + size + '"]')
- if the element is missing, get the last element and add a label:
selectedOption = this.container.querySelector('[data-size]:last-child');
selectedOption.classList.add('labeled');
selectedOption.setAttribute('real-size', size);
With this small change we can reuse the SizePicker directly, just need to change the setSpacing to setSize and the data-spacing to data-size where appropriate.
Grand, thanks for the feedback - I should get to it today or tomorrow. |
I've made the changes above, and removed the now-redundant SpacingPicker js/css to clean up the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the comments! I have two small nits, but I'll just push them in a follow up.
Thanks again for picking this up, I should take some time to make a release now and make this feature available on piskelapp.com!
<div class="size-picker-option" | ||
title="32px" rel="tooltip" data-placement="top" data-size="32"></div> | ||
<div class="size-picker-option" | ||
title="64px" rel="tooltip" data-placement="top" data-size="64"></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to have custom sizes defined in CSS for those, otherwise the last four elements have the same size.
if (gridWidth > 0) { | ||
var gridColor = this.getGridColor(); | ||
// Scale out before drawing the grid. | ||
displayContext.scale(1 / z, 1 / z); | ||
|
||
var drawOrClear; | ||
var drawing = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable is not used
Copying styles/elements from the GridSize picker, this adds a GridSpacing picker
Fixes #774