DVUI

addCorner

DO NOT USE this function as a user which you should always use addRect, this should only be used for the internal library

Parameters

#
path:*Builder
*Builder
corner:Corner.Physical
Corner.Physical
rect:Rect.Physical
Rect.Physical
r_cur:Point.Physical
Point.Physical
r_next:Point.Physical
Point.Physical
p:CornerRect.Position
CornerRect.Position

Source

Implementation

#
pub fn addCorner(
        path: *Builder,
        corner: Corner.Physical,
        rect: Rect.Physical,
        r_cur: Point.Physical,
        r_next: Point.Physical,
        comptime p: CornerRect.Position,
    ) void {
        const origin_x: f32, const origin_y: f32 = getCornerOrigin(rect, p);
        const offset_x, const offset_y = getCornerOffset(r_cur, p);

        switch (corner.kind) {
            .round => {
                const pi_start: f32, const pi_end: f32 = switch (p) {
                    .tl => .{ math.pi * 1.5, math.pi },
                    .tr => .{ math.pi * 2.0, math.pi * 1.5 },
                    .bl => .{ math.pi, math.pi * 0.5 },
                    .br => .{ math.pi * 0.5, 0 },
                };
                path.addArc(.{ .x = origin_x + offset_x, .y = origin_y + offset_y }, r_cur.x, pi_start, pi_end, @abs((origin_x + offset_x) - (rect.x + r_next.x)) < 0.5);
            },
            .nudge => path.addPoint(.{ .x = origin_x + offset_x, .y = origin_y + offset_y }),
            .angular, .chamfer => {
                const p_next: CornerRect.Position = switch (p) {
                    .tl => .bl,
                    .bl => .br,
                    .br => .tr,
                    .tr => .tl,
                };
                const origin_x_next, const origin_y_next = getCornerOrigin(rect, p_next);
                const offset_x_next, const offset_y_next = getCornerOffset(r_next, p_next);

                var draw_last = switch (p) {
                    .tl => origin_y + offset_y < origin_y_next + offset_y_next,
                    .bl => origin_x + offset_x < origin_x_next + offset_x_next,
                    .br => origin_y + offset_y > origin_y_next + offset_y_next,
                    .tr => origin_x + offset_x > origin_x_next + offset_x_next,
                };
                draw_last = draw_last and (offset_x != 0 or offset_y != 0);
                switch (p) {
                    .tl, .br => {
                        path.addPoint(.{ .x = origin_x + offset_x, .y = origin_y });
                        if (draw_last) path.addPoint(.{ .x = origin_x, .y = origin_y + offset_y });
                    },
                    .tr, .bl => {
                        path.addPoint(.{ .x = origin_x, .y = origin_y + offset_y });
                        if (draw_last) path.addPoint(.{ .x = origin_x + offset_x, .y = origin_y });
                    },
                }
            },
            .square, .theme => {
                // INFO: .theme shouldn't be unhandled at this stage since there is no way to find the corner
                // INFO: and rect in physical size, thus treated same as the square mode, for now.
                path.addPoint(.{ .x = origin_x, .y = origin_y });
            },
        }
    }