diff --git a/RimeWithWeasel/RimeWithWeasel.cpp b/RimeWithWeasel/RimeWithWeasel.cpp index b218622f1..a9a11f0ee 100644 --- a/RimeWithWeasel/RimeWithWeasel.cpp +++ b/RimeWithWeasel/RimeWithWeasel.cpp @@ -558,6 +558,11 @@ static void _UpdateUIStyle(RimeConfig* config, weasel::UI* ui, bool initialize) style.layout_type = (style.layout_type == weasel::LAYOUT_HORIZONTAL) ? weasel::LAYOUT_HORIZONTAL_FULLSCREEN : weasel::LAYOUT_VERTICAL_FULLSCREEN; } + char label_text_format[128] = { 0 }; + if (RimeConfigGetString(config, "style/label_format", label_text_format, sizeof(label_text_format) - 1)) + { + style.label_text_format = utf8towcs(label_text_format); + } // layout (alternative to style/horizontal) char layout_type[256] = {0}; if (RimeConfigGetString(config, "style/layout/type", layout_type, sizeof(layout_type) - 1)) diff --git a/WeaselUI/HorizontalLayout.cpp b/WeaselUI/HorizontalLayout.cpp index 82e9edf6c..539d5ed4c 100644 --- a/WeaselUI/HorizontalLayout.cpp +++ b/WeaselUI/HorizontalLayout.cpp @@ -46,7 +46,7 @@ void HorizontalLayout::DoLayout(CDCHandle dc) w += _style.candidate_spacing; /* Label */ - std::wstring label = GetLabelText(labels, i); + std::wstring label = GetLabelText(labels, i, _style.label_text_format.c_str()); dc.GetTextExtent(label.c_str(), label.length(), &size); _candidateLabelRects[i].SetRect(w, height, w + size.cx, height + size.cy); w += size.cx, h = max(h, size.cy); diff --git a/WeaselUI/Layout.h b/WeaselUI/Layout.h index 08193ec1b..9ff37e65f 100644 --- a/WeaselUI/Layout.h +++ b/WeaselUI/Layout.h @@ -22,7 +22,7 @@ namespace weasel virtual CRect GetCandidateCommentRect(int id) const = 0; virtual CRect GetStatusIconRect() const = 0; - virtual std::wstring GetLabelText(const std::vector &labels, int id) const = 0; + virtual std::wstring GetLabelText(const std::vector &labels, int id, const wchar_t *format) const = 0; virtual bool IsInlinePreedit() const = 0; virtual bool ShouldDisplayStatusIcon() const = 0; diff --git a/WeaselUI/StandardLayout.cpp b/WeaselUI/StandardLayout.cpp index 661c61b5a..5e90215cf 100644 --- a/WeaselUI/StandardLayout.cpp +++ b/WeaselUI/StandardLayout.cpp @@ -8,9 +8,11 @@ StandardLayout::StandardLayout(const UIStyle &style, const Context &context, con { } -std::wstring StandardLayout::GetLabelText(const std::vector &labels, int id) const +std::wstring StandardLayout::GetLabelText(const std::vector &labels, int id, const wchar_t *format) const { - return labels.at(id).str + L'.'; + wchar_t buffer[128]; + swprintf_s<128>(buffer, format, labels.at(id).str.c_str()); + return std::wstring(buffer); } CSize StandardLayout::GetPreeditSize(CDCHandle dc) const diff --git a/WeaselUI/StandardLayout.h b/WeaselUI/StandardLayout.h index c42567fd9..accc69618 100644 --- a/WeaselUI/StandardLayout.h +++ b/WeaselUI/StandardLayout.h @@ -22,7 +22,7 @@ namespace weasel virtual CRect GetCandidateCommentRect(int id) const { return _candidateCommentRects[id]; } virtual CRect GetStatusIconRect() const { return _statusIconRect; } - virtual std::wstring GetLabelText(const std::vector &labels, int id) const; + virtual std::wstring GetLabelText(const std::vector &labels, int id, const wchar_t *format) const; virtual bool IsInlinePreedit() const; virtual bool ShouldDisplayStatusIcon() const; diff --git a/WeaselUI/VerticalLayout.cpp b/WeaselUI/VerticalLayout.cpp index 975c19a85..76fa0672c 100644 --- a/WeaselUI/VerticalLayout.cpp +++ b/WeaselUI/VerticalLayout.cpp @@ -50,7 +50,7 @@ void VerticalLayout::DoLayout(CDCHandle dc) int w = _style.margin_x, h = 0; int candidate_width = 0, comment_width = 0; /* Label */ - std::wstring label = GetLabelText(labels, i); + std::wstring label = GetLabelText(labels, i, _style.label_text_format.c_str()); dc.GetTextExtent(label.c_str(), label.length(), &size); _candidateLabelRects[i].SetRect(w, height, w + size.cx, height + size.cy); w += size.cx + space, h = max(h, size.cy); diff --git a/WeaselUI/WeaselPanel.cpp b/WeaselUI/WeaselPanel.cpp index bf83080af..3b0434d29 100644 --- a/WeaselUI/WeaselPanel.cpp +++ b/WeaselUI/WeaselPanel.cpp @@ -227,7 +227,7 @@ bool WeaselPanel::_DrawCandidates(CDCHandle dc) dc.SetTextColor(m_style.label_text_color); // Draw label - std::wstring label = m_layout->GetLabelText(labels, i); + std::wstring label = m_layout->GetLabelText(labels, i, m_style.label_text_format.c_str()); rect = m_layout->GetCandidateLabelRect(i); _TextOut(dc, rect.left, rect.top, rect, label.c_str(), label.length()); diff --git a/include/WeaselUI.h b/include/WeaselUI.h index 89a89e44c..50a9edd8a 100644 --- a/include/WeaselUI.h +++ b/include/WeaselUI.h @@ -31,6 +31,7 @@ namespace weasel bool inline_preedit; PreeditType preedit_type; bool display_tray_icon; + std::wstring label_text_format; // layout LayoutType layout_type; int min_width; @@ -64,6 +65,7 @@ namespace weasel inline_preedit(false), preedit_type(COMPOSITION), display_tray_icon(false), + label_text_format(), layout_type(LAYOUT_VERTICAL), min_width(0), min_height(0), diff --git a/output/data/weasel.yaml b/output/data/weasel.yaml index 1cc1e3a06..ffa75e64b 100644 --- a/output/data/weasel.yaml +++ b/output/data/weasel.yaml @@ -16,6 +16,7 @@ style: inline_preedit: false preedit_type: composition display_tray_icon: false + label_format: "%s." layout: min_width: 160 min_height: 0