Skip to content

Commit

Permalink
Allow selecting loops in the UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
sigh committed May 30, 2024
1 parent 342ec37 commit b6e5031
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ select {
justify-content: space-between;
}

#multi-cell-constraint-loop-container {
margin-bottom: -10px;
}

.description {
line-height: 1;
font-size: 12px;
Expand Down
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ <h2>Create from selection</h2>
</div>
<div id="multi-cell-constraint-description" class="description">
</div>
<div id="multi-cell-constraint-loop-container">
<input type="checkbox" name="is-loop" id="multi-cell-constraint-loop-input"></input>
<label for="multi-cell-constraint-loop-input">Loop</label>
</div>
<div>
<div id="multi-cell-constraint-value-container"></div>
<button type="submit" name="add-constraint" title="Add constraint" disabled>
Expand Down
13 changes: 13 additions & 0 deletions js/render_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,9 @@ class ConstraintManager {
const valueContainer = document.getElementById('multi-cell-constraint-value-container');
const valueElems = [];

const loopContainer = document.getElementById('multi-cell-constraint-loop-container');
loopContainer.style.display = 'none';

// Initialize defaults.
for (const [name, config] of Object.entries(this._multiCellConstraints)) {
config.text ||= name;
Expand Down Expand Up @@ -1158,6 +1161,12 @@ class ConstraintManager {
valueContainer.style.visibility = 'hidden';
}

if (config.constraintClass.LOOPS_ALLOWED) {
loopContainer.style.display = 'block';
} else {
loopContainer.style.display = 'none';
}

descriptionElem.textContent = config.description;

if (!selectionForm.classList.contains('disabled')) {
Expand All @@ -1182,6 +1191,10 @@ class ConstraintManager {
if (!config) throw ('Unknown constraint type: ' + type);
if (config.elem.disabled) throw ('Invalid selection for ' + type);

if (config.constraintClass.LOOPS_ALLOWED && formData.get('is-loop')) {
cells.push('LOOP');
}

if (config.constraintClass === SudokuConstraint.Quad) {
const valuesStr = formData.get(type + '-value');
const values = valuesStr.split(/[, ]+/).map(v => +v).filter(
Expand Down

0 comments on commit b6e5031

Please sign in to comment.