Skip to content

Commit

Permalink
Small paint improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongoode committed Feb 14, 2024
1 parent bd1d3d1 commit 7e4d876
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions psst-gui/src/widget/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl<T: Data> Widget<T> for Link<T> {

fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, data: &T, env: &Env) {
if let LifeCycle::HotChanged(_) = event {
ctx.request_anim_frame();
ctx.request_paint();
}
self.inner.lifecycle(ctx, event, data, env)
Expand All @@ -69,37 +70,41 @@ impl<T: Data> Widget<T> for Link<T> {
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env) {
let background = if ctx.is_hot() {
env.get(theme::LINK_HOT_COLOR)
} else {
let is_active = self
let visible_background = (env.get(theme::LINK_HOT_COLOR).as_rgba_u32() >> 24) > 0;
let visible_border = self.border_color.resolve(env).as_rgba_u32() >> 24 > 0
&& self.border_width.resolve(env) > 0.0;

if visible_background || visible_border {
let background = if ctx.is_hot() {
env.get(theme::LINK_HOT_COLOR)
} else if self
.is_active
.as_ref()
.map(|predicate| predicate(data, env))
.unwrap_or(false);
if is_active {
.map(|f| f(data, env))
.unwrap_or(false)
{
env.get(theme::LINK_ACTIVE_COLOR)
} else {
env.get(theme::LINK_COLD_COLOR)
}
};
let border_color = self.border_color.resolve(env);
let border_width = self.border_width.resolve(env);
let visible_background = background.as_rgba_u32() >> 24 > 0;
let visible_border = border_color.as_rgba_u32() >> 24 > 0 && border_width > 0.0;
if visible_background || visible_border {
};

let border_color = self.border_color.resolve(env);
let border_width = self.border_width.resolve(env);
let corner_radius = self.corner_radius.resolve(env);

let rounded_rect = ctx
.size()
.to_rect()
.inset(-border_width / 2.0)
.to_rounded_rect(corner_radius);

if (background.as_rgba_u32() >> 24) > 0 {
ctx.fill(rounded_rect, &background);
}

if visible_border {
ctx.stroke(rounded_rect, &border_color, border_width);
}
if visible_background {
ctx.fill(rounded_rect, &background);
}
}
self.inner.paint(ctx, data, env);
}
Expand Down

0 comments on commit 7e4d876

Please sign in to comment.