Step 98: inline annotation decorations
This commit is contained in:
@@ -21,6 +21,8 @@ struct CodeEditorOptions {
|
||||
EditorMode* mode = nullptr;
|
||||
bool enableFolding = false;
|
||||
bool showMinimap = false;
|
||||
bool showAnnotations = false;
|
||||
int annotationLayout = 0; // 0=above, 1=margin, 2=beside
|
||||
const std::vector<int>* errorLines = nullptr;
|
||||
const std::vector<int>* warningLines = nullptr;
|
||||
const std::vector<struct DiagnosticRange>* diagnostics = nullptr;
|
||||
@@ -336,6 +338,27 @@ public:
|
||||
pos = spanEnd;
|
||||
}
|
||||
|
||||
// Inline annotation tag
|
||||
if (options.showAnnotations && options.annotations) {
|
||||
AnnotationMarker marker;
|
||||
if (annotationAtLine(*options.annotations, ln, marker)) {
|
||||
ImVec2 tagPos;
|
||||
if (options.annotationLayout == 1) {
|
||||
tagPos = ImVec2(origin.x + 18.0f, y);
|
||||
} else if (options.annotationLayout == 2) {
|
||||
tagPos = ImVec2(textBase.x + len * charAdvance + 8.0f, y);
|
||||
} else {
|
||||
tagPos = ImVec2(textBase.x, y - lineHeight * 0.7f);
|
||||
}
|
||||
ImVec2 textSize = font->CalcTextSizeA(font->FontSize, FLT_MAX, -1.0f, marker.message.c_str());
|
||||
ImVec2 bgA(tagPos.x - 2.0f, tagPos.y);
|
||||
ImVec2 bgB(tagPos.x + textSize.x + 6.0f, tagPos.y + lineHeight * 0.8f);
|
||||
drawList->AddRectFilled(bgA, bgB, IM_COL32(30, 30, 30, 220), 2.0f);
|
||||
drawList->AddText(font, font->FontSize, ImVec2(tagPos.x + 2.0f, tagPos.y),
|
||||
marker.color, marker.message.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Folded placeholder
|
||||
if (fold && fold->folded) {
|
||||
ImVec2 p(textBase.x + len * charAdvance + 6.0f, y);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "Pipeline.h"
|
||||
#include "Diagnostics.h"
|
||||
#include "SettingsManager.h"
|
||||
#include "LayoutManager.h"
|
||||
#include "ast/Generator.h"
|
||||
#include "ast/Annotation.h"
|
||||
|
||||
@@ -83,6 +84,8 @@ struct EditorState {
|
||||
// Custom editor widget state
|
||||
bool showWhitespace = false;
|
||||
bool showMinimap = false;
|
||||
bool showAnnotations = false;
|
||||
LayoutPreset layoutPreset = LayoutPreset::VSCode;
|
||||
WelcomeScreen welcome;
|
||||
std::string workspaceRoot;
|
||||
FileTree fileTree;
|
||||
@@ -968,7 +971,17 @@ int main(int, char**) {
|
||||
if (ImGui::BeginMenu("View")) {
|
||||
ImGui::MenuItem("Show Whitespace", nullptr, &state.showWhitespace);
|
||||
ImGui::MenuItem("Show Minimap", nullptr, &state.showMinimap);
|
||||
ImGui::MenuItem("Show Annotations", nullptr, &state.showAnnotations);
|
||||
ImGui::MenuItem("LSP Servers...", nullptr, &state.showLspSettings);
|
||||
if (ImGui::BeginMenu("Layout")) {
|
||||
if (ImGui::MenuItem("VSCode", nullptr, state.layoutPreset == LayoutPreset::VSCode))
|
||||
state.layoutPreset = LayoutPreset::VSCode;
|
||||
if (ImGui::MenuItem("Emacs", nullptr, state.layoutPreset == LayoutPreset::Emacs))
|
||||
state.layoutPreset = LayoutPreset::Emacs;
|
||||
if (ImGui::MenuItem("JetBrains", nullptr, state.layoutPreset == LayoutPreset::JetBrains))
|
||||
state.layoutPreset = LayoutPreset::JetBrains;
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Language")) {
|
||||
@@ -1155,6 +1168,10 @@ int main(int, char**) {
|
||||
opts.mode = &buf->mode;
|
||||
opts.enableFolding = true;
|
||||
opts.showMinimap = state.showMinimap;
|
||||
opts.showAnnotations = state.showAnnotations;
|
||||
if (state.layoutPreset == LayoutPreset::Emacs) opts.annotationLayout = 1;
|
||||
else if (state.layoutPreset == LayoutPreset::JetBrains) opts.annotationLayout = 2;
|
||||
else opts.annotationLayout = 0;
|
||||
opts.errorLines = &errorLines;
|
||||
opts.warningLines = &warningLines;
|
||||
opts.diagnostics = &diagRanges;
|
||||
|
||||
Reference in New Issue
Block a user