From eb0aac0f54f3cfae1a847edc65de463d5629d394 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 20 Sep 2022 19:07:17 -0500 Subject: [PATCH] GUI: more work on it --- src/gui/gui.h | 4 +- src/gui/pattern.cpp | 100 +++++++++++++++++++++++++++++-------------- src/gui/settings.cpp | 10 ++++- 3 files changed, 79 insertions(+), 35 deletions(-) diff --git a/src/gui/gui.h b/src/gui/gui.h index bbfb3cf5..5bf8adfe 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -1179,6 +1179,7 @@ class FurnaceGUI { int channelVolStyle; int channelFeedbackStyle; int channelFont; + int channelTextCenter; int maxRecentFile; unsigned int maxUndoSteps; String mainFontPath; @@ -1297,10 +1298,11 @@ class FurnaceGUI { saveUnusedPatterns(0), channelColors(1), channelTextColors(0), - channelStyle(0), + channelStyle(1), channelVolStyle(0), channelFeedbackStyle(1), channelFont(1), + channelTextCenter(1), maxRecentFile(10), maxUndoSteps(100), mainFontPath(""), diff --git a/src/gui/pattern.cpp b/src/gui/pattern.cpp index add285f6..103ecbbe 100644 --- a/src/gui/pattern.cpp +++ b/src/gui/pattern.cpp @@ -18,6 +18,7 @@ */ // for suck's fake Clang extension! +#include #define _USE_MATH_DEFINES #include "gui.h" #include "../ta-log.h" @@ -25,6 +26,7 @@ #include "IconsFontAwesome4.h" #include "misc/cpp/imgui_stdlib.h" #include "guiConst.h" +#include "../utfutils.h" #include inline float randRange(float min, float max) { @@ -448,27 +450,6 @@ void FurnaceGUI::drawPattern() { if (!e->curSubSong->chanShow[i]) continue; ImGui::TableNextColumn(); bool displayTooltip=false; - if (e->curSubSong->chanCollapse[i]) { - const char* chName=e->getChannelShortName(i); - if (strlen(chName)>3) { - snprintf(chanID,2048,"...##_CH%d",i); - } else { - snprintf(chanID,2048,"%s##_CH%d",chName,i); - } - displayTooltip=true; - } else { - const char* chName=e->getChannelName(i); - size_t chNameLimit=6+4*e->curPat[i].effectCols; - if (strlen(chName)>chNameLimit) { - String shortChName=chName; - shortChName.resize(chNameLimit-3); - shortChName+="..."; - snprintf(chanID,2048," %s##_CH%d",shortChName.c_str(),i); - displayTooltip=true; - } else { - snprintf(chanID,2048," %s##_CH%d",chName,i); - } - } bool muted=e->isChannelMuted(i); ImVec4 chanHead=muted?uiColors[GUI_COLOR_CHANNEL_MUTED]:channelColor(i); @@ -532,10 +513,14 @@ void FurnaceGUI::drawPattern() { ImGuiWindow* window=ImGui::GetCurrentWindow(); ImVec2 size=ImVec2( 1.0f, - lineHeight+1.0f*dpiScale+6.0*dpiScale + lineHeight+1.0f*dpiScale ); ImDrawList* dl=ImGui::GetWindowDrawList(); + if (settings.channelStyle!=0) { + size.y+=6.0f*dpiScale; + } + if (settings.channelStyle==2) { size.y+=6.0f*dpiScale; } @@ -546,13 +531,63 @@ void FurnaceGUI::drawPattern() { minArea.y+size.y ); ImRect rect=ImRect(minArea,maxArea); + float padding=ImGui::CalcTextSize("A").x; + + ImVec2 minLabelArea=minArea; + ImVec2 maxLabelArea=maxArea; + + if (e->curSubSong->chanCollapse[i]) { + const char* chName=e->getChannelShortName(i); + if (strlen(chName)>3) { + snprintf(chanID,2048,"..."); + } else { + snprintf(chanID,2048,"%s",chName); + } + displayTooltip=true; + } else { + minLabelArea.x+=padding; + maxLabelArea.x-=padding; + const char* chName=e->getChannelName(i); + float chNameLimit=maxLabelArea.x-minLabelArea.x; + if (ImGui::CalcTextSize(chName).x>chNameLimit) { + String shortChName; + float totalAdvanced=0.0f; + float ellipsisSize=ImGui::CalcTextSize("...").x; + for (const char* j=chName; *j;) { + signed char l; + int ch=decodeUTF8((const unsigned char*)j,l); + + totalAdvanced+=ImGui::GetFont()->GetCharAdvance(ch); + if (totalAdvanced>(chNameLimit-ellipsisSize)) break; + + for (int k=0; kAddRectFilled(rect.Min,rect.Max,col); + dl->AddText(ImVec2(minLabelArea.x,rect.Min.y),ImGui::GetColorU32(channelTextColor(i)),chanID); } - ImGui::Selectable(chanID,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,ImVec2(0.0f,lineHeight+1.0f*dpiScale)); break; case 1: { // line ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y); @@ -572,7 +607,7 @@ void FurnaceGUI::drawPattern() { )); dl->AddRectFilledMultiColor(rect.Min,rect.Max,fadeCol0,fadeCol0,fadeCol,fadeCol); dl->AddLine(ImVec2(rect.Min.x,rect.Max.y),ImVec2(rect.Max.x,rect.Max.y),ImGui::GetColorU32(chanHeadBase),2.0f*dpiScale); - dl->AddText(ImVec2(rect.Min.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID,strstr(chanID,"##")); + dl->AddText(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID); } break; } @@ -599,18 +634,16 @@ void FurnaceGUI::drawPattern() { rMax.x-=3.0f*dpiScale; rMax.y-=6.0f*dpiScale; dl->AddRectFilledMultiColor(rMin,rMax,fadeCol0,fadeCol0,fadeCol,fadeCol,4.0f*dpiScale); - dl->AddText(ImVec2(rect.Min.x,rect.Min.y+6.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID,strstr(chanID,"##")); + dl->AddText(ImVec2(minLabelArea.x,rect.Min.y+6.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID); } break; } case 3: // split button ImGui::Dummy(ImVec2(1.0f,2.0f*dpiScale)); - ImGui::TextUnformatted(chanID,strstr(chanID,"##")); + ImGui::TextUnformatted(chanID); ImGui::SameLine(); ImGui::PushFont(mainFont); - ImGui::PushID(chanID); ImGui::SmallButton(muted?ICON_FA_VOLUME_OFF:ICON_FA_VOLUME_UP); - ImGui::PopID(); ImGui::PopFont(); break; case 4: { // square border @@ -630,7 +663,7 @@ void FurnaceGUI::drawPattern() { rMax.x-=3.0f*dpiScale; rMax.y-=3.0f*dpiScale; dl->AddRect(rMin,rMax,fadeCol,0.0f,2.0*dpiScale); - dl->AddText(ImVec2(rect.Min.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID,strstr(chanID,"##")); + dl->AddText(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID); } break; } @@ -651,11 +684,12 @@ void FurnaceGUI::drawPattern() { rMax.x-=3.0f*dpiScale; rMax.y-=3.0f*dpiScale; dl->AddRect(rMin,rMax,fadeCol,4.0f*dpiScale,ImDrawFlags_RoundCornersAll,2.0*dpiScale); - dl->AddText(ImVec2(rect.Min.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID,strstr(chanID,"##")); + dl->AddText(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID); } break; } } + ImGui::PopID(); if (displayTooltip && ImGui::IsItemHovered()) { ImGui::SetTooltip("%s",e->getChannelName(i)); diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index e5c60982..bf360dae 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1355,6 +1355,11 @@ void FurnaceGUI::drawSettings() { settings.channelFont=1; } + bool channelTextCenterB=settings.channelTextCenter; + if (ImGui::Checkbox("Center channel name",&channelTextCenterB)) { + settings.channelTextCenter=channelTextCenterB; + } + ImGui::Separator(); bool insEditColorizeB=settings.insEditColorize; @@ -2291,10 +2296,11 @@ void FurnaceGUI::syncSettings() { settings.saveUnusedPatterns=e->getConfInt("saveUnusedPatterns",0); settings.channelColors=e->getConfInt("channelColors",1); settings.channelTextColors=e->getConfInt("channelTextColors",0); - settings.channelStyle=e->getConfInt("channelStyle",0); + settings.channelStyle=e->getConfInt("channelStyle",1); settings.channelVolStyle=e->getConfInt("channelVolStyle",0); settings.channelFeedbackStyle=e->getConfInt("channelFeedbackStyle",1); settings.channelFont=e->getConfInt("channelFont",1); + settings.channelTextCenter=e->getConfInt("channelTextCenter",1); settings.maxRecentFile=e->getConfInt("maxRecentFile",10); clampSetting(settings.mainFontSize,2,96); @@ -2395,6 +2401,7 @@ void FurnaceGUI::syncSettings() { clampSetting(settings.channelVolStyle,0,4); clampSetting(settings.channelFeedbackStyle,0,3); clampSetting(settings.channelFont,0,1); + clampSetting(settings.channelTextCenter,0,1); clampSetting(settings.maxRecentFile,0,30); settings.initialSys=e->decodeSysDesc(e->getConfString("initialSys","")); @@ -2551,6 +2558,7 @@ void FurnaceGUI::commitSettings() { e->setConf("channelVolStyle",settings.channelVolStyle); e->setConf("channelFeedbackStyle",settings.channelFeedbackStyle); e->setConf("channelFont",settings.channelFont); + e->setConf("channelTextCenter",settings.channelTextCenter); e->setConf("maxRecentFile",settings.maxRecentFile); // colors