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

Further customization of grid spacing #983

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 6 additions & 43 deletions src/css/settings-application.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,9 @@
flex-shrink: 0;
}

.grid-spacing-container .size-picker-option[data-size='1'] {
padding: 7px;
}
.grid-spacing-container .size-picker-option[data-size='2'] {
padding: 6px;
}
.grid-spacing-container .size-picker-option[data-size='4'] {
padding: 5px;
}
.grid-spacing-container .size-picker-option[data-size='8'] {
padding: 4px;
}
.grid-spacing-container .size-picker-option[data-size='16'] {
padding: 3px;
}
.grid-spacing-container .size-picker-option[data-size='32'] {
padding: 2px;
}
.grid-spacing-container .size-picker-option[data-size='64'] {
padding: 1px;
.grid-spacing-input-container {
display:inline-block;
padding: 7px 5px;
}

.settings-item-grid-size .size-picker-option,
Expand All @@ -110,29 +93,9 @@
margin: 5px 5px 0 5px;
}


.grid-colors-list {
overflow: hidden;
padding: 0 5px;
}

.grid-colors-item {
float: left;
width: 20px;
height: 20px;
cursor: pointer;
border: 2px solid #888;
margin-right: 2px;
margin-bottom: 2px;
box-sizing: border-box;
}

.grid-colors-item:hover {
border-color: white;
}

.grid-colors-item.selected {
border-color: gold;
.grid-color-container .sp-preview {
width: 16px;
height: 16px;
}

.settings-section-preferences > .settings-title {
Expand Down
53 changes: 21 additions & 32 deletions src/js/controller/settings/preferences/GridPreferencesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
this.piskelController = piskelController;
this.preferencesController = preferencesController;
this.sizePicker = new pskl.widgets.SizePicker(this.onSizePickerChanged_.bind(this));
this.spacingPicker = new pskl.widgets.SizePicker(this.onSpacingPickerChanged_.bind(this));
};

pskl.utils.inherit(ns.GridPreferencesController, pskl.controller.settings.AbstractSettingController);
Expand All @@ -42,60 +41,50 @@
this.sizePicker.setSize(gridWidth);

//Grid Spacing
var gridSpacing = pskl.UserSettings.get(pskl.UserSettings.GRID_SPACING);
this.spacingPicker.init(document.querySelector('.grid-spacing-container'));
this.spacingPicker.setSize(gridSpacing);
var gridSpacingInput = document.querySelector('.grid-spacing-input');
gridSpacingInput.value = pskl.UserSettings.get(pskl.UserSettings.GRID_SPACING);
this.addEventListener(gridSpacingInput, 'change', this.onGridSpacingChange_);

// Grid color
var colorListItemTemplate = pskl.utils.Template.get('color-list-item-template');

var gridColor = pskl.UserSettings.get(pskl.UserSettings.GRID_COLOR);
var gridColorSelect = document.querySelector('#grid-color');

var markup = '';
Object.keys(colorsMap).forEach(function (key, index) {
var background = colorsMap[key];
if (key === 'transparent') {
background = 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZ' +
'F8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==)';
}
markup += pskl.utils.Template.replace(colorListItemTemplate, {
color: colorsMap[key],
title: key,
background: background,
':selected': gridColor === colorsMap[key]
});
});
this.gridColorList = document.querySelector('.grid-colors-list');
this.gridColorList.innerHTML = markup;

this.addEventListener(this.gridColorList, 'click', this.onGridColorClicked_.bind(this));
var gridColorSelector = $('#grid-color-picker');
var spectrumCfg = {
showPalette: false,
showButtons: false,
showInput: true,
clickoutFiresChange : true,
};
gridColorSelector.spectrum($.extend({color: gridColor}, spectrumCfg));
gridColorSelector.change(this.onGridColorClicked_);
};

ns.GridPreferencesController.prototype.destroy = function () {
this.sizePicker.destroy();
this.spacingPicker.destroy();
this.superclass.destroy.call(this);
};

ns.GridPreferencesController.prototype.onSizePickerChanged_ = function (size) {
pskl.UserSettings.set(pskl.UserSettings.GRID_WIDTH, size);
};

ns.GridPreferencesController.prototype.onSpacingPickerChanged_ = function (size) {
pskl.UserSettings.set(pskl.UserSettings.GRID_SPACING, size);
ns.GridPreferencesController.prototype.onGridSpacingChange_ = function (evt) {
var target = evt.target;
var gridSpacing = parseInt(target.value, 10);
if (gridSpacing && !isNaN(gridSpacing)) {
pskl.UserSettings.set(pskl.UserSettings.GRID_SPACING, gridSpacing);
} else {
target.value = pskl.UserSettings.get(pskl.UserSettings.GRID_SPACING);
};
};

ns.GridPreferencesController.prototype.onEnableGridChange_ = function (evt) {
pskl.UserSettings.set(pskl.UserSettings.GRID_ENABLED, evt.currentTarget.checked);
};

ns.GridPreferencesController.prototype.onGridColorClicked_ = function (evt) {
var color = evt.target.dataset.color;
var color = evt.target.value;
if (color) {
pskl.UserSettings.set(pskl.UserSettings.GRID_COLOR, color);
this.gridColorList.querySelector('.selected').classList.remove('selected');
evt.target.classList.add('selected');
}
};
})();
33 changes: 8 additions & 25 deletions src/templates/settings/preferences/grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,18 @@
title="4px" rel="tooltip" data-placement="top" data-size="4"></div>
</div>
</div>
<div class="settings-item settings-item-grid-spacing">
<label>Grid spacing</label>
<div class="grid-spacing-container size-picker-container">
<div class="size-picker-option"
title="1px" rel="tooltip" data-placement="top" data-size="1"></div>
<div class="size-picker-option"
title="2px" rel="tooltip" data-placement="top" data-size="2"></div>
<div class="size-picker-option"
title="4px" rel="tooltip" data-placement="top" data-size="4"></div>
<div class="size-picker-option"
title="8px" rel="tooltip" data-placement="top" data-size="8"></div>
<div class="size-picker-option"
title="16px" rel="tooltip" data-placement="top" data-size="16"></div>
<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>
<div class="resize-section settings-item">
<label class="resize-section-title">Grid spacing</label>
<div class="grid-spacing-input-container">
<input type="text" class="textfield resize-size-field grid-spacing-input" autocomplete="off"/>
<span>px</span>
</div>
</div>
<div class="settings-item settings-item-grid-color">
<label>Grid color</label>
<div class="grid-colors-list"></div>
<script type="text/template" id="color-list-item-template">
<div class="grid-colors-item {{:selected}}"
data-color="{{color}}"
style="background:{{background}}"
title="{{title}}">
</div>
</script>
<div class="grid-color-container">
<input id="grid-color-picker" class="color" type="text"/>
</div>
</div>
</div>
</script>