diff --git a/README.md b/README.md index 46581ae..92b861c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,6 @@ | IDE | Disk | RAM | |---------|---------|---------| | | | | -| Vide | < 5MB | ~ 60MB | +| Vide | < 5MB | ~ 70MB | | VS Code | 300MB | ~ 300MB | | | | | diff --git a/src/code_suggest.v b/src/code_suggest.v index 2c1f40e..fdba202 100644 --- a/src/code_suggest.v +++ b/src/code_suggest.v @@ -370,8 +370,8 @@ fn find_all_fn_in_vlib(mut win ui.Window, mod string) []string { } fn get_v_exe(win &ui.Window) string { - mut conf := get_config(win) - mut saved := conf.get_value('v_exe').replace('\{user_home}', '~') + mut saved := config.get_value('v_exe').replace('\{user_home}', '~') + dump(saved) saved = saved.replace('~', os.home_dir().replace('\\', '/')) if saved.len <= 0 { @@ -383,8 +383,8 @@ fn get_v_exe(win &ui.Window) string { vexe = os.environ()['VEXE'].replace('\\', '/') } vexe = vexe.replace(os.home_dir().replace('\\', '/'), '~') - conf.set('v_exe', vexe) - conf.save() + config.set('v_exe', vexe) + config.save() return vexe } else { return saved diff --git a/src/config.v b/src/config.v index e0e9034..7b01964 100644 --- a/src/config.v +++ b/src/config.v @@ -10,6 +10,7 @@ const ( 'workspace_dir = ~/vide/workspace', 'v_flags = -skip-unused', ].join_lines() + config = make_config() ) // Make Config as a 'Fake' Component @@ -19,17 +20,14 @@ pub mut: conf map[string]string } -fn config(mut win ui.Window) &Config { - mut config := &Config{} - config.set_id(mut win, 'vide-config') - win.add_child(config) - config.read() - return config +fn make_config() &Config { + mut conf := &Config{} + conf.read() + return conf } fn get_config(win &ui.Window) &Config { - conf := win.get_from_id('vide-config') - return &Config(conf) + return config } fn (mut this Config) read() { @@ -52,14 +50,16 @@ fn (mut this Config) read() { ui.debug('Vide: Loaded config.') } -fn (mut this Config) get_value(key string) string { +fn (this &Config) get_value(key string) string { if key in this.conf { return this.conf[key] } else { for line in default_config.split_into_lines() { if line.starts_with(key) { spl := line.split('=') - this.conf[spl[0].trim_space()] = spl[1].trim_space() + unsafe { + this.conf[spl[0].trim_space()] = spl[1].trim_space() + } return spl[1].trim_space() } } @@ -67,11 +67,13 @@ fn (mut this Config) get_value(key string) string { return '' } -fn (mut this Config) set(key string, val string) { - this.conf[key] = val +fn (this &Config) set(key string, val string) { + unsafe { + this.conf[key] = val + } } -fn (mut this Config) save() { +fn (this &Config) save() { mut con := '# Vide Configuration\n# Last Modified: ' + time.now().str() for key, val in this.conf { con = con + '\n' + key + ' = ' + val diff --git a/src/draw_events.v b/src/draw_events.v index c877ea5..f37279e 100644 --- a/src/draw_events.v +++ b/src/draw_events.v @@ -82,7 +82,7 @@ fn on_draw(mut win ui.Window, mut tb ui.Component) { mut spv := &ui.SplitView(win.get_from_id('spv')) spv.width = width - height := ws.height - spv.y - 5 + height := ws.height - spv.y - 1 if spv.height != height { spv.height = height diff --git a/src/ide.v b/src/ide.v index 55fa828..4fd2fd2 100644 --- a/src/ide.v +++ b/src/ide.v @@ -6,7 +6,7 @@ import os import hc const ( - version = '0.0.13-dev' + version = '0.0.14-dev' ) struct App { @@ -35,17 +35,15 @@ fn main() { ui_mode: false ) - mut conf := config(mut window) - mut app := &App{ win: window - conf: conf + conf: config } // our custom config get_v_exe(window) - fs := conf.get_value('font_size') + fs := config.get_value('font_size') if fs.len > 0 { window.font_size = fs.int() } @@ -56,7 +54,7 @@ fn main() { // Set Saved Theme app.set_theme_from_save() - workd := conf.get_value('workspace_dir').replace('\{user_home}', '~').replace('\\', + workd := config.get_value('workspace_dir').replace('\{user_home}', '~').replace('\\', '/') // ' folder := os.expand_tilde_to_home(workd).replace('~', os.home_dir()) @@ -83,7 +81,7 @@ fn main() { if 'font_load' !in win.extra_map { download_jbm() mut conf := get_config(win) - saved_font := conf.get_value('main_font') + saved_font := config.get_value('main_font') if saved_font.len > 0 { font := win.add_font('Saved Font', saved_font) win.graphics_context.font = font @@ -103,7 +101,6 @@ fn main() { mut console_box := create_box(window) console_box.z_index = 2 console_box.set_id(mut window, 'consolebox') - // window.add_child(console_box) mut sv := ui.scroll_view( view: console_box @@ -122,7 +119,7 @@ fn main() { h1: 70 h2: 20 bounds: ui.Bounds{ - y: 28 + y: 30 x: 4 } ) @@ -143,9 +140,9 @@ fn main() { fn setup_tree(mut window ui.Window, folder string) &ui.Tree2 { mut tree2 := ui.tree2('Projects') - tree2.set_bounds(4, 28, 300, 200) + tree2.set_bounds(4, 30, 300, 200) tree2.draw_event_fn = fn (mut win ui.Window, mut tree ui.Component) { - tree.height = gg.window_size().height - 30 + tree.height = gg.window_size().height - 32 } files := os.ls(folder) or { [] } diff --git a/src/menus.v b/src/menus.v index c1da5dd..7837681 100644 --- a/src/menus.v +++ b/src/menus.v @@ -119,9 +119,8 @@ fn (mut app App) set_theme_from_save() { fn on_theme_click(mut win ui.Window, com ui.MenuItem) { theme := ui.theme_by_name(com.text) - mut conf := get_config(win) - conf.set('theme', com.text) - conf.save() + config.set('theme', com.text) + config.save() win.set_theme(theme) } diff --git a/src/new_file.v b/src/new_file.v index 4f8e88a..cccb272 100644 --- a/src/new_file.v +++ b/src/new_file.v @@ -24,9 +24,7 @@ fn new_file_click(mut win ui.Window, com ui.MenuItem) { mut fold_btn := ui.button(text: 'Pick Directory') fold_btn.set_click_fn(fn (a voidptr, b voidptr, c voidptr) { - mut win := &ui.Window(a) - mut conf := get_config(win) - dir := conf.get_value('workspace_dir').replace('\{user_home}', os.real_path(os.home_dir())) + dir := config.get_value('workspace_dir').replace('\{user_home}', os.real_path(os.home_dir())) /* path_change_fn := file_picker_path_change @@ -63,8 +61,7 @@ fn new_file_click(mut win ui.Window, com ui.MenuItem) { close.set_click(fn (mut win ui.Window, btn ui.Button) { name := win.extra_map['nf-name'] pdir := win.extra_map['nf-dir'] - mut conf := get_config(win) - dir := conf.get_value('workspace_dir').replace('\{user_home}', os.real_path(os.home_dir())) + dir := config.get_value('workspace_dir').replace('\{user_home}', os.real_path(os.home_dir())) os.write_file(pdir + '/' + name, '') or {} diff --git a/src/new_proj.v b/src/new_proj.v index 17396e0..78bf961 100644 --- a/src/new_proj.v +++ b/src/new_proj.v @@ -37,17 +37,19 @@ fn new_project_click(mut win ui.Window, com ui.MenuItem) { mut close := ui.button(text: 'Create') close.set_bounds(86, 255, 145, 25) - mut can := ui.button(text: 'Cancel') - can.set_bounds(20, 255, 60, 25) - can.set_click(fn (mut win ui.Window, btn ui.Button) { - win.components = win.components.filter(mut it !is ui.Modal) + mut can := ui.button( + text: 'Cancel' + bounds: ui.Bounds{20, 255, 60, 25} + ) + can.subscribe_event('mouse_up', fn (mut e ui.MouseEvent) { + e.ctx.win.components = e.ctx.win.components.filter(mut it !is ui.Modal) }) modal.add_child(can) close.set_click(fn (mut win ui.Window, btn ui.Button) { - name := &ui.TextField(win.get_from_id('NewProj-Name')).text - des := &ui.TextField(win.get_from_id('NewProj-Description')).text - ver := &ui.TextField(win.get_from_id('NewProj-Version')).text + name := win.get[&ui.TextField]('NewProj-Name').text + des := win.get[&ui.TextField]('NewProj-Description').text + ver := win.get[&ui.TextField]('NewProj-Version').text lic := win.extra_map['np-lic'] dir := win.extra_map['workspace'] @@ -57,7 +59,7 @@ fn new_project_click(mut win ui.Window, com ui.MenuItem) { win.components = win.components.filter(mut it !is ui.Modal) - mut com := &ui.Tree2(win.get_from_id('proj-tree')) + mut com := win.get[&ui.Tree2]('proj-tree') refresh_tree(mut win, dir, mut com) }) @@ -74,7 +76,7 @@ fn create_input(mut win ui.Window, mut vbox ui.VBox, title string, x int, y int) work_lbl.pack() vbox.add_child(work_lbl) - mut work := ui.textfield(win, '') + mut work := ui.text_field(text: '') work.draw_event_fn = fn (mut win ui.Window, mut work ui.Component) { work.width = int(f64_max(200, ui.text_width(win, work.text) + work.text.len)) work.height = ui.text_height(win, 'A{0|') + 8 diff --git a/src/settings.v b/src/settings.v index d496cf0..8455e10 100644 --- a/src/settings.v +++ b/src/settings.v @@ -27,8 +27,7 @@ fn settings_click(mut win ui.Window, com ui.MenuItem) { modal.add_child(can) close.set_click(fn (mut win ui.Window, btn ui.Button) { - mut conf := get_config(win) - conf.save() + config.save() win.components = win.components.filter(mut it !is ui.Page) }) @@ -39,11 +38,9 @@ fn settings_click(mut win ui.Window, com ui.MenuItem) { } win.id_map['setting_box'] = vbox - mut conf := get_config(win) - - general_section(win, mut conf, mut vbox) - appearance_section(win, mut conf, mut vbox) - cloud_section(win, mut conf, mut vbox) + general_section(win, mut vbox) + appearance_section(win, mut vbox) + cloud_section(win, mut vbox) // Spacer spacer := title_label(win, ' ') @@ -71,41 +68,38 @@ fn title_label(win &ui.Window, text string) &ui.Label { return &lbl } -fn cloud_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { +fn cloud_section(win &ui.Window, mut vbox ui.VBox) { mut box := ui.vbox(win) box.set_pos(16, 0) - mut lbl := ui.label(win, 'Server URL') - mut field := ui.text_field(text: 'http://TODO-Comingsoon.linodeusercontent.com/') - lbl.set_bounds(8, 8, 200, 25) - lbl.pack() - field.set_bounds(8, 4, 400, 30) - box.add_child(lbl) - box.add_child(field) + mut field := ui.text_field(text: 'TODO ') + field.set_bounds(8, 0, 400, 30) + + mut fb := ui.title_box('Server URL', [field]) + box.add_child(fb) mut tb := ui.title_box('Cloud Compile (*Coming soon*)', [box]) tb.set_bounds(0, 16, 600, 25) vbox.add_child(tb) } -fn general_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { +fn general_section(win &ui.Window, mut vbox ui.VBox) { mut work_lbl := ui.label(win, 'Workspace Location') work_lbl.pack() - workd := os.real_path(conf.get_value('workspace_dir').replace('\{user_home}', '~')) + workd := os.real_path(config.get_value('workspace_dir').replace('\{user_home}', '~')) folder := os.expand_tilde_to_home(workd) - mut work := ui.textfield(win, folder) - mut dialog_btn := ui.button(text: 'Choose Folder') + mut work := ui.text_field(text: folder) + mut dialog_btn := ui.button(text: 'Pick Folder') work.draw_event_fn = fn (mut win ui.Window, mut work ui.Component) { work.width = math.max(ui.text_width(win, work.text + 'a b'), 300) work.height = win.graphics_context.line_height + 8 } work.text_change_event_fn = fn (a voidptr, b voidptr) { - mut conf := get_config(&ui.Window(a)) work := &ui.TextField(b) - conf.set('workspace_dir', work.text.replace(os.home_dir().replace('\\', '/'), + config.set('workspace_dir', work.text.replace(os.home_dir().replace('\\', '/'), '~')) // ' } @@ -123,8 +117,7 @@ fn general_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { mut win := &ui.Window(win_ptr) work := &ui.TextField(box_ptr) - mut conf := get_config(win) - conf.set('v_exe', work.text.replace(os.home_dir().replace('\\', '/'), '~')) // ' + config.set('v_exe', work.text.replace(os.home_dir().replace('\\', '/'), '~')) // ' } work_lbl.set_bounds(32, 8, 0, 0) @@ -150,7 +143,7 @@ fn general_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { '~')) // ' } }, work)*/ - dialog_btn.set_pos(4, 0) + dialog_btn.set_pos(2, 0) dialog_btn.pack() hbox.add_child(work) @@ -167,30 +160,36 @@ fn general_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { vbox.add_child(tb) } -fn create_font_slider(win &ui.Window) &ui.VBox { - mut fs_lbl := ui.label(win, 'Font size:') - fs_lbl.set_bounds(4, 4, 100, 20) - fs_lbl.draw_event_fn = fn (mut win ui.Window, mut lbl ui.Component) { - lbl.text = 'Font Size (' + win.font_size.str() + '):' - lbl.width = ui.text_width(win, lbl.text) - } +fn create_font_slider(win &ui.Window) &ui.Titlebox { + mut vbox := ui.hbox(win) + vbox.set_bounds(4, 0, 140, 37) - mut font_slider := ui.slider(win, 0, 28, .hor) - font_slider.set_bounds(4, 4, 100, 25) - font_slider.cur = win.font_size - 10 - font_slider.draw_event_fn = font_slider_draw + mut field := ui.numeric_field(win.font_size) + field.set_bounds(4, 0, 90, 35) + vbox.add_child(field) - mut vbox := ui.vbox(win) - vbox.set_pos(16, 0) - vbox.add_child(fs_lbl) - vbox.add_child(font_slider) + mut btn := ui.button( + text: 'Set' + bounds: ui.Bounds{2, 0, 40, 35} + ) + btn.parent = &ui.Component_A(field) + btn.subscribe_event('mouse_up', fn (mut e ui.MouseEvent) { + txt := e.target.parent.text + e.ctx.win.font_size = txt.int() + e.ctx.font_size = txt.int() + config.set('font_size', txt) + }) + vbox.add_child(btn) - return vbox + mut tb := ui.title_box('Font Size', [vbox]) + tb.set_pos(16, 0) + + return tb } fn tree_padding_slider_draw(mut win ui.Window, com &ui.Component) { mut this := *com - mut tree := &ui.Tree2(win.get_from_id('proj-tree')) + mut tree := win.get[&ui.Tree2]('proj-tree') if mut this is ui.Slider { fs := tree.width new_val := (int(this.cur) * 10) + 100 @@ -202,46 +201,24 @@ fn tree_padding_slider_draw(mut win ui.Window, com &ui.Component) { } } -fn font_slider_draw(mut win ui.Window, com &ui.Component) { - mut this := *com - if mut this is ui.Slider { - fs := win.font_size - new_val := int(this.cur) + 10 - if fs == new_val { - return - } - - mut conf := get_config(win) - conf.set('font_size', new_val.str()) - - win.font_size = new_val - } -} - -fn create_tree_width_slider(win &ui.Window) &ui.VBox { - mut tree_padding_lbl := ui.label(win, 'Project Tree Padding') - tree_padding_lbl.set_bounds(4, 4, 100, 20) - tree_padding_lbl.draw_event_fn = fn (mut win ui.Window, mut lbl ui.Component) { - tree := &ui.Tree2(win.get_from_id('proj-tree')) - lbl.text = 'Project Tree Width (${tree.width}):' - lbl.width = ui.text_width(win, lbl.text) - } - +fn create_tree_width_slider(win &ui.Window) &ui.Titlebox { mut tree_padding_slider := ui.slider(win, 0, 30, .hor) tree_padding_slider.set_bounds(8, 8, 100, 25) - tree := &ui.Tree2(win.get_from_id('proj-tree')) + tree := win.get[&ui.Tree2]('proj-tree') tree_padding_slider.cur = (tree.width - 100) / 10 tree_padding_slider.draw_event_fn = tree_padding_slider_draw - mut vbox := ui.vbox(win) - vbox.set_pos(16, 0) - vbox.add_child(tree_padding_lbl) - vbox.add_child(tree_padding_slider) + mut tb := ui.title_box('File Tree Width', [tree_padding_slider]) + tb.subscribe_event('draw', fn (mut e ui.DrawEvent) { + tree := e.ctx.win.get[&ui.Tree2]('proj-tree') + e.target.text = 'File Tree Width (${tree.width}):' + }) + tb.set_bounds(16, 0, 200, 30) - return vbox + return tb } -fn appearance_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { +fn appearance_section(win &ui.Window, mut vbox ui.VBox) { font_size_box := create_font_slider(win) tree_padding_box := create_tree_width_slider(win) @@ -253,16 +230,8 @@ fn appearance_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { hbox.set_bounds(0, 0, 500, 100) hbox.parent = vbox - // hbox.pack() - - font_lbl := ui.label(win, 'Main Font', ui.LabelConfig{ - x: 24 - y: 16 - should_pack: true - }) - mut font_box := ui.selector(win, 'Font', ui.SelectConfig{ - bounds: ui.Bounds{24, 2, 250, 35} + bounds: ui.Bounds{8, 2, 200, 35} items: [ 'Default Font', 'Anomaly Mono', @@ -275,13 +244,17 @@ fn appearance_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { mut box := ui.vbox(win) box.add_child(hbox) - box.add_child(font_lbl) - box.add_child(font_box) + + mut fb := ui.title_box('Main Font', [font_box]) + fb.set_pos(16, 8) + + box.add_child(fb) mut tb := ui.title_box('Appearance', [box]) tb.set_bounds(0, 16, 600, 100) box.subscribe_event('draw', fn [mut tb] (mut e ui.DrawEvent) { - mut sb := e.target.children[2] + mut fb := e.target.children[1] + mut sb := fb.children[0] if mut sb is ui.Select { mut hei := 0 for ch in e.target.children { @@ -289,9 +262,11 @@ fn appearance_section(win &ui.Window, mut conf Config, mut vbox ui.VBox) { } if sb.show_items { - hei += (sb.items.len + 1) * sb.sub_height + subs := (sb.items.len + 1) * sb.sub_height + fb.height = subs + (e.ctx.line_height * 2) + } else { + fb.height = sb.height } - e.target.height = hei tb.height = hei } }) @@ -319,8 +294,7 @@ fn sel_change(mut win ui.Window, com ui.Select, old_val string, new_val string) font := win.add_font(new_val, path) win.graphics_context.font = font - mut conf := get_config(win) - conf.set('main_font', path) + config.set('main_font', path) } // Downloads JetBrainsMono diff --git a/src/settings_old.v b/src/settings_old.v index c6a32fa..d9caa5a 100644 --- a/src/settings_old.v +++ b/src/settings_old.v @@ -1,222 +1,26 @@ module main import iui as ui -import os -import math fn settings_click_old(mut win ui.Window, com ui.MenuItem) { mut modal := ui.page(win, 'Settings') - // modal.top_off = 16 - // modal.in_width = 600 - // modal.in_height = 355 mut tb := ui.tabbox(win) tb.closable = false - mut vbox := ui.vbox(win) - - mut work_lbl := ui.label(win, 'Workspace Location') - work_lbl.pack() - - mut conf := get_config(win) - - workd := os.real_path(conf.get_value('workspace_dir').replace('\{user_home}', '~')) - folder := os.expand_tilde_to_home(workd) - - mut work := ui.textfield(win, folder) - mut dialog_btn := ui.button(text: 'Choose Folder') - /* - work.draw_event_fn = fn [dialog_btn_ref] (mut win ui.Window, mut work ui.Component) { - work.width = math.max(ui.text_width(win, work.text + 'a b'), 300) - work.height = dialog_btn_ref.height // ui.text_height(win, 'A{0|') + 8 - }*/ - work.text_change_event_fn = fn (a voidptr, b voidptr) { - mut conf := get_config(&ui.Window(a)) - work := &ui.TextField(b) - conf.set('workspace_dir', work.text.replace(os.home_dir().replace('\\', '/'), - '~')) // ' - } - - mut lib_lbl := ui.label(win, 'Path to VEXE') - lib_lbl.pack() - - home := os.home_dir().replace('\\', '/') // ' - mut vlib := ui.textfield(win, get_v_exe(win).replace(home, '~')) - - vlib.draw_event_fn = fn (mut win ui.Window, mut work ui.Component) { - work.width = math.max(250, ui.text_width(win, work.text + 'a b')) - work.height = win.graphics_context.line_height + 10 - } - vlib.text_change_event_fn = fn (win_ptr voidptr, box_ptr voidptr) { - mut win := &ui.Window(win_ptr) - work := &ui.TextField(box_ptr) - - mut conf := get_config(win) - conf.set('v_exe', work.text.replace(os.home_dir().replace('\\', '/'), '~')) // ' - } - - work_lbl.set_bounds(0, 8, 0, 0) - lib_lbl.set_bounds(0, 8, 0, 0) - work.set_bounds(8, 0, 0, 0) - vlib.set_bounds(8, 4, 0, 0) - - mut hbox := ui.hbox(win) - hbox.set_pos(0, 4) - hbox.pack() - - /* - dialog_btn.set_click_fn(fn [mut work] (a voidptr, b voidptr, c voidptr) { - val := dialogs.select_folder_dialog('Select Workspace Directory', work.text) - if val.len > 0 && os.exists(val) { - work.text = val - - mut win := &ui.Window(a) - mut conf := get_config(win) - conf.set('workspace_dir', work.text.replace(os.home_dir().replace('\\', '/'), - '~')) // ' - } - }, 0)*/ - dialog_btn.set_pos(4, 0) - dialog_btn.pack() - - hbox.add_child(work) - hbox.add_child(dialog_btn) - - vbox.set_bounds(16, 16, 0, 0) - vbox.add_child(work_lbl) - vbox.add_child(hbox) - vbox.add_child(lib_lbl) - vbox.add_child(vlib) - - tb.add_child('General', vbox) - - settings_flags(win, mut conf, tb) - appearance_tab(win, mut conf, tb) - - // fs_group(win, 20, 170, tb) - modal.needs_init = false - mut close := ui.button(text: 'Save & Done') - close.set_bounds(425, modal.in_height - 42, 160, 30) - - mut can := ui.button(text: 'Cancel') - can.set_bounds(330, modal.in_height - 42, 85, 30) - can.set_click(fn (mut win ui.Window, btn ui.Button) { - win.components = win.components.filter(mut it !is ui.Page) - }) - modal.add_child(can) - - close.set_click(fn (mut win ui.Window, btn ui.Button) { - mut conf := get_config(win) - conf.save() - win.components = win.components.filter(mut it !is ui.Page) - }) + settings_flags(win, mut tb) tb.draw_event_fn = fn (mut win ui.Window, mut com ui.Component) { ui.set_bounds(mut com, 70, 10, 1920, 1080) } - /* - tb.draw_event_fn = fn [modal, mut tb, mut can_btn, mut close_btn] (win &ui.Window, mut com ui.Component) { - tb.set_bounds(70, 10, modal.width - 140, modal.height - modal.top_off - 99) - - ctx := win.graphics_context - tb.tab_height_active = ctx.line_height * 2 - tb.tab_height_inactive = ctx.line_height * 2 - tb.inactive_offset = -1 - tb.active_offset = -4 - - btn_y := modal.height - 68 - modal.top_off - btn_x := modal.width - 320 - - can_btn.set_bounds(btn_x, btn_y, 85, 35) - close_btn.set_bounds(btn_x + 99, btn_y, 165, 35) - }*/ - - modal.add_child(close) modal.add_child(tb) win.add_child(modal) } -fn appearance_tab(win &ui.Window, mut conf Config, tbp voidptr) { - mut tb := &ui.Tabbox(tbp) - - mut vbox := ui.vbox(win) - - fs_lbl, font_slider := make_font_slider(win) - tree_padding_lbl, tree_padding_slider := make_tree_width_slider(win) - - vbox.add_child(fs_lbl) - vbox.add_child(font_slider) - vbox.add_child(tree_padding_lbl) - vbox.add_child(tree_padding_slider) - - font_lbl := ui.label(win, 'Main Font', ui.LabelConfig{ - x: 16 - y: 16 - should_pack: true - }) - vbox.add_child(font_lbl) - - mut font_box := ui.selector(win, 'Font', ui.SelectConfig{ - bounds: ui.Bounds{16, 8, 250, 35} - items: [ - 'Default Font', - 'Anomaly Mono', - 'KARISMA_', - 'Agave-Regular', - 'JetBrainsMono-Regular', - 'System SegoeUI', - ] - }) - font_box.set_change(sel_change) - - vbox.add_child(font_box) - - tb.add_child('Appearance', vbox) -} - -fn make_tree_width_slider(win &ui.Window) (ui.Label, &ui.Slider) { - mut tree_padding_lbl := ui.label(win, 'Project Tree Padding') - tree_padding_lbl.set_bounds(32, 16, 300, 20) - tree_padding_lbl.draw_event_fn = fn (mut win ui.Window, mut lbl ui.Component) { - tree := &ui.Tree2(win.get_from_id('proj-tree')) - lbl.text = 'Project Tree Width (${tree.width}):' - lbl.width = ui.text_width(win, lbl.text) - } - - mut tree_padding_slider := ui.slider(win, 0, 30, .hor) - tree_padding_slider.set_bounds(32, 4, 100, 20) - tree := &ui.Tree2(win.get_from_id('proj-tree')) - tree_padding_slider.cur = (tree.width - 100) / 10 - tree_padding_slider.draw_event_fn = tree_padding_slider_draw - return tree_padding_lbl, tree_padding_slider -} - -fn make_font_slider(win &ui.Window) (ui.Label, &ui.Slider) { - mut fs_lbl := ui.label(win, 'Font size:') - fs_lbl.set_bounds(32, 16, 300, 20) - fs_lbl.draw_event_fn = fn (mut win ui.Window, mut lbl ui.Component) { - lbl.text = 'Font Size (' + win.font_size.str() + '):' - lbl.width = ui.text_width(win, lbl.text) - } - - mut font_slider := ui.slider(win, 0, 28, .hor) - font_slider.set_bounds(32, 4, 200, 20) - font_slider.cur = win.font_size - 10 - font_slider.draw_event_fn = font_slider_draw - return fs_lbl, font_slider -} - -fn settings_flags(win &ui.Window, mut conf Config, tbp voidptr) { - mut tb := &ui.Tabbox(tbp) - +fn settings_flags(win &ui.Window, mut tb ui.Tabbox) { mut flag_lbl := ui.label(win, 'Compiler Flags') flag_lbl.set_bounds(20, 20, 300, 30) - flag_lbl.draw_event_fn = fn (mut win ui.Window, mut lbl ui.Component) { - lbl.width = ui.text_width(win, lbl.text) - } - - tb.add_child('Compiler', flag_lbl) mut vbox := ui.vbox(win) vbox.set_bounds(20, 50, 600, 600) @@ -225,28 +29,30 @@ fn settings_flags(win &ui.Window, mut conf Config, tbp voidptr) { flags := ['-skip-unused', '-gc boehm', '-compress', '-cflags -static', '-prod'] for flag in flags { - flag_com := create_flag_check(win, flag, mut conf) + flag_com := create_flag_check(win, flag) vbox.add_child(flag_com) } + tb.add_child('Compiler', flag_lbl) tb.add_child('Compiler', vbox) } -fn create_flag_check(win &ui.Window, text string, mut conf Config) ui.Checkbox { - mut gc := ui.checkbox(win, text) - gc.is_selected = conf.get_value('v_flags').contains(text) - gc.set_bounds(0, 8, 100, 20) +fn create_flag_check(win &ui.Window, text string) &ui.Checkbox { + mut gc := ui.check_box( + text: text + bounds: ui.Bounds{0, 8, 100, 20} + ) + gc.is_selected = config.get_value('v_flags').contains(text) gc.set_click(check_click) return gc } fn check_click(mut win ui.Window, box ui.Checkbox) { - mut conf := get_config(win) - mut valu := conf.get_value('v_flags') + mut valu := config.get_value('v_flags') if valu.contains(box.text) { valu = valu.replace(box.text, '') } else { valu = valu + ' ' + box.text } - conf.set('v_flags', valu.trim_space()) + config.set('v_flags', valu.trim_space()) } diff --git a/src/v_install.v b/src/v_install.v index 1ddca80..d266d8c 100644 --- a/src/v_install.v +++ b/src/v_install.v @@ -28,6 +28,12 @@ fn show_install_modal(mut win ui.Window, com ui.MenuItem) { mut modal := ui.modal(win, 'V Manager (Non-finished Test)') + $if debug ? { + show_install_info(win, mut modal, v_ver) + win.add_child(modal) + return + } + if v_found { show_installed_info(win, mut modal, v_ver) } else { @@ -54,7 +60,7 @@ fn show_installed_info(win &ui.Window, mut modal ui.Modal, data string) { // If V not found fn show_install_info(win &ui.Window, mut modal ui.Modal, data string) { - logo := &gg.Image(win.id_map['vide_logo1']) + logo := win.get[&gg.Image]('vide_logo1') modal.text = 'Vide Setup: Install V' modal.in_width = 600 @@ -64,7 +70,8 @@ fn show_install_info(win &ui.Window, mut modal ui.Modal, data string) { mut logo_im := ui.image(win, logo) logo_im.set_bounds((modal.in_width - 230) / 2, 20, 230, 90) - lbl_txt := 'Welcome to Vide!\nUnfortunately, Vide was unable to find the V compiler executable.\n\nWould you like to download V, or configure in Settings later' + // lbl_txt := 'Welcome to Vide!\nUnfortunately, Vide was unable to find the path to V.\n\nWould you like to download V, or configure in Settings later' + lbl_txt := 'Welcome to Vide!\nUnfortunately, Vide was unable to find the path to V.\n\nPlease configure in Settings.' lbl := ui.label(win, lbl_txt, ui.LabelConfig{ should_pack: true @@ -80,13 +87,14 @@ fn show_install_info(win &ui.Window, mut modal ui.Modal, data string) { dlbtn.set_click_fn(download_v, 0) dlbtn.set_bounds(btn_x, btn_y, btn_width, 40) - mut ignore_btn := ui.button(text: 'Ignore / Configure later') + // mut ignore_btn := ui.button(text: 'Ignore / Configure later') + mut ignore_btn := ui.button(text: 'OK') ignore_btn.set_click(ui.default_modal_close_fn) ignore_btn.set_bounds(btn_x, btn_y + 45, btn_width, 40) modal.add_child(logo_im) modal.add_child(ignore_btn) - modal.add_child(dlbtn) + // modal.add_child(dlbtn) modal.add_child(lbl) modal.needs_init = false @@ -157,7 +165,7 @@ pub fn extract_zip_to_dir(file string, dir string) ?bool { fn get_v_version(win &ui.Window) (string, string) { output := get_v_version_1('v') - if output.starts_with('error') { + if output.starts_with('error') || !output.starts_with('V ') { // Try Again with set path v_exe := get_v_exe(win) output_new := get_v_version_1(v_exe) diff --git a/src/verminal.v b/src/verminal.v index 2ea5be2..6ad771f 100644 --- a/src/verminal.v +++ b/src/verminal.v @@ -58,7 +58,7 @@ fn before_txt_change(mut win ui.Window, tb ui.TextArea) bool { jump_sv(mut win, tb.height, tb.lines.len) if is_enter { - mut tbox := &ui.TextArea(win.get_from_id('vermbox')) + mut tbox := win.get[&ui.TextArea]('vermbox') tbox.last_letter = '' mut txt := tb.lines[tb.caret_top] @@ -75,7 +75,7 @@ fn before_txt_change(mut win ui.Window, tb ui.TextArea) bool { } fn jump_sv(mut win ui.Window, tbh int, lines int) { - mut sv := &ui.ScrollView(win.get_from_id('vermsv')) + mut sv := win.get[&ui.ScrollView]('vermsv') val := tbh - sv.height if lines <= 1 { sv.scroll_i = 0 @@ -87,7 +87,7 @@ fn jump_sv(mut win ui.Window, tbh int, lines int) { fn on_cmd(mut win ui.Window, box ui.TextArea, cmd string) { args := cmd.split(' ') - mut tbox := &ui.TextArea(win.get_from_id('vermbox')) + mut tbox := win.get[&ui.TextArea]('vermbox') if args[0] == 'cd' { cmd_cd(mut win, mut tbox, args) add_new_input_line(mut tbox) diff --git a/src/vpm_list.v b/src/vpm_list.v index e1dd929..dd9b2ba 100644 --- a/src/vpm_list.v +++ b/src/vpm_list.v @@ -14,8 +14,8 @@ mut: } fn (mut this Package) draw(ctx &ui.GraphicsContext) { - page := &ui.Page(ctx.win.get_from_id('vpm-modal')) - sear := &ui.TextField(ctx.win.get_from_id('vpm-search')) + page := ctx.win.get[&ui.Page]('vpm-modal') + sear := ctx.win.get[&ui.TextField]('vpm-search') label_text := this.label.text.to_lower() search_text := sear.text.to_lower() @@ -74,12 +74,12 @@ fn vpm_click_(mut win ui.Window, com ui.MenuItem) { modal.set_id(mut win, 'vpm-modal') mut slbl := ui.label(win, 'Search: ') - mut tbox := ui.textfield(win, '') + mut tbox := ui.text_field(text: '') mut vbox := ui.hbox(win) tbox.draw_event_fn = fn (mut win ui.Window, mut box ui.Component) { - modal := &ui.Page(win.get_from_id('vpm-modal')) + modal := win.get[&ui.Page]('vpm-modal') tw := ui.text_width(win, ' Search: ') + 20 box.x = tw box.width = modal.width - (tw * 2) - 28 @@ -112,7 +112,7 @@ fn vpm_click_(mut win ui.Window, com ui.MenuItem) { } fn vpm_vbox_draw(mut win ui.Window, mut com ui.Component) { - modal := &ui.Page(win.get_from_id('vpm-modal')) + modal := win.get[&ui.Page]('vpm-modal') if modal.width < 900 { com.width = modal.width - 8 - 28 @@ -122,7 +122,7 @@ fn vpm_vbox_draw(mut win ui.Window, mut com ui.Component) { } fn vpm_sv_draw_border(mut win ui.Window, mut com ui.Component) { - modal := &ui.Page(win.get_from_id('vpm-modal')) + modal := win.get[&ui.Page]('vpm-modal') com.x = 1 com.width = modal.width - 2 com.height = modal.height - modal.top_off - 44 @@ -159,7 +159,7 @@ fn load_modules_(mut win ui.Window, mut vbox ui.HBox) { mut pack := &Package{ win: win label: lbl - btn: create_cmd_btn(btn_txt) + btn: ui.button(text: btn_txt) } update_comd_btn(mut win, btn_txt, name, mut pack) @@ -204,8 +204,3 @@ fn module_exists(name string) bool { } return exists } - -fn create_cmd_btn(cmd string) &ui.Button { - mut btn := ui.button(text: cmd.title()) - return btn -}