Step 119: zoom controls
This commit is contained in:
@@ -222,6 +222,7 @@ All 38 steps implemented and passing. Each step has a corresponding test (`step1
|
||||
- [x] Step 116: **IMPLEMENTED** — Project save/load (.whetstone) with AST serialization (4/4 tests pass)
|
||||
- [x] Step 117: **IMPLEMENTED** — Session persistence (layout, buffers, cursors, folds) (5/5 tests pass)
|
||||
- [x] Step 118: **IMPLEMENTED** — Settings panel + persistence (11/11 tests pass)
|
||||
- [x] Step 119: **IMPLEMENTED** — Zoom controls and status bar indicator (5/5 tests pass)
|
||||
|
||||
---
|
||||
|
||||
@@ -323,6 +324,7 @@ vcpkg's imgui 1.91.9 removed the `sdl2-binding` feature (only `sdl3-binding` exi
|
||||
**Step 116:** Compile and pass (4/4)
|
||||
**Step 117:** Compile and pass (5/5)
|
||||
**Step 118:** Compile and pass (11/11)
|
||||
**Step 119:** Compile and pass (5/5)
|
||||
|
||||
---
|
||||
|
||||
@@ -374,7 +376,7 @@ vcpkg's imgui 1.91.9 removed the `sdl2-binding` feature (only `sdl3-binding` exi
|
||||
|
||||
## What's Next
|
||||
|
||||
Sprint 4 in progress. Step 118 (settings panel) done. Next: Step 119 (zoom).
|
||||
Sprint 4 in progress. Step 119 (zoom) done. Next: Step 120 (undo/redo rework).
|
||||
|
||||
---
|
||||
|
||||
@@ -454,3 +456,4 @@ Sprint 4 in progress. Step 118 (settings panel) done. Next: Step 119 (zoom).
|
||||
| 2026-02-09 | Codex | Step 116: Project save/load (.whetstone) with AST serialization. 4/4 tests pass. |
|
||||
| 2026-02-09 | Codex | Step 117: Session persistence (layout, buffers, cursors, folds). 5/5 tests pass. |
|
||||
| 2026-02-09 | Codex | Step 118: Settings panel + persistence. 11/11 tests pass. |
|
||||
| 2026-02-09 | Codex | Step 119: Zoom controls and status bar indicator. 5/5 tests pass. |
|
||||
|
||||
@@ -634,6 +634,10 @@ add_executable(step118_test tests/step118_test.cpp)
|
||||
target_include_directories(step118_test PRIVATE src)
|
||||
target_link_libraries(step118_test PRIVATE nlohmann_json::nlohmann_json)
|
||||
|
||||
add_executable(step119_test tests/step119_test.cpp)
|
||||
target_include_directories(step119_test PRIVATE src)
|
||||
target_link_libraries(step119_test PRIVATE nlohmann_json::nlohmann_json)
|
||||
|
||||
find_package(SDL2 CONFIG REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(glad CONFIG REQUIRED)
|
||||
|
||||
14
editor/src/ZoomUtils.h
Normal file
14
editor/src/ZoomUtils.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
// Step 119: Zoom utilities
|
||||
|
||||
inline int clampFontSize(int size, int minSize = 12, int maxSize = 24) {
|
||||
if (size < minSize) return minSize;
|
||||
if (size > maxSize) return maxSize;
|
||||
return size;
|
||||
}
|
||||
|
||||
inline int zoomPercent(int fontSize, float baseFontSize) {
|
||||
if (baseFontSize <= 0.0f) return 100;
|
||||
float pct = (fontSize / baseFontSize) * 100.0f;
|
||||
return (int)(pct + 0.5f);
|
||||
}
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "Orchestrator.h"
|
||||
#include "ProjectManager.h"
|
||||
#include "SessionManager.h"
|
||||
#include "ZoomUtils.h"
|
||||
#include "ast/Serialization.h"
|
||||
#include "ast/Generator.h"
|
||||
#include "ast/Annotation.h"
|
||||
@@ -1962,6 +1963,17 @@ int main(int, char**) {
|
||||
state.commandSelected = 0;
|
||||
}
|
||||
|
||||
auto applyFontSize = [&](int newSize) {
|
||||
newSize = clampFontSize(newSize);
|
||||
state.settings.setFontSize(newSize);
|
||||
io.FontGlobalScale = newSize / baseFontSize;
|
||||
state.saveSettingsToDisk();
|
||||
};
|
||||
|
||||
if ((sdlMod & KMOD_CTRL) && sym == SDLK_0) {
|
||||
applyFontSize((int)baseFontSize);
|
||||
}
|
||||
|
||||
if (key != 0 && mods != WMOD_NONE) {
|
||||
KeyCombo combo{key, mods};
|
||||
std::string action = state.keys.getAction(combo);
|
||||
@@ -1979,6 +1991,8 @@ int main(int, char**) {
|
||||
std::string lang = state.active() ? state.active()->language : "python";
|
||||
state.createBuffer(state.makeUntitledName(), "", lang);
|
||||
}
|
||||
else if (action == "view.zoomIn") applyFontSize(state.settings.getFontSize() + 1);
|
||||
else if (action == "view.zoomOut") applyFontSize(state.settings.getFontSize() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4009,6 +4023,10 @@ int main(int, char**) {
|
||||
ImGui::Text("Keys: %s", KeybindingManager::profileName(state.keys.getProfile()));
|
||||
ImGui::SameLine(0, 30);
|
||||
|
||||
// Zoom
|
||||
ImGui::Text("Zoom: %d%%", zoomPercent(state.settings.getFontSize(), baseFontSize));
|
||||
ImGui::SameLine(0, 30);
|
||||
|
||||
// Modified indicator
|
||||
if (state.active() && state.active()->modified)
|
||||
ImGui::Text("Modified");
|
||||
|
||||
27
editor/tests/step119_test.cpp
Normal file
27
editor/tests/step119_test.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Step 119 TDD Test: Zoom utilities
|
||||
#include "ZoomUtils.h"
|
||||
#include <iostream>
|
||||
|
||||
static void expect(bool cond, const std::string& name, int& passed, int& failed) {
|
||||
if (cond) {
|
||||
std::cout << "Test " << (passed + failed + 1) << " PASS: " << name << "\n";
|
||||
++passed;
|
||||
} else {
|
||||
std::cout << "Test " << (passed + failed + 1) << " FAIL: " << name << "\n";
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int passed = 0;
|
||||
int failed = 0;
|
||||
|
||||
expect(clampFontSize(10) == 12, "clamp low", passed, failed);
|
||||
expect(clampFontSize(30) == 24, "clamp high", passed, failed);
|
||||
expect(clampFontSize(18) == 18, "clamp ok", passed, failed);
|
||||
expect(zoomPercent(15, 15.0f) == 100, "zoom 100", passed, failed);
|
||||
expect(zoomPercent(18, 15.0f) == 120, "zoom 120", passed, failed);
|
||||
|
||||
std::cout << "\n=== Step 119 Results: " << passed << " passed, " << failed << " failed ===\n";
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
@@ -380,7 +380,7 @@ AST extensions for Sprint 5.
|
||||
keybinding profile. Persisted to `~/.whetstone/settings.json`.
|
||||
*New:* `SettingsManager.h`
|
||||
|
||||
- [ ] **Step 119: Zoom**
|
||||
- [x] **Step 119: Zoom**
|
||||
Ctrl+= zoom in, Ctrl+- zoom out, Ctrl+0 reset. Scales the editor font
|
||||
size dynamically. Status bar shows current zoom level.
|
||||
*Modifies:* `main.cpp`
|
||||
|
||||
Reference in New Issue
Block a user