-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_template.sh
executable file
·83 lines (58 loc) · 1.8 KB
/
make_template.sh
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
prefix="QtC6"
if [ -z $1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Create a basic Widget template based on the first argument given"
echo
echo "usage: $0 [CLASS NAME]"
exit 1
fi
widget_name="$1"
widget_name_lower=$(tr '[:upper:]' '[:lower:]' <<< "$widget_name")
echo "Creating files: \`include/$prefix/${widget_name_lower}.h\` \`lib/${widget_name_lower}.cpp\` \`lib/${widget_name}.zig\`"
echo -e "#pragma once
#include \"private/common.h\"
#include \"widget.h\"
#ifdef __cplusplus
extern \"C\" {
#endif
typedef struct QtC_$widget_name QtC_$widget_name;
QtC_COMMON_DECLS($widget_name);
QtC_${widget_name}* QtC_${widget_name}_new(
QtC_Widget* parent
);
#ifdef __cplusplus
}
#endif" > "include/$prefix/${widget_name_lower}.h"
echo "#include <QtWidgets/Q${widget_name}>
#include <$prefix/private/common.h>
#include <$prefix/${widget_name_lower}.h>
extern \"C\" {
QtC_COMMON_FUNCTIONS($widget_name);
QtC_${widget_name}* QtC_${widget_name}_new(QtC_Widget* parent) {
return QtC_FROM_CLASS($widget_name, new Q${widget_name}(
QtC_TO_CLASS(Widget, parent)
));
}
}" > "lib/${widget_name_lower}.cpp"
echo "const qt = @import(\"qt.zig\");
const c = qt.c;
const $widget_name = @This();
const Widget = qt.widgets.Widget;
pub const InitOptions = struct {
parent: ?*Widget = null,
label: []const u8 = \"\",
};
pub fn init(opts: InitOptions) *$widget_name {
const str = c.QtC_String_new(opts.label.ptr, @intCast(opts.label.len));
defer c.QtC_String_delete(str);
return @ptrCast(c.QtC_${widget_name}_new(
str,
@ptrCast(opts.parent),
));
}
pub fn deinit(self: *$widget_name) void {
c.QtC_${widget_name}_delete(@ptrCast(self));
}
pub fn widget(self: *$widget_name) *Widget {
return @ptrCast(self);
}" > "lib/${widget_name}.zig"