~mil/mepo

b62ea9e1d987bc1cdf30cae40b836b32fcc8c7a1 — Miles Alan 2 years ago ead072e f/wip-table-rendering table-rendering
Use table rendering for pin overlay as well
3 files changed, 19 insertions(+), 18 deletions(-)

M src/Mepo.zig
M src/api/pin_add.zig
M src/types.zig
M src/Mepo.zig => src/Mepo.zig +17 -16
@@ 319,21 319,9 @@ fn blit_pin_active_text(mepo: *@This()) !void {

    const pin = mepo.pin_groups[mepo.pin_group_active].pins.items[mepo.pin_group_active_item.?];
    const d_unit = if (mepo.distance_unit_tf_km_mi) "km" else "mi";
    try mepo.blit_multiline_text(
        0x000000,
        null,
        .{ .align_y = .Center, .h = overlay_height },
        5,
        y_pos,
        null,
        \\Pin: {s}
        \\Coordinates: {d:.5} lat / {d:.5} lon
        \\Distance: {d:.2}{s} away
    ,
        .{
            pin.name,
            pin.lat,
            pin.lon,

    const coords_str = try std.fmt.allocPrintZ(mepo.allocator, "{d:.5} lat / {d:.5} lon", .{pin.lat, pin.lon});
    const distance_str = try std.fmt.allocPrintZ(mepo.allocator, "{d:.2}{s} away", .{
            utilconversion.distance_haversine(
                if (mepo.distance_unit_tf_km_mi) .Km else .Mi,
                mepo.lat,


@@ 342,9 330,22 @@ fn blit_pin_active_text(mepo: *@This()) !void {
                pin.lon,
            ),
            d_unit,
        },
    });

    try mepo.blit_table(
        0x000000,
        0x000000,
        5,
        y_pos,
        500,
        (&[_][2][:0]const u8{
            ([_][:0]const u8{ "Pin:", pin.name, })[0..].*,
            ([_][:0]const u8{ "Coords:", coords_str })[0..].*,
            ([_][:0]const u8{ "Dist:", distance_str  })[0..].*,
        })[0..],
    );


    try mepo.blit_multiline_text(
        0x000000,
        null,

M src/api/pin_add.zig => src/api/pin_add.zig +1 -1
@@ 11,7 11,7 @@ pub fn f_pin_add(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
}

fn pin_add(mepo: *Mepo, lat: f64, lon: f64, is_structural: bool, name: []const u8) !void {
    const name_heap_allocated = try mepo.allocator.dupe(u8, name);
    const name_heap_allocated = try mepo.allocator.dupeZ(u8, name);
    try mepo.pin_groups[mepo.pin_group_active].pins.append(.{
        .lat = lat,
        .lon = lon,

M src/types.zig => src/types.zig +1 -1
@@ 8,7 8,7 @@ pub const XYZ = struct { x: u32, y: u32, z: u8 };
pub const Pin = struct {
    lat: f64,
    lon: f64,
    name: []const u8,
    name: [:0]const u8,
    category: enum { Instructive, Structural } = .Instructive,
};
pub const PinGroup = struct {