Fix 04: NoWrap text, full-width popup anchor, always upward placement, longer history previews

This commit is contained in:
Win Dictation Dev
2026-06-11 18:53:07 +12:00
parent 09cac68075
commit a87a12ae7e
3 changed files with 326 additions and 22 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ inline std::vector<HistoryEntry> LoadHistoryIndex() {
e.path = HistoryDir() + L"\\" + fd.cFileName;
std::wstring stem(fd.cFileName);
stem = stem.substr(0, stem.find(L'.'));
std::wstring preview = ReadFileUtf8(e.path).substr(0, 28);
std::wstring preview = ReadFileUtf8(e.path).substr(0, 60);
for (wchar_t& c : preview) if (c == L'\r' || c == L'\n') c = L' ';
e.label = stem.substr(0, 10) + L" " + stem.substr(11, 2) + L":" + stem.substr(13, 2)
+ L" \u2014 " + preview + L"\u2026";
+31 -21
View File
@@ -364,6 +364,7 @@ static void StrokeRound(Graphics& g, const Color& c, const Rect& r, int rad, REA
static void DrawTextC(Graphics& g, const wchar_t* s, const Font& f, const Color& c,
const RectF& box, StringAlignment h, StringAlignment v) {
StringFormat sf; sf.SetAlignment(h); sf.SetLineAlignment(v);
sf.SetFormatFlags(StringFormatFlagsNoWrap);
sf.SetTrimming(StringTrimmingEllipsisCharacter);
SolidBrush b(c); g.DrawString(s, -1, &f, box, &sf, &b);
}
@@ -758,11 +759,25 @@ void ShowSelectPopup(HWND owner, int ctrlId, const std::vector<std::wstring>& it
}
if (items.empty()) return;
float s = g_dpiScale;
int rowH = (int)(30 * s);
int pad = (int)(3 * s); if (pad < 3) pad = 3;
int n = (int)items.size();
int visRows = std::min(n, kPopupMaxVisible);
float s = g_dpiScale;
int rowH = (int)(30 * s);
int pad = (int)(3 * s); if (pad < 3) pad = 3;
int n = (int)items.size();
POINT tl{ (LONG)anchor.X, (LONG)anchor.Y };
ClientToScreen(owner, &tl);
int anchorTop = tl.y;
int x = tl.x;
HMONITOR mon = MonitorFromWindow(owner, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi{ sizeof(mi) };
GetMonitorInfo(mon, &mi);
int visRows = std::min(n, kPopupMaxVisible);
int spaceAbove = anchorTop - mi.rcWork.top - 2;
int fitRows = (spaceAbove - 2 * pad) / rowH;
if (fitRows < 1) fitRows = 1;
if (visRows > fitRows) visRows = fitRows;
g_pop = PopupState{};
g_pop.items = items;
@@ -776,20 +791,9 @@ void ShowSelectPopup(HWND owner, int ctrlId, const std::vector<std::wstring>& it
g_pop.scroll = std::max(0, std::min(sel - visRows / 2, n - visRows));
int h = visRows * rowH + 2 * pad;
int wdt = std::max((int)anchor.Width, (int)(260 * s));
int wdt = (int)anchor.Width;
POINT tl{ (LONG)anchor.X, (LONG)anchor.Y };
ClientToScreen(owner, &tl);
int anchorTop = tl.y;
int anchorBottom = tl.y + (int)anchor.Height;
int x = tl.x;
HMONITOR mon = MonitorFromWindow(owner, MONITOR_DEFAULTTONEAREST);
MONITORINFO mi{ sizeof(mi) };
GetMonitorInfo(mon, &mi);
int y;
if (anchorBottom + 2 + h <= mi.rcWork.bottom) y = anchorBottom + 2;
else y = anchorTop - h - 2;
int y = anchorTop - h - 2;
if (y < mi.rcWork.top) y = mi.rcWork.top;
if (x + wdt > mi.rcWork.right) x = mi.rcWork.right - wdt;
if (x < mi.rcWork.left) x = mi.rcWork.left;
@@ -1120,6 +1124,12 @@ int HitTest(POINT p) {
return -1;
}
static RectF SelectsRowFullWidthAnchor() {
const RectF& a = g_w[(int)WK::SelAudio].r;
const RectF& b = g_w[(int)WK::History].r;
return RectF(a.X, b.Y, (b.X + b.Width) - a.X, b.Height);
}
void OnClick(HWND hWnd, WK kind) {
if (!g_modelLoaded.load() && kind != WK::RecordHero && kind != WK::Clear
&& kind != WK::Copy && kind != WK::Paste && kind != WK::Pin
@@ -1170,7 +1180,7 @@ void OnClick(HWND hWnd, WK kind) {
PersistNow();
break;
case WK::SelAudio:
ShowSelectPopup(hWnd, ID_SEL_AUDIO, g_audioItems, g_audioSel, g_w[(int)WK::SelAudio].r);
ShowSelectPopup(hWnd, ID_SEL_AUDIO, g_audioItems, g_audioSel, SelectsRowFullWidthAnchor());
break;
case WK::History: {
g_history = LoadHistoryIndex();
@@ -1178,7 +1188,7 @@ void OnClick(HWND hWnd, WK kind) {
std::vector<std::wstring> labels;
labels.reserve(g_history.size());
for (const auto& e : g_history) labels.push_back(e.label);
ShowSelectPopup(hWnd, ID_SEL_HISTORY, labels, -1, g_w[(int)WK::History].r);
ShowSelectPopup(hWnd, ID_SEL_HISTORY, labels, -1, SelectsRowFullWidthAnchor());
break;
}
case WK::SettingsCog: SwitchView(hWnd, View::Settings); break;
@@ -1814,7 +1824,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
break;
case ID_SEL_AUDIO:
ShowSelectPopup(hWnd, ID_SEL_AUDIO, g_audioItems, g_audioSel, g_w[(int)WK::SelAudio].r);
ShowSelectPopup(hWnd, ID_SEL_AUDIO, g_audioItems, g_audioSel, SelectsRowFullWidthAnchor());
break;
}
break;