capy-ui / capy

💻Build one codebase and get native UI on Windows, Linux and Web
https://capy-ui.org
Mozilla Public License 2.0
1.6k stars 60 forks source link

Unable to create a custom shape in the canvas using lines #88

Open kanajakala opened 1 month ago

kanajakala commented 1 month ago

Hello, I am was trying to create a function that could generate a triangle in the canvas:

fn triangle(ctx: *capy.DrawContext, x: i32, y: i32, size: i16) void {
    ctx.line(x, y, x + size, y);
    ctx.line(x + size, y, x + size, y + size);
    ctx.line(x + size, y + size, x, y);
    ctx.fill();
}

It draws triangles but only as strokes resulting in a hollow shape. I do not know if it's supposed to be that way but maybe removing c.cairo_stroke(self.cr); from

pub fn line(self: *DrawContext, x1: i32, y1: i32, x2: i32, y2: i32) void {
        c.cairo_move_to(self.cr, @as(f64, @floatFromInt(x1)), @as(f64, @floatFromInt(y1)));
        c.cairo_line_to(self.cr, @as(f64, @floatFromInt(x2)), @as(f64, @floatFromInt(y2)));
        c.cairo_stroke(self.cr);
    }

in src/backends/gtk/Canvas.zig could help ? If this a not a solution is there any other way to draw custom shapes in the canvas ? Thanks for creating this awesome library btw :)