dvui icon indicating copy to clipboard operation
dvui copied to clipboard

Simpler Reorderable Lists Api

Open VisenDev opened this issue 6 months ago • 1 comments

The simple reorderable list example still seems quite complex. I struggled to understand the simple and advanced usages in Example.zig

For example, it seems like this function could be automatically generated with comptime, and shouldn't need to be manually written by the user

        pub fn reorder(removed_idx: ?usize, insert_before_idx: ?usize) void {
            if (removed_idx) |ri| {
                if (insert_before_idx) |ibi| {
                    // save this index
                    const removed = strings[ri];
                    if (ri < ibi) {
                        // moving down, shift others up
                        for (ri..ibi - 1) |i| {
                            strings[i] = strings[i + 1];
                        }
                        strings[ibi - 1] = removed;
                    } else {
                        // moving up, shift others down
                        for (ibi..ri, 0..) |_, i| {
                            strings[ri - i] = strings[ri - i - 1];
                        }
                        strings[ibi] = removed;
                    }
                }
            }
        }

It would be really nice to have some reorderable list helper functions which would make this widget much more convenient to use.

For example, something along the lines of

pub fn reorderList(src: std.builtin.SourceLocation, comptime T: type, list_items: []T,  list_item_widget: *fn(src: std.builtin.SourceLocation, item: *T, index: usize) !void) !ReorderableList(T){}

might be possible

VisenDev avatar Aug 21 '24 00:08 VisenDev