Step 119: zoom controls
This commit is contained in:
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");
|
||||
|
||||
Reference in New Issue
Block a user