From e7375fd733991d1bf34c4508ec95bdda761f60d4 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 10 Nov 2024 04:14:39 -0500 Subject: [PATCH] GUI: implement scrolltext issue #1961 applied on Checkbox --- extern/imgui_patched/imgui.cpp | 4 ++ extern/imgui_patched/imgui.h | 7 ++++ extern/imgui_patched/imgui_widgets.cpp | 58 +++++++++++++++++++++++++- src/gui/debugWindow.cpp | 9 ++++ src/gui/gui.cpp | 18 -------- src/gui/gui.h | 3 -- src/gui/settings.cpp | 2 + 7 files changed, 78 insertions(+), 23 deletions(-) diff --git a/extern/imgui_patched/imgui.cpp b/extern/imgui_patched/imgui.cpp index 8b39f2f26..20dbcd36f 100644 --- a/extern/imgui_patched/imgui.cpp +++ b/extern/imgui_patched/imgui.cpp @@ -1305,6 +1305,10 @@ ImGuiIO::ImGuiIO() // Inertial scrolling options (when ImGuiConfigFlags_InertialScrollEnable is set) ConfigInertialScrollToleranceSqr = 36.0f; + // ScrollText options + ScrollTextSpeed = 100.0f; + ScrollTextSpacing = 8.0f; + // Miscellaneous options MouseDrawCursor = false; #ifdef __APPLE__ diff --git a/extern/imgui_patched/imgui.h b/extern/imgui_patched/imgui.h index d826095b9..5624f9024 100644 --- a/extern/imgui_patched/imgui.h +++ b/extern/imgui_patched/imgui.h @@ -510,6 +510,9 @@ namespace ImGui IMGUI_API void BulletTextV(const char* fmt, va_list args) IM_FMTLIST(1); IMGUI_API void SeparatorText(const char* label); // currently: formatted text with an horizontal line + // Widgets: ScrollText (tildearrow) + IMGUI_API void ScrollText(ImGuiID id, const char* text, const ImVec2& pos, ImVec2 size=ImVec2(0,0), bool alwaysScroll=false); + // Widgets: Main // - Most widgets return true when the value has been changed or when pressed/selected // - You may also use one of the many IsItemXXX functions (e.g. IsItemActive, IsItemHovered, etc.) to query widget state. @@ -2093,6 +2096,10 @@ struct ImGuiIO // Inertial scrolling options (when ImGuiConfigFlags_InertialScrollEnable is set) float ConfigInertialScrollToleranceSqr;// = 36.0f // After a point moves past this distance, inertial scroll begins + // ScrollText options + float ScrollTextSpeed; // = 100.0f; + float ScrollTextSpacing; // = 8.0f; + // Miscellaneous options bool MouseDrawCursor; // = false // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). Cannot be easily renamed to 'io.ConfigXXX' because this is frequently used by backend implementations. bool ConfigMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl. diff --git a/extern/imgui_patched/imgui_widgets.cpp b/extern/imgui_patched/imgui_widgets.cpp index e79dc1da9..baf07ab12 100644 --- a/extern/imgui_patched/imgui_widgets.cpp +++ b/extern/imgui_patched/imgui_widgets.cpp @@ -527,6 +527,59 @@ void ImGui::BulletTextV(const char* fmt, va_list args) RenderText(bb.Min + ImVec2(g.FontSize + style.FramePadding.x * 2, 0.0f), text_begin, text_end, false); } +//------------------------------------------------------------------------- +// [SECTION] Widgets: ScrollText (tildearrow) +//------------------------------------------------------------------------- +// - ScrollText() +//------------------------------------------------------------------------- + +void ImGui::ScrollText(ImGuiID id, const char* text, const ImVec2& pos, ImVec2 size, bool alwaysScroll) { + ImGuiContext& g = *GImGui; + ImGuiWindow* window=g.CurrentWindow; + ImDrawList* dl=window->DrawList; + ImGuiStorage* storage=GetStateStorage(); + + ImVec2 textSize=ImGui::CalcTextSize(text); + bool mustNotScroll=false; + + if (size.x==0) { + size.x=((window->DC.CurrentColumns || g.CurrentTable) ? window->WorkRect.Max : window->ContentRegionRect.Max).x-pos.x; + if (textSize.xGetFloat(id,0.0f); + + dl->PushClipRect(minArea,maxArea,true); + if (hovered || alwaysScroll) { + minArea.x-=textPos; + } + dl->AddText(minArea,ImGui::GetColorU32(ImGuiCol_Text),text); + if ((hovered || alwaysScroll) && !mustNotScroll) { + textPos+=ImGui::GetIO().DeltaTime*g.IO.ScrollTextSpeed; + if (textPos>textSize.x) { + textPos-=textSize.x+size.x+g.IO.ScrollTextSpacing; + } + g.IO.IsSomethingHappening=true; + } else { + textPos=0.0; + } + storage->SetFloat(id,textPos); + dl->PopClipRect(); +} + //------------------------------------------------------------------------- // [SECTION] Widgets: Main //------------------------------------------------------------------------- @@ -1283,8 +1336,9 @@ bool ImGui::Checkbox(const char* label, bool* v) ImVec2 label_pos = ImVec2(check_bb.Max.x + style.ItemInnerSpacing.x, check_bb.Min.y + style.FramePadding.y); if (g.LogEnabled) LogRenderedText(&label_pos, mixed_value ? "[~]" : *v ? "[x]" : "[ ]"); - if (label_size.x > 0.0f) - RenderText(label_pos, label); + if (label_size.x > 0.0f) { + ScrollText(id, label, label_pos, ImVec2(0,0), hovered); + } IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0)); return pressed; diff --git a/src/gui/debugWindow.cpp b/src/gui/debugWindow.cpp index d19bfce22..9d7226749 100644 --- a/src/gui/debugWindow.cpp +++ b/src/gui/debugWindow.cpp @@ -347,6 +347,15 @@ void FurnaceGUI::drawDebug() { } ImGui::TreePop(); } + if (ImGui::TreeNode("Scroll Text Test")) { + /* + ImGui::ScrollText(ImGui::GetID("scrolltest1"),"Lorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?"); + ImGui::ScrollText(ImGui::GetID("scrolltest2"),"quis autem vel eum iure reprehenderit"); + ImGui::ScrollText(ImGui::GetID("scrolltest3"),"qui in ea voluptate velit esse",ImVec2(100.0f*dpiScale,0),true); + ImGui::ScrollText(ImGui::GetID("scrolltest4"),"quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?",ImVec2(0,0),true); + */ + ImGui::TreePop(); + } if (ImGui::TreeNode("Pitch Table Calculator")) { ImGui::InputDouble("Clock",&ptcClock); ImGui::InputDouble("Divider/FreqBase",&ptcDivider); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 5fad264b3..966f13df6 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -548,24 +548,6 @@ void FurnaceGUI::sameLineMaybe(float width) { if (ImGui::GetContentRegionAvail().xDC.CursorPos; - ImVec2 maxArea=ImVec2( - minArea.x+size.x, - minArea.y+size.y - ); - ImRect rect=ImRect(minArea,maxArea); - ImGuiStyle& style=ImGui::GetStyle(); - ImGui::ItemSize(size,style.FramePadding.y); - if (ImGui::ItemAdd(rect,id)) { - // TODO - dl->AddText(minArea,ImGui::GetColorU32(ImGuiCol_Text),text); - } -} - const char* FurnaceGUI::getSystemName(DivSystem which) { /* if (settings.chipNames) { diff --git a/src/gui/gui.h b/src/gui/gui.h index fa5df0b5d..00c7d8d09 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2792,9 +2792,6 @@ class FurnaceGUI { // inverted checkbox bool InvCheckbox(const char* label, bool* value); - // scrolling text - void ScrollText(ImGuiID id, const char* text, const ImVec2& size=ImVec2(0,0), bool alwaysScroll=false); - // mixer stuff ImVec2 calcPortSetSize(String label, int ins, int outs); bool portSet(String label, unsigned int portSetID, int ins, int outs, int activeIns, int activeOuts, int& clickedPort, std::map& portPos); diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index 806273909..990d69c01 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -6497,6 +6497,8 @@ void FurnaceGUI::applyUISettings(bool updateFonts) { ImGui::GetIO().ConfigWindowsMoveFromTitleBarOnly=settings.moveWindowTitle; ImGui::GetIO().ConfigInertialScrollToleranceSqr=pow(dpiScale*4.0f,2.0f); ImGui::GetIO().MouseDoubleClickTime=settings.doubleClickTime; + ImGui::GetIO().ScrollTextSpacing=8.0*dpiScale; + ImGui::GetIO().ScrollTextSpeed=60.0*dpiScale; for (int i=0; i<256; i++) { ImVec4& base=uiColors[GUI_COLOR_PATTERN_EFFECT_PITCH];