Skip to content

Commit b61e240

Browse files
fix: draw border correctly without acrylic effect
1 parent d6f1e2e commit b61e240

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/shell/widgets/background_widget.cc

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ background_widget::background_widget(bool is_main) {
3030
bg_impl = std::make_shared<ui::rect_widget>();
3131
auto c = light_color ? 1 : 25 / 255.f;
3232
bg_impl->bg_color = nvgRGBAf(c, c, c, 1);
33+
render_bg_impl = false;
3334
}
3435

3536
bg_impl->radius->reset_to(config::current->context_menu.theme.radius);
@@ -76,13 +77,24 @@ void background_widget::update(ui::update_context &ctx) {
7677
}
7778

7879
void background_widget::render(ui::nanovg_context ctx) {
80+
auto &theme = config::current->context_menu.theme;
81+
float border_width = theme.border_width;
82+
float background_inset = theme.inset_border ? border_width
83+
: border_width / 2;
84+
const auto draw_inner_background = [&] {
85+
auto t = ctx.transaction();
86+
ctx.globalAlpha(*opacity / 255.f);
87+
ctx.fillColor(bg_color);
88+
ctx.fillRoundedRect(*x + background_inset, *y + background_inset,
89+
std::max(0.f, *width - background_inset * 2),
90+
std::max(0.f, *height - background_inset * 2),
91+
*radius);
92+
};
93+
7994
{
8095
auto t = ctx.transaction();
8196
ctx.globalAlpha(*opacity / 255.f);
82-
auto &theme = config::current->context_menu.theme;
8397
bool light = is_light_mode();
84-
85-
float border_width = theme.border_width;
8698
// Draw shadow and border
8799
{
88100
float shadow_size = theme.shadow_size,
@@ -126,14 +138,15 @@ void background_widget::render(ui::nanovg_context ctx) {
126138
ctx.globalAlpha(1);
127139
auto cl = nvgRGBAf(0, 0, 0, 1 - *opacity / 255.f);
128140
ctx.fillColor(cl);
129-
if (theme.inset_border)
130-
ctx.fillRoundedRect(*x + border_width, *y + border_width,
131-
*width - border_width * 2,
132-
*height - border_width * 2, *radius);
133-
else
134-
ctx.fillRoundedRect(*x, *y, *width, *height, *radius);
141+
ctx.fillRoundedRect(*x + background_inset, *y + background_inset,
142+
std::max(0.f, *width - background_inset * 2),
143+
std::max(0.f, *height - background_inset * 2),
144+
*radius);
135145
}
136-
bg_impl->render(ctx);
146+
if (render_bg_impl)
147+
bg_impl->render(ctx);
148+
else
149+
draw_inner_background();
137150
super::render(ctx);
138151
}
139152

src/shell/widgets/background_widget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class background_widget : public ui::widget {
2323

2424
private:
2525
bool is_main = false;
26+
bool render_bg_impl = true;
2627
std::shared_ptr<ui::rect_widget> bg_impl;
2728
};
2829

0 commit comments

Comments
 (0)