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

Add a Grid Spacing option to the GridSettings #782

Merged
merged 2 commits into from
Feb 18, 2018

Conversation

Craggar
Copy link

@Craggar Craggar commented Feb 16, 2018

Copying styles/elements from the GridSize picker, this adds a GridSpacing picker

Fixes #774

@juliandescottes
Copy link
Collaborator

Thanks for opening the PR! I'll have a look today.

@juliandescottes
Copy link
Collaborator

juliandescottes commented Feb 17, 2018

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 while (this.zoom < 6 * gridWidth) { gridWidth--; }. This works well for thickness. But for density, if spacing is enabled we can keep displaying a thin grid on smaller zoom levels. Something like that would work:

  ns.FrameRenderer.prototype.computeGridWidthForDisplay_ = function () {
    var gridSpacing = this.getGridSpacing();
    if (this.zoom * gridSpacing < 6) {
      return 0;
    }

    var gridWidth = this.getGridWidth();
    while (gridWidth > 1 && this.zoom < 6 * gridWidth) {
      gridWidth--;
    }

    return gridWidth;
  };

Copy link
Collaborator

@juliandescottes juliandescottes left a 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 :)

@@ -60,13 +60,15 @@
}

.settings-item-grid-size,
.settings-item-grid-color {
.settings-item-grid-spacing,
.settings-item-grid-color,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"," should be "{"

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment


var storedGridSpacing = ns.UserSettings.readFromLocalStorage_('GRID_SPACING');
if (storedGridSpacing === 0) {
ns.UserSettings.writeToLocalStorage_('GRID_SPACING', 1);
Copy link
Collaborator

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 :)

(function () {
var ns = $.namespace('pskl.widgets');

ns.SpacingPicker = function (onChange) {
Copy link
Collaborator

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.

@Craggar
Copy link
Author

Craggar commented Feb 17, 2018

Grand, thanks for the feedback - I should get to it today or tomorrow.

@Craggar
Copy link
Author

Craggar commented Feb 18, 2018

I've made the changes above, and removed the now-redundant SpacingPicker js/css to clean up the PR.

Copy link
Collaborator

@juliandescottes juliandescottes left a 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>
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable is not used

@juliandescottes juliandescottes merged commit 3e450c3 into piskelapp:master Feb 18, 2018
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