l4l / yofi

yofi is a minimalistic menu for wayland
https://crates.io/crates/yofi
MIT License
376 stars 21 forks source link

Add background border #141

Closed KuabeM closed 1 year ago

KuabeM commented 1 year ago

This adds support for drawing borders around RoundedRect. I added two params bg_border_color and bg_border_width for background in the first commit. The defaults are red and 2.0 which is probably a bad idea. Would you rather disable the border per default? I.e. transparent color and 0.0 width.

The second commit draws the border just on the same path as the actual background. The left side is unfortunately not shown (see picture). I guess it lies just outside the background surface? Do you see a way to still re-use the background path for this?

20230210-111538_grim

I didn't yet add support for borders on the input text, but this would be straightforward. Let me know if what you think about adding it on the input text, too.

Resolves #140

KuabeM commented 1 year ago

Actually, after having a closer look at raqote and arc(), I noticed that just the last piece of the path was missing.. It was fine for filling the surface but the line back to the start point was not part of the path. A simple pb.line_to(x, y + top_left) fixes this.

Anyway, it might still be better to implement your suggestion. What do you think?

KuabeM commented 1 year ago

Some more pictures:

This one has a corner-radius of 8 and a border-width of 2.0 20230215-120820_grim

For more extreme values, it starts to look weird, radius and width of 20.0. The border will eat up space of the inner content.

20230215-120848_grim

l4l commented 1 year ago

Yep, I'm good with this impl. The only thing I don't like is a non-optional border inside RoundedRect. Something like this would be way better imo:

pub struct Border {
    border_color: Color,
    border_width: f32,
}

pub struct RoundedRect {
    radius: Radius,
    color: Color,
    boder: Option<Border>,
}

impl RoundedRect {
    fn new(radius: Radius, color: Color) -> Self { .. }

    fn with_border(self, border: Border) -> Self { Self { border, ..self } }
}

So no need to call stroke for empty border and to modify input_text.rs. Then i guess, the meaningful behavior is to draw some border if at least one of params (color/width) is specified and having Backgrond struct inside background::Params (so defaults are remain in config).

KuabeM commented 1 year ago

Makes sense to me, I tried to follow your suggestion and added a Border with a simple method to add a stroke to a path. Is this what you had in mind?

l4l commented 1 year ago

Looks good to me, thanks for your contribution!