refactor(samples/calc-02): simplify layout to portrait-only single column

Remove the responsive two-column desktop arrangement and make the calculator stack vertically with a 4-column display button row that preserves alignment. Also align the display buttons with the shared base button styling.
This commit is contained in:
2026-05-16 01:16:47 +02:00
parent 75bf6d69df
commit 54797f9dd9
4 changed files with 19 additions and 91 deletions
+2 -2
View File
@@ -1,9 +1,9 @@
# State # State
- Core engine: `src/rpn-calculator.js` - Core engine: `src/rpn-calculator.js`
- Active demo: `samples/calc-02/` responsive HP48GX layout with portrait/landscape support; display-adjacent button row stays in 4 columns - Active demo: `samples/calc-02/` portrait-only HP48GX layout; display-adjacent button row stays in 4 columns and now shares the same base button styling as the function keys
- Mode button shows the current angle mode only; selecting a mode uses a popup menu - Mode button shows the current angle mode only; selecting a mode uses a popup menu
- Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants` - Public API: `push`, `pop`, `clear`, `swap`, `remove`, `edit`, `isValidIndex`, `input`, `command`, `getOperationsByCategory`, `getConstants`
- Config: `maxSize`, `base`, `angleMode`, `enabledCommands` - Config: `maxSize`, `base`, `angleMode`, `enabledCommands`
- Commands: arithmetic, stack, trigonometry, constants `pi` and `e`; arithmetic now includes `root` for y-th roots - Commands: arithmetic, stack, trigonometry, constants `pi` and `e`; arithmetic now includes `root` for y-th roots
- Demo actions: keyboard focus is kept on the hidden input on desktop so typing keeps working; the keypad layout places Enter in the bottom-left, ± in the former Enter position, and Esc before Clear for safety; paste parses clipboard text as a number before pushing it to the stack; Ctrl+V is supported via the hidden input paste event; backspace is ignored when the stack is empty; operation errors are shown as an overlay bar on top of the calculator with a shorter timeout and darker red - Demo actions: keyboard focus is kept on the hidden input on desktop so typing keeps working; the keypad layout places Enter in the bottom-left, ± in the former Enter position, and Esc before Clear for safety; paste parses clipboard text as a number before pushing it to the stack; Ctrl+V is supported via the hidden input paste event; backspace is ignored when the stack is empty; operation errors are shown as an overlay bar on top of the calculator with a shorter timeout and darker red; the display button row uses a 4-column grid with a spacer cell to preserve alignment
- Exports: browser `window.RpnCalculator`, CommonJS `module.exports` - Exports: browser `window.RpnCalculator`, CommonJS `module.exports`
+10 -79
View File
@@ -51,23 +51,23 @@ body {
.calculator { .calculator {
width: 100%; width: 100%;
height: 100%; height: auto;
min-height: 100%;
display: grid; display: grid;
padding: 8px; padding: 8px;
border-radius: 8px; border-radius: 8px;
background: linear-gradient(180deg, var(--panel2), var(--panel)); background: linear-gradient(180deg, var(--panel2), var(--panel));
border: 1px solid var(--edge); border: 1px solid var(--edge);
box-shadow: 0 26px 70px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08); box-shadow: 0 26px 70px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
grid-template-columns: 1.3fr 0.9fr; grid-template-columns: 1fr;
grid-template-rows: minmax(0, 0.62fr) min-content minmax(180px, 1fr) minmax(180px, 1fr); grid-template-rows: auto auto auto auto auto;
align-content: start; row-gap: 6px;
grid-template-areas: grid-template-areas:
"display functions" "display"
"display functions" "display-buttons"
"keypad functions" "keypad"
"keypad trigo"; "functions"
row-gap: 0; "trigo";
column-gap: clamp(10px, 1.4vw, 18px);
} }
.display-block, .display-block,
@@ -113,7 +113,6 @@ body {
padding: 0; padding: 0;
} }
.display-grid { .display-grid {
height: 100%; height: 100%;
display: grid; display: grid;
@@ -188,7 +187,6 @@ body {
border-radius: 8px; border-radius: 8px;
background: rgba(18, 24, 33, 0.98); background: rgba(18, 24, 33, 0.98);
border: 1px solid rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35); box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
} }
@@ -368,7 +366,6 @@ button:active {
outline-offset: 2px; outline-offset: 2px;
} }
.key-default { .key-default {
background: linear-gradient(180deg, var(--btnTop), var(--btnBottom)); background: linear-gradient(180deg, var(--btnTop), var(--btnBottom));
color: #eef2f7; color: #eef2f7;
@@ -403,70 +400,4 @@ button:active {
pointer-events: none; pointer-events: none;
} }
@media (orientation: portrait), (max-width: 860px) {
.calculator {
width: 100%;
height: auto;
min-height: 100%;
grid-template-columns: 1fr;
grid-template-rows: minmax(0px, auto) auto auto auto;
row-gap: 6px;
grid-template-areas:
"display"
"display-buttons"
"keypad"
"functions"
"trigo";
}
.display-buttons-grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.keypad-grid {
grid-template-rows: repeat(5, minmax(42px, 1fr));
}
.functions-grid,
.trigo-grid {
grid-auto-rows: minmax(0, auto);
grid-template-rows: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 520px) {
.app-shell {
padding: 0;
}
.calculator {
width: 100%;
min-height: 100%;
border-radius: 8px;
padding: 8px;
gap: 12px;
}
.display-panel {
padding: 8px;
padding-bottom: 8px;
}
.stack-cell {
font-size: clamp(16px, 5.2vw, 22px);
gap: 8px;
}
.stack-copy-button {
padding: 4px;
min-width: 24px;
}
button {
border-radius: 8px;
padding: 10px 8px;
font-size: 13px;
line-height: 1;
}
}
+7 -7
View File
@@ -25,13 +25,13 @@
<div class="display-buttons-panel"> <div class="display-buttons-panel">
<div class="display-buttons-grid"> <div class="display-buttons-grid">
<button id="modeButton" class="display-button key-default">Mode</button> <button id="modeButton" class="display-button">Mode</button>
<button id="pasteButton" class="display-button key-default"></button> <button id="pasteButton" class="display-button"></button>
<button id="upButton" class="display-button key-default"></button> <button id="upButton" class="display-button"></button>
<button id="constButton" class="display-button key-default">π</button> <button id="constButton" class="display-button">π</button>
<button id="leftButton" class="display-button key-default display-button-offset"></button> <button id="leftButton" class="display-button display-button-offset"></button>
<button id="downButton" class="display-button key-default"></button> <button id="downButton" class="display-button"></button>
<button id="rightButton" class="display-button key-default"></button> <button id="rightButton" class="display-button"></button>
<div class="display-button-spacer"></div> <div class="display-button-spacer"></div>
</div> </div>
</div> </div>
-3
View File
@@ -228,7 +228,6 @@ function execute(name) {
} else if (calc.isValidIndex(0)) { } else if (calc.isValidIndex(0)) {
calc.remove(0); calc.remove(0);
} }
} else if (name === 'swap') { } else if (name === 'swap') {
pushEditingValueIfNeeded(); pushEditingValueIfNeeded();
if (calc.isValidIndex(1)) { if (calc.isValidIndex(1)) {
@@ -489,12 +488,10 @@ downButton.addEventListener('click', () => {
} }
}); });
rightButton.addEventListener('click', () => { rightButton.addEventListener('click', () => {
execute('swap'); execute('swap');
}); });
window.addEventListener('keydown', handleKeyboard, { capture: true }); window.addEventListener('keydown', handleKeyboard, { capture: true });
window.addEventListener('load', focusInput); window.addEventListener('load', focusInput);
window.addEventListener('pageshow', focusInput); window.addEventListener('pageshow', focusInput);