DVUI

defaultFieldOption

Return a default value for a field if no default for that field has been supplied through StructOptions.

Parameters

#
FieldType:type
type

Source

Implementation

#
pub fn defaultFieldOption(FieldType: type) FieldOptions {
            return switch (@typeInfo(FieldType)) {
                .int, .float => .{ .number = .{} },
                .bool => .{ .boolean = .{} },
                // For arrays, pointers and optionals, field_options are set for the child type.
                .pointer => |ptr| if (ptr.size == .slice and ptr.child == u8)
                    .{
                        .text = .{ .display = if (ptr.is_const or ptr.sentinel_ptr != null) .read_only else .read_write },
                    }
                else
                    defaultFieldOption(ptr.child),
                .optional => |opt| defaultFieldOption(opt.child),
                .array => |arr| if (arr.child == u8) .{ .text = .{ .display = .read_only } } else defaultFieldOption(arr.child),
                else => .{ .standard = .{} },
            };
        }