Skip to content

Commit

Permalink
editable mark bar weight
Browse files Browse the repository at this point in the history
This reverts commit 8216bab83c38004f944229b9b501d70ce9ae0acd.
  • Loading branch information
ccyybn committed May 16, 2024
1 parent 263ca2f commit 3466a98
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 30 deletions.
21 changes: 18 additions & 3 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1468,13 +1468,21 @@ static void _RimeGetIntWithFallback(RimeConfig* config,
const char* key,
int* value,
const char* fb_key = NULL,
std::function<void(int*)> func = NULL) {
if (!RimeConfigGetInt(config, key, value) && fb_key != NULL) {
RimeConfigGetInt(config, fb_key, value);
std::function<void(int*)> func = NULL,
std::function<int()> fb_func = NULL) {
if (!RimeConfigGetInt(config, key, value)) {
if (fb_key != NULL) {
if (!RimeConfigGetInt(config, fb_key, value)) {
if (fb_func)
*value = fb_func();
}
} else if (fb_func)
*value = fb_func();
}
if (func)
func(value);
}

// get string value, with fallback value *fallback, and func to execute after
// reading
static void _RimeGetStringWithFunc(
Expand Down Expand Up @@ -1681,6 +1689,13 @@ static void _UpdateUIStyle(RimeConfig* config, UI* ui, bool initialize) {
_RimeGetIntWithFallback(config, "style/layout/corner_radius",
&style.round_corner_ex, "style/layout/round_corner",
_abs);
// the weight of the '|' when mark_text is empty, if not set explicitly, set
// it to the default value 0, which has no effect
std::function<int()> fb_func = NULL;
if (initialize)
fb_func = []() { return 0; };
_RimeGetIntWithFallback(config, "style/layout/mark_bar_weight",
&style.mark_bar_weight, NULL, _abs, fb_func);
// fix padding and spacing settings
if (style.layout_type != UIStyle::LAYOUT_VERTICAL_TEXT) {
// hilite_padding vs spacing
Expand Down
14 changes: 9 additions & 5 deletions WeaselUI/FullScreenLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ void weasel::FullScreenLayout::DoLayout(CDCHandle dc, PDWR pDWR) {
mark_width = sg.cx;
mark_height = sg.cy;
if (_style.mark_text.empty()) {
mark_width = mark_height / 7;
if (_style.linespacing && _style.baseline)
mark_width =
(int)((float)mark_width / ((float)_style.linespacing / 100.0f));
mark_width = max(mark_width, 6);
if (_style.mark_bar_weight) {
mark_width = _style.mark_bar_weight;
} else {
mark_width = mark_height / 7;
if (_style.linespacing && _style.baseline)
mark_width =
(int)((float)mark_width / ((float)_style.linespacing / 100.0f));
mark_width = max(mark_width, 6);
}
}
mark_gap = (_style.mark_text.empty())
? mark_width
Expand Down
14 changes: 9 additions & 5 deletions WeaselUI/HorizontalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ void HorizontalLayout::DoLayout(CDCHandle dc, PDWR pDWR) {
mark_width = sg.cx;
mark_height = sg.cy;
if (_style.mark_text.empty()) {
mark_width = mark_height / 7;
if (_style.linespacing && _style.baseline)
mark_width =
(int)((float)mark_width / ((float)_style.linespacing / 100.0f));
mark_width = max(mark_width, 6);
if (_style.mark_bar_weight) {
mark_width = _style.mark_bar_weight;
} else {
mark_width = mark_height / 7;
if (_style.linespacing && _style.baseline)
mark_width =
(int)((float)mark_width / ((float)_style.linespacing / 100.0f));
mark_width = max(mark_width, 6);
}
}
mark_gap = (_style.mark_text.empty()) ? mark_width
: mark_width + _style.hilite_spacing;
Expand Down
28 changes: 18 additions & 10 deletions WeaselUI/VHorizontalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ void VHorizontalLayout::DoLayout(CDCHandle dc, PDWR pDWR) {
mark_width = sg.cx;
mark_height = sg.cy;
if (_style.mark_text.empty()) {
mark_height = mark_width / 7;
if (_style.linespacing && _style.baseline)
mark_height =
(int)((float)mark_height / ((float)_style.linespacing / 100.0f));
mark_height = max(mark_height, 6);
if (_style.mark_bar_weight) {
mark_height = _style.mark_bar_weight;
} else {
mark_height = mark_width / 7;
if (_style.linespacing && _style.baseline)
mark_height =
(int)((float)mark_height / ((float)_style.linespacing / 100.0f));
mark_height = max(mark_height, 6);
}
}
mark_gap = (_style.mark_text.empty()) ? mark_height
: mark_height + _style.hilite_spacing;
Expand Down Expand Up @@ -270,11 +274,15 @@ void VHorizontalLayout::DoLayoutWithWrap(CDCHandle dc, PDWR pDWR) {
mark_width = sg.cx;
mark_height = sg.cy;
if (_style.mark_text.empty()) {
mark_height = mark_width / 7;
if (_style.linespacing && _style.baseline)
mark_height =
(int)((float)mark_height / ((float)_style.linespacing / 100.0f));
mark_height = max(mark_height, 6);
if (_style.mark_bar_weight) {
mark_height = _style.mark_bar_weight;
} else {
mark_height = mark_width / 7;
if (_style.linespacing && _style.baseline)
mark_height =
(int)((float)mark_height / ((float)_style.linespacing / 100.0f));
mark_height = max(mark_height, 6);
}
}
mark_gap = (_style.mark_text.empty()) ? mark_height
: mark_height + _style.hilite_spacing;
Expand Down
14 changes: 9 additions & 5 deletions WeaselUI/VerticalLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ void weasel::VerticalLayout::DoLayout(CDCHandle dc, PDWR pDWR) {
mark_width = sg.cx;
mark_height = sg.cy;
if (_style.mark_text.empty()) {
mark_width = mark_height / 7;
if (_style.linespacing && _style.baseline)
mark_width =
(int)((float)mark_width / ((float)_style.linespacing / 100.0f));
mark_width = max(mark_width, 6);
if (_style.mark_bar_weight) {
mark_width = _style.mark_bar_weight;
} else {
mark_width = mark_height / 7;
if (_style.linespacing && _style.baseline)
mark_width =
(int)((float)mark_width / ((float)_style.linespacing / 100.0f));
mark_width = max(mark_width, 6);
}
}
mark_gap = (_style.mark_text.empty()) ? mark_width
: mark_width + _style.hilite_spacing;
Expand Down
4 changes: 2 additions & 2 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,13 +809,13 @@ bool WeaselPanel::_DrawCandidates(CDCHandle& dc, bool back) {
if (m_style.layout_type == UIStyle::LAYOUT_VERTICAL_TEXT) {
int x = rect.left + (rect.Width() - width) / 2;
CRect mkrc{x, rect.top, x + width, rect.top + m_layout->mark_height};
GraphicsRoundRectPath mk_path(mkrc, mkrc.Height() / 2);
GraphicsRoundRectPath mk_path(mkrc, 2);
g_back.FillPath(&mk_brush, &mk_path);
} else {
int y = rect.top + (rect.Height() - height) / 2;
CRect mkrc{rect.left, y, rect.left + m_layout->mark_width,
y + height};
GraphicsRoundRectPath mk_path(mkrc, mkrc.Width() / 2);
GraphicsRoundRectPath mk_path(mkrc, 2);
g_back.FillPath(&mk_brush, &mk_path);
}
}
Expand Down
4 changes: 4 additions & 0 deletions include/WeaselIPCData.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ struct UIStyle {
int shadow_radius;
int shadow_offset_x;
int shadow_offset_y;
int mark_bar_weight;
bool vertical_auto_reverse;
// color scheme
int text_color;
Expand Down Expand Up @@ -345,6 +346,7 @@ struct UIStyle {
shadow_radius(0),
shadow_offset_x(0),
shadow_offset_y(0),
mark_bar_weight(0),
vertical_auto_reverse(false),
text_color(0),
candidate_text_color(0),
Expand Down Expand Up @@ -407,6 +409,7 @@ struct UIStyle {
shadow_radius != st.shadow_radius ||
shadow_offset_x != st.shadow_offset_x ||
shadow_offset_y != st.shadow_offset_y ||
mark_bar_weight != st.mark_bar_weight ||
vertical_auto_reverse != st.vertical_auto_reverse ||
baseline != st.baseline || linespacing != st.linespacing ||
text_color != st.text_color ||
Expand Down Expand Up @@ -481,6 +484,7 @@ void serialize(Archive& ar, weasel::UIStyle& s, const unsigned int version) {
ar & s.shadow_radius;
ar & s.shadow_offset_x;
ar & s.shadow_offset_y;
ar & s.mark_bar_weight;
ar & s.vertical_auto_reverse;
// color scheme
ar & s.text_color;
Expand Down

0 comments on commit 3466a98

Please sign in to comment.