M src/Runtime.zig => src/Runtime.zig +5 -17
@@ 154,13 154,13 @@ fn event_touch_handle(runtime: *@This(), evt_data: linput.input_event) !void {
if (evt_data.code == linput.ABS_MT_POSITION_Y) runtime.pending_touch.?.y = evt_data.value;
if (runtime.pending_touch.?.y < framebuffer.fb_vinfo.yres - h or runtime.pending_touch.?.y > framebuffer.fb_vinfo.yres) return;
- try utilgrid.grid_calculate(runtime.grid(), runtime.dims_cols(), runtime.dims_rows(), 0, config.status_height, w, h, grid_calculate_callback_register_click, runtime);
+ try utilgrid.grid_calculate(runtime.grid(), 0, config.status_height, w, h, grid_calculate_callback_register_click, runtime);
}
if (evt_data.code == linput.ABS_MT_TRACKING_ID and evt_data.value == -1 and runtime.pending_touch != null) {
if (runtime.pending_touch.?.y < framebuffer.fb_vinfo.yres - h or runtime.pending_touch.?.y > framebuffer.fb_vinfo.yres) return;
- try utilgrid.grid_calculate(runtime.grid(), runtime.dims_cols(), runtime.dims_rows(), 0, config.status_height, w, h, grid_calculate_callback_register_click, runtime);
+ try utilgrid.grid_calculate(runtime.grid(), 0, config.status_height, w, h, grid_calculate_callback_register_click, runtime);
runtime.grid_select();
if (runtime.grid_current_index()) |current_index| {
runtime.grid()[current_index].touched = false;
@@ 289,14 289,6 @@ fn refresh_status(runtime: *@This()) !void {
}
}
-fn dims_cols(runtime: *@This()) u32 {
- return if (runtime.submode_normal == .Strings) config.strings_dims_cols else config.keyboard_dims_cols;
-}
-
-fn dims_rows(runtime: *@This()) u32 {
- return if (runtime.submode_normal == .Strings) config.strings_dims_rows else config.keyboard_dims_rows;
-}
-
fn redraw_ui(runtime: *@This()) !void {
comptime {
if (config.strings_paginate > config.strings_dims_cols * config.strings_dims_rows) {
@@ 311,9 303,9 @@ fn redraw_ui(runtime: *@This()) !void {
const s = try std.fmt.allocPrint(runtime.allocator, "/dev/tty{d}: L | {s}", .{ utiltty.current_vt(), runtime.status });
defer runtime.allocator.free(s);
try framebuffer.draw_grid(
- &[_]types.GridItem{.{ .t = "Locked" }},
- 1,
- 1,
+ (&[_][]const types.GridItem{
+ (&[_]types.GridItem{.{ .t = "Locked" }})[0..],
+ })[0..],
0xffcfd4,
s,
);
@@ 323,8 315,6 @@ fn redraw_ui(runtime: *@This()) !void {
defer runtime.allocator.free(s);
try framebuffer.draw_grid(
runtime.grid(),
- runtime.dims_cols(),
- runtime.dims_rows(),
0xc2d7ff,
s,
);
@@ 334,8 324,6 @@ fn redraw_ui(runtime: *@This()) !void {
defer runtime.allocator.free(s);
try framebuffer.draw_grid(
runtime.grid(),
- runtime.dims_cols(),
- runtime.dims_rows(),
0xc7ffdf,
s,
);
M src/interfaces/framebuffer.zig => src/interfaces/framebuffer.zig +2 -4
@@ 90,7 90,7 @@ pub fn draw_text(x: usize, y: usize, w: usize, h: usize, text: []const u8, fonts
}
}
-pub fn draw_grid_item(x: u32, y: u32, w: u32, h: u32, item: types.GridItem, item_i: usize, unused: anytype) !bool {
+pub fn draw_grid_item(x: u32, y: u32, w: u32, h: u32, item: types.GridItem, unused: anytype) !bool {
// Bg
var color: u24 = undefined;
if (item.touched) {
@@ 120,15 120,13 @@ pub fn draw_grid_item(x: u32, y: u32, w: u32, h: u32, item: types.GridItem, item
return true;
}
-pub fn draw_grid(items: []const types.GridItem, cols: u32, rows: u32, status_color: u24, status_r: []const u8) !void {
+pub fn draw_grid(items: []const []const types.GridItem, status_color: u24, status_r: []const u8) !void {
// Clear
std.mem.set(types.Pixel, buffer, types.Pixel.from_u24(0xffffff));
// Grid item
try utilgrid.grid_calculate(
items,
- cols,
- rows,
0,
config.status_height,
fb_vinfo.xres,
M src/util/utilgrid.zig => src/util/utilgrid.zig +21 -14
@@ 1,21 1,28 @@
const types = @import("../types.zig");
-pub fn grid_calculate(items: []const types.GridItem, cols: u32, rows: u32, x_off: u32, y_off: u32, w_total: u32, h_total: u32, comptime callback: fn run(x: u32, y: u32, w_total: u32, h_total: u32, item: types.GridItem, item_i: usize, userdata: anytype) anyerror!bool, userdata: anytype) !void {
- const w_u1 = w_total / cols;
- const h_u1 = h_total / rows;
+pub fn grid_calculate(items: []const []const types.GridItem, x_off: u32, y_off: u32, w_total: u32, h_total: u32, comptime callback: fn run(x: u32, y: u32, w_total: u32, h_total: u32, item: types.GridItem, userdata: anytype) anyerror!bool, userdata: anytype) !void {
+ const n_cols = calcd_ncols: {
+ var n : u32 = 0;
+ for (items[0]) |item| n += item.span;
+ break :calcd_ncols n;
+ };
+ const w_u1 : u32 = w_total / n_cols;
+ const h_u1 : u32 = h_total / @intCast(u32, items.len);
var item_i: u32 = 0;
- for (items) |item, item_index| {
- defer {
- item_i += item.span;
- }
- const row_n = item_i / cols;
- const col_n = item_i % cols;
- const x = col_n * w_u1;
- const y = row_n * h_u1;
- const w = w_u1 * item.span;
+ for (items) |row, row_index| {
+ for (row) |col, col_index| {
+ defer {
+ item_i += col.span;
+ }
+ const row_n = item_i / n_cols;
+ const col_n = item_i % n_cols;
+ const x = col_n * w_u1;
+ const y = row_n * h_u1;
+ const w = w_u1 * col.span;
- if (!try callback(x + x_off, y + y_off, w, h_u1, item, item_index, userdata)) {
- return;
+ if (!try callback(x + x_off, y + y_off, w, h_u1, col, userdata)) {
+ return;
+ }
}
}
}