~mil/mepo

ref: 4bb3b55aac499ba4f85180006c6b69976c6c0a14 mepo/src/api/prefinc.zig -rw-r--r-- 1.5 KiB
4bb3b55aMiles Alan Move prefrences into global / utilprefs rather then object structure 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utildbg = @import("../util/utildbg.zig");
const utilprefs = @import("../util/utilprefs.zig");

pub const spec = .{
    .name = "prefinc",
    .desc = "Increase or decrease a preference by a given delta value",
    .args = (&[_]types.MepoFnSpecArg{
        .{ .tag = .Text, .name = "prefname", .desc = "Preference name" },
        .{ .tag = .Number, .name = "delta", .desc = "Delta value to increment/decrement (positive or negative)" },
    })[0..],
    .execute = execute,
};

fn execute(_: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    const name = args[0].Text;
    const delta = args[1].Number;

    const val = utilprefs.get(name).u;
    utilprefs.set_n(name, @intToFloat(f64, val) + delta);

    //for (&[_]struct { prop: []const u8, ptr: *u8 }{
    //    .{ .prop = "fontsize_ui", .ptr = &mepo.fontsize_ui },
    //    .{ .prop = "drag_scale", .ptr = &mepo.drag_scale },
    //    .{ .prop = "zoom", .ptr = &mepo.zoom },
    //    .{ .prop = "crosshair_size", .ptr = &mepo.crosshair_size },
    //    .{ .prop = "tile_cache_max_n_transfers", .ptr = &mepo.tile_cache.max_n_transfers },
    //}) |stg| {
    //    if (std.mem.eql(u8, stg.prop, name)) {
    //        if (delta > 0) {
    //            stg.ptr.* +|= @floatToInt(u8, delta);
    //        } else {
    //            stg.ptr.* -|= @intCast(u8, try std.math.absInt(@floatToInt(i8, delta)));
    //        }
    //    }
    //}
}