Skip to content

Commit be66e3f

Browse files
committed
impr: Simplify and standardize resizable console window in pattern editor
1 parent d794734 commit be66e3f

File tree

1 file changed

+11
-42
lines changed

1 file changed

+11
-42
lines changed

plugins/builtin/source/content/views/view_pattern_editor.cpp

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -456,43 +456,29 @@ namespace hex::plugin::builtin {
456456
auto provider = ImHexApi::Provider::get();
457457

458458
if (ImHexApi::Provider::isValid() && provider->isAvailable()) {
459-
static float height = 0;
460459
const ImGuiContext& g = *ImGui::GetCurrentContext();
461460
if (g.CurrentWindow->Appearing)
462461
return;
463-
const auto availableSize = ImVec2(g.CurrentWindow->Size.x, g.CurrentWindow->Size.y - 2 * ImGui::GetFrameHeightWithSpacing());
464-
const auto windowPosition = ImGui::GetCursorScreenPos();
465-
static ImVec2 oldTextEditorSize = ImVec2(0, 0);
466-
ImVec2 textEditorSize = ImVec2(availableSize.x, oldTextEditorSize.x == 0 ? availableSize.y * 3.0F / 5.0F : oldTextEditorSize.y);
467-
static ImVec2 oldAvailableSize = ImVec2(0, 0);
468-
if (availableSize.y != oldAvailableSize.y && oldAvailableSize.y != 0) {
469-
float factor = availableSize.y / oldAvailableSize.y;
470-
height *= factor;
471-
}
472-
473-
static float oldHeight = 0;
474-
auto heightIncrement = height - oldHeight;
475-
if (heightIncrement != 0) {
476-
float smallestTexEditorHeight = ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().ScrollbarSize;
477-
float largestTextEditorHeight = availableSize.y - ImGui::GetTextLineHeightWithSpacing() - 2 * ImGui::GetFrameHeightWithSpacing() - ImGui::GetStyle().ScrollbarSize;
478-
textEditorSize.y = std::clamp(textEditorSize.y + heightIncrement, smallestTexEditorHeight, largestTextEditorHeight);
479-
}
480-
481-
oldAvailableSize = availableSize;
482-
oldTextEditorSize = textEditorSize;
483-
oldHeight = height;
462+
484463
if (g.NavWindow != nullptr) {
485464
std::string name = g.NavWindow->Name;
486465
if (name.contains(TextEditorView) || name.contains(ConsoleView) || name.contains(VariablesView) || name.contains(SettingsView) || name.contains(VirtualFilesView) || name.contains(DebuggerView))
487466
m_focusedSubWindowName = name;
488467
}
489468

469+
auto defaultEditorSize = ImGui::GetContentRegionAvail();
470+
defaultEditorSize.y *= 0.66F;
471+
490472
fonts::CodeEditor().push();
491-
m_textEditor.get(provider).render("##pattern_editor", textEditorSize, false);
473+
if (ImGui::BeginChild("##pattern_editor_resizer", defaultEditorSize, ImGuiChildFlags_ResizeY)) {
474+
m_textEditor.get(provider).render("##pattern_editor", ImGui::GetContentRegionAvail(), false);
475+
m_textEditorHoverBox = ImGui::GetCurrentWindow()->Rect();
476+
}
477+
ImGui::EndChild();
492478
fonts::CodeEditor().pop();
493479

494-
m_textEditorHoverBox = ImRect(windowPosition,windowPosition+textEditorSize);
495-
m_consoleHoverBox = ImRect(ImVec2(windowPosition.x,windowPosition.y+textEditorSize.y),windowPosition+availableSize);
480+
m_consoleHoverBox = ImGui::GetCurrentWindow()->Rect();
481+
m_consoleHoverBox.Min.y = m_textEditorHoverBox.Max.y + ImGui::GetTextLineHeightWithSpacing() * 1.5F;
496482

497483
if (m_textEditor.get(provider).raiseContextMenu()) {
498484
RequestOpenPopup::post("hex.builtin.menu.edit");
@@ -512,23 +498,6 @@ namespace hex::plugin::builtin {
512498
setupGotoLine(editor);
513499
}
514500

515-
static bool dragging = false;
516-
ImGui::Button("##settings_drag_bar", ImVec2(ImGui::GetContentRegionAvail().x, 4_scaled));
517-
if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, 0)) {
518-
if (ImGui::IsItemHovered())
519-
dragging = true;
520-
} else {
521-
dragging = false;
522-
}
523-
if (ImGui::IsItemHovered()) {
524-
ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS);
525-
}
526-
527-
if (dragging) {
528-
height += ImGui::GetMouseDragDelta(ImGuiMouseButton_Left, 0).y;
529-
ImGui::ResetMouseDragDelta(ImGuiMouseButton_Left);
530-
}
531-
532501
auto settingsSize = ImGui::GetContentRegionAvail();
533502
settingsSize.y -= ImGui::GetTextLineHeightWithSpacing() * 2.5F;
534503

0 commit comments

Comments
 (0)