mirror of https://git.sr.ht/~kikoodx/kble
46 lines
1.2 KiB
Zig
46 lines
1.2 KiB
Zig
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2021 KikooDX
|
|
// This file is part of [KBLE](https://sr.ht/~kikoodx/kble), which is
|
|
// MIT licensed. The MIT license requires this copyright notice to be
|
|
// included in all copies and substantial portions of the software.
|
|
//! Operates on a scale value used by drawing code.
|
|
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
const maxInt = std.math.maxInt;
|
|
|
|
pub const scale_type = u16;
|
|
pub const scale_default: comptime_int = 16;
|
|
const scale_min: comptime_int = 3;
|
|
const scale_max: comptime_int = maxInt(scale_type);
|
|
|
|
pub fn scale_reset(current_scale: scale_type) scale_type {
|
|
return scale_default;
|
|
}
|
|
|
|
pub fn scale_up(current_scale: scale_type) scale_type {
|
|
if (current_scale < scale_max) {
|
|
return current_scale + 1;
|
|
} else return current_scale;
|
|
}
|
|
|
|
pub fn scale_down(current_scale: scale_type) scale_type {
|
|
if (current_scale > scale_min) {
|
|
return current_scale - 1;
|
|
} else return current_scale;
|
|
}
|
|
|
|
test "scale reset" {
|
|
expect(scale_reset(42) == scale_default);
|
|
}
|
|
|
|
test "scale up" {
|
|
expect(scale_up(42) == 43);
|
|
expect(scale_up(scale_max) == scale_max);
|
|
}
|
|
|
|
test "scale down" {
|
|
expect(scale_down(42) == 41);
|
|
expect(scale_down(scale_min) == scale_min);
|
|
}
|
|
|