-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.odin
More file actions
260 lines (182 loc) · 8.46 KB
/
app.odin
File metadata and controls
260 lines (182 loc) · 8.46 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#+feature using-stmt
package main
import "core:fmt"
import "core:mem"
import "base:runtime"
import ui "winforms"
// Global declarations
print :: fmt.println
ptf :: fmt.printf
pgb : ^ui.ProgressBar
tk : ^ui.TrackBar
frm : ^ui.Form
tmr: ^ui.Timer
ti : ^ui.TrayIcon
cmb : ^ui.ComboBox
np1 : ^ui.NumberPicker
lb2 : ^ui.Label
//
cntme : int = 1
cntml : int = 1
MakeWindow :: proc()
{
using ui
frm = new_form( txt = "Odin is fun")
frm.width = 1100
frm.height = 600
// frm.font = new_font("Tahoma", 13)
print_points(frm)
frm.start_pos = .Center //.Mid_Right
create_handle(frm)
// frm.createChilds = true
// Let's create a tray icon.
ti = new_tray_icon("Winforms tray icon!", "winforms-icon.ico")
// frm.onClick = frmClickProc // Show a balloon text when clicking on form.
// // Let's add a context menu for our tray icon. "|" is for separator.
tray_add_context_menu(ti, false, .Any_Click, "Windows", "|", "Linux", "ReactOS")
ti.contextMenu.menus[0].onClick = proc(c: rawptr, ea: ^EventArgs) {print("Windows menu selected")}
timer_ontick :: proc(f: rawptr, e: ^ui.EventArgs) {
print("Timer ticked")
}
// // Let's add a timer to this form which ticks in every 400 ms.
// // And our timer_ontick proc will be called on each tick.
tmr = form_addTimer(frm, 400, timer_ontick)
mbar := new_menubar(frm, false, "File", "Edit", "Format")
// // Add some sub menus. "|" is for separator.
menubar_add_items(mbar, mbar.menus[0], "New Work", "New Client", "|", "Exit")
menubar_add_items(mbar, mbar.menus[1], "New Client", "Copy", "Delete")
menubar_add_items(mbar, mbar.menus[2], "Font", "Line Space", "Para Spce")
menubar_add_items(mbar, mbar.menus[0].menus[0], "Contract Work", "Carriage Work", "Transmission Work")
// mbar.menus[0].menus[1].onClick = newclient_menuclick
mbar.menus[0].menus[1].menuState = .Checked
b1 := new_button(frm, "Normal", 10, 10, 110, 35 )
// b1.onClick = open_file_proc
b2 := new_button(frm, "Flat Color", cright(b1) + 20, 10, 120, 35 )
set_property(b2, CommonProps.Back_Color, 0x94d2bd)
// b2.onClick = b2_click_proc
b3 := new_button(frm, "Gradient", cright(b2) + 20, 10, 110, 35 )
button_set_gradient_colors(b3, 0xfb8500, 0xffbe0b)
cmb := new_combobox(frm, cright(b3) + 20, 10, .Tb_Combo)
// cmb = new_combobox(frm, 530, 390)
combo_add_items(cmb, "Windows", "MacOS", "Linux", "ReactOS")
set_property(cmb, ComboProps.Selected_Index, 0)
dtp := new_datetimepicker(frm, cright(cmb) + 20, 10)
gb := new_groupbox(frm, "Format Options", 10, 80, w=230, h=110) //, style=.Classic)
lb1 := new_label(gb, "Line_Space", 10, 40)
cb := new_checkbox(gb, "Show Timings", 10, 77)
// set_property(lb1, CommonProps.Back_Color, 0xddAA45)
// np1 = new_numberpicker(frm, cright(lb1) + 15, gby(gb, 35), deciPrec = 2, step = 1.5)
np1 = new_numberpicker(gb, 100, 37, 80, 30, deciPrec = 2, step = 1.5)
// np1.foreColor = 0x9d0208
np1.backColor = 0xddAA45
// lb2 = new_label(frm, "pt: ", 80, 280)
// np1.onMouseDown = proc(c: ^ui.Control, ea: ^ui.MouseEventArgs) {
// txt := fmt.tprintf("md X=%d, Y=%d, linex: %d", ea.x, ea.y, np1._lineX)
// ui.control_set_text(lb2, txt)
// }
// control_place_right(np1, lb1, 10)
// lb2 := new_label(frm, "Col Width", gbx(gb, 10), cbottom(lb1) + 12)
// np2 := new_numberpicker(frm, np1.xpos, cbottom(np1) + 15)
gb2 := new_groupbox(frm, "Compiler Options", 10, cbottom(gb) + 20, w = 210, h = 200)
gb2.foreColor = 0x8338ec
cb2 := new_checkbox(gb2, "No Entry Point", 15, 33)
rb1 := new_radiobutton(gb2, "SubSystem:Windows", 15, 65)
rb1.foreColor = 0xd90429
rb2 := new_radiobutton(gb2, "SubSystem:Console", 15, 100)
lb2 := new_label(gb2, "Threads:", 10, 140)
np2 := new_numberpicker(gb2, 80, 140, 80, 28, btnLeft = true)
np2.backColor = 0xcaffbf
np2.textAlignment = .Center
lbx := new_listbox(frm, cright(gb) + 10, cbottom(b1) + 10)
listbox_add_items(lbx, "Windows", "MacOS", "Linux", "ReactOS")
set_property(cb2, CheckBoxProps.Checked, true)
lv := new_listview(frm, cright(lbx) + 10, cbottom(b3) + 10, 340, 150, "Windows", "MacOS", "Linux", 100, 120, 100)
listview_add_row(lv, "XP", "Mountain Lion", "RedHat")
listview_add_row(lv, "Vista", "Mavericks", "Mint")
listview_add_row(lv, "Win7", "Mavericks", "Ubuntu")
listview_add_row(lv, "Win8", "Catalina", "Debian")
listview_add_row(lv, "Win10", " Big Sur", "Kali")
// control_add_contextmenu(lv, false, "Compile", "Link Only", "|", "Make Console")
// lv.contextMenu.menus[0].onClick = contextmenu_click // Handler for "Compile" menu
// lv.contextMenu.menus[0].menuState = MenuState.Checked
// lv.contextMenu._ownDraw = true
tb := new_textbox(frm, 250, 280)
pbx := new_picturebox(frm, cright(gb2) + 10, 328, 270, 180, "gbil.jpg", .Stretch)
pgb = new_progressbar(frm, lv.xpos, cbottom(lv) + 15, lv.width, 30, perc = true)
tk = new_trackbar(frm, lv.xpos, cbottom(pgb) + 20, 200, 50)
tk.customDraw = true
tk.onValueChanged = track_change_proc
tv := new_treeview(frm, cright(lv) + 20, dtp.ypos, 250, 220)
treeview_add_nodes(tv, "Windows", "MacOS", "Linux", "ReactOS")
treeview_add_childnodes(tv, 0, "XP", "Vista", "Win7", "Win8", "Win10", "Win11")
treeview_add_childnodes(tv, 1, "Mountain Lion", "Mavericks", "Catalina", "Big Sur", "Monterey")
treeview_add_childnodes(tv, 2, "RedHat", "Mint", "Ubuntu", "Debian", "Kali")
treeview_add_node_with_children(tv, "BSD", "VersionA", "VersionB", "VersionC")
cal := new_calendar(frm, tv.xpos, cbottom(tv) + 20)
track_change_proc :: proc(c : rawptr, e : ^ui.EventArgs) {
ui.progressbar_set_value(pgb, tk.value)
}
newclient_menuclick :: proc(sender: rawptr, e: ^ui.EventArgs) {
print("New Client selected")
}
contextmenu_click :: proc(sender: rawptr, e: ^ui.EventArgs) {
// ptf("%s option is selected\n", sender.text)
}
open_file_proc :: proc(c : rawptr, e : ^ui.EventArgs) {
ptf("Open File button clicked: %d", context.user_index)
idir : string = "D:\\Work\\Shashikumar\\2023\\Jack Ryan"
ofd := file_open_dialog(initFolder = idir, filterStr = "PDF Files|*.pdf")
// ofd.multiSel = true
x := ui.dialog_show(ofd, frm.handle)
ptf("Dialog result: %s\n", ofd.selectedPath)
dialog_destroy(ofd)
}
b2_click_proc :: proc(c : rawptr, e : ^ui.EventArgs) {
// ui.timer_start(tmr)
print("duuuup")
// ui.print_rcpt(np1._myrc, {0, 0}, "In app odin")
}
frmClickProc :: proc(c: ^ui.Control, ea: ^ui.EventArgs) {
tray_show_balloon(ti, "Winforms", "Info from Winforms", 3000)
}
mep :: proc(c: rawptr, ea: ^ui.EventArgs) {
@static cntme1 : int = 1
ptf("[%d] Mouse entered Numpic", cntme1)
cntme1 += 1
}
mlp :: proc(c: rawptr, ea: ^ui.EventArgs) {
@static cntml1 : int = 1
ptf("[%d] Mouse left from Numpic", cntml1)
cntml1+= 1
}
mhp :: proc(c: rawptr, ea: ^ui.EventArgs) {
@static cntmh1 : int = 1
ptf("[%d] Mouse hovered Numpic", cntmh1)
cntmh1+= 1
}
ui.ctrl_set_mouse_enter_handler(np1, mep)
ui.ctrl_set_mouse_leave_handler(np1, mlp)
ui.ctrl_set_mouse_hover_handler(np1, mhp)
ptf("frm bkg: %X, lb bkg: %X", frm.backColor, lb1.backColor)
start_mainloop(frm)
}
main :: proc()
{
// BOOL1:: distinct i32
// v1 : BOOL1 = 1
// ptf("v1: %32b", v1)
track: mem.Tracking_Allocator
// temp_track: mem.Tracking_Allocator
mem.tracking_allocator_init(&track, context.allocator)
// mem.tracking_allocator_init(&temp_track, context.temp_allocator)
context.allocator = mem.tracking_allocator(&track)
context.user_index = 225
// x := 23
// context.user_ptr = &x
defer mem.tracking_allocator_destroy(&track)
MakeWindow()
ui.show_memory_report(&track)
// print("===================================================================")
// ui.show_memory_report(&temp_track)
// ptf("size of long %d\n", size_of(long))
}