Skip to content

Commit

Permalink
Fix Save/Run menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
pisaiah committed Jun 25, 2023
1 parent 5b60ef0 commit 4dc3884
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/config.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mut:
workspace_dir string
vexe string
font_path string
font_size int = 16
font_size int = 18
theme string = 'Vide Default Dark'
}

Expand Down
4 changes: 2 additions & 2 deletions src/events.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn (mut app App) proj_tree_draw(mut e ui.DrawEvent) {
e.target.width -= app.activty_speed
}
if e.target.width < app.activty_speed {
e.target.width = 1
e.target.width = 0
}
} else {
if e.target.width < 250 {
Expand Down Expand Up @@ -62,7 +62,7 @@ fn (mut app App) search_pane_draw(mut e ui.DrawEvent) {
e.target.width -= app.activty_speed
}
if e.target.width < app.activty_speed {
e.target.width = 1
e.target.width = 0
}
} else {
if e.target.width < 250 {
Expand Down
38 changes: 18 additions & 20 deletions src/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ fn main() {
confg := make_config()

mut win := ui.make_window(
width: 910
height: 520
width: 930
height: 530
title: 'Vide'
font_size: 16
font_size: 18
font_path: confg.font_path
)

Expand All @@ -58,7 +58,7 @@ fn main() {
hbox.add_child(activity_bar)

hbox.add_child(tree)

// Search box
search := app.setup_search(mut win, folder)
hbox.add_child(search)
Expand Down Expand Up @@ -111,44 +111,42 @@ fn main() {
fn (mut app App) make_activity_bar() &ui.VBox {
mut activity_bar := ui.vbox(app.win)
activity_bar.set_bounds(0, 25, 41, 100)

activity_bar.subscribe_event('draw', fn (mut e ui.DrawEvent) {
hei := e.ctx.gg.window_size().height
e.ctx.theme.menu_bar_fill_fn(e.target.x, e.target.y, e.target.width, hei, e.ctx)
})

// Explore Button
img_wide_file := $embed_file('assets/explore.png')
mut calb := app.icon_btn(img_wide_file.to_bytes(), app.win)

activity_bar.add_child(calb)

calb.subscribe_event('mouse_up', app.calb_click)

// Search Button
img_search_file := $embed_file('assets/search.png')
mut serb := app.icon_btn(img_search_file.to_bytes(), app.win)

activity_bar.add_child(serb)

serb.subscribe_event('mouse_up', app.serb_click)

// Git Commit satus Button
img_gitm_file := $embed_file('assets/merge.png')
mut gitb := app.icon_btn(img_gitm_file.to_bytes(), app.win)

activity_bar.add_child(gitb)

gitb.subscribe_event('mouse_up', app.calb_click)

return activity_bar
}

fn (mut app App) icon_btn(data []u8, win &ui.Window) &ui.Button {
mut ggc := win.gg
gg_im := ggc.create_image_from_byte_array(data) or {
return ui.button(text: 'NO IMG')
}
gg_im := ggc.create_image_from_byte_array(data) or { return ui.button(text: 'NO IMG') }
cim := ggc.cache_image(gg_im)
mut btn := ui.button_with_icon(cim)

Expand Down Expand Up @@ -187,30 +185,30 @@ fn (mut app App) setup_tree(mut window ui.Window, folder string) &ui.ScrollView
}

fn (mut app App) setup_search(mut window ui.Window, folder string) &ui.ScrollView {

mut search_box := &ui.Panel{
x: 2
y: 0
width: 200
height: 250
layout: ui.FlowLayout{}
}

search_box.set_layout(ui.BoxLayout{ ori: 1 })

search_box.subscribe_event('draw', fn (mut e ui.DrawEvent) {
e.ctx.gg.draw_rect_empty(e.target.x, e.target.y, e.target.width, e.target.height, gx.blue)
e.ctx.gg.draw_rect_empty(e.target.x, e.target.y, e.target.width, e.target.height,
gx.blue)
})

search_field := ui.text_field(
text: 'Search ...'
bounds: ui.Bounds{1, 1, 190, 25}
)
search_box.add_child(search_field)

mut stb := ui.title_box('Search', [search_box])
stb.set_bounds(4, 4, 200, 250)

// hbox.add_child(stb)

mut sv := ui.scroll_view(
Expand Down
41 changes: 28 additions & 13 deletions src/menus.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ fn (mut app App) make_menubar() {
save_img := $embed_file('assets/icons8-save-24.png')
theme_img := $embed_file('assets/icons8-change-theme-24.png')

file_icon := ui.image_from_bytes(mut window, file_img.to_bytes(), 24, 22)
edit_icon := ui.image_from_bytes(mut window, edit_img.to_bytes(), 24, 22)
help_icon := ui.image_from_bytes(mut window, help_img.to_bytes(), 24, 22)
save_icon := ui.image_from_bytes(mut window, save_img.to_bytes(), 24, 22)
theme_icon := ui.image_from_bytes(mut window, theme_img.to_bytes(), 24, 22)
i_w := 26
i_h := 26

file_icon := ui.image_from_bytes(mut window, file_img.to_bytes(), i_w, i_h)
edit_icon := ui.image_from_bytes(mut window, edit_img.to_bytes(), i_w, i_h)
help_icon := ui.image_from_bytes(mut window, help_img.to_bytes(), i_w, i_h)
save_icon := ui.image_from_bytes(mut window, save_img.to_bytes(), i_w, i_h)
theme_icon := ui.image_from_bytes(mut window, theme_img.to_bytes(), i_w, i_h)

file_menu := ui.menu_item(
text: 'File'
Expand All @@ -40,11 +43,11 @@ fn (mut app App) make_menubar() {
),
ui.menu_item(
text: 'Save'
// click_event_fn: save_click
click_event_fn: save_click
),
ui.menu_item(
text: 'Run'
// click_event_fn: run_click
click_event_fn: run_click
),
ui.menu_item(
text: 'Manage Modules..'
Expand Down Expand Up @@ -189,26 +192,38 @@ fn save_click(mut win ui.Window, item ui.MenuItem) {
fn do_save(mut win ui.Window) {
mut com := &ui.Tabbox(win.get_from_id('main-tabs'))

/*
mut tab := com.kids[com.active_tab]
for mut sv in tab {
if mut sv is ui.ScrollView {
for mut child in sv.children {
if mut child is ui.TextArea {
if mut child is ui.Textbox {
os.write_file(com.active_tab, child.lines.join('\n')) or {
set_console_text(mut win, 'Unable to save file!')
// set_console_text(mut win, 'Unable to save file!')
}
}
}
}
}*/
}
}

fn run_click(mut win ui.Window, item ui.MenuItem) {
com := &ui.Tabbox(win.get_from_id('main-tabs'))

txt := com.active_tab
dir := os.dir(txt)
mut dir := os.dir(txt)

if dir.ends_with('src') {
dir = os.dir(dir)
}

args := ['v', '-skip-unused', 'run', dir]

mut tbox := win.get[&ui.Textbox]('vermbox')

spawn verminal_cmd_exec(mut win, mut tbox, args)

jump_sv(mut win, tbox.height, tbox.lines.len)

// spawn run_v(dir, mut win)
win.extra_map['update_scroll'] = 'true'
win.extra_map['lastcmd'] = args.join(' ')
}
13 changes: 6 additions & 7 deletions src/new_proj.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ fn (mut app App) new_project_click(mut win ui.Window, com ui.MenuItem) {
modal.add_child(vbox)

mut lic := make_license_section(win)

lic_sv := ui.scroll_view(
view: lic
bounds: ui.Bounds{-5, 0, 210, 150}
padding: 0
)

mut lic_tb := ui.title_box('License', [lic_sv])
lic_tb.set_bounds(25, 125, 5, 25)
modal.add_child(lic_tb)
Expand Down Expand Up @@ -65,10 +65,9 @@ fn (mut app App) new_project_click(mut win ui.Window, com ui.MenuItem) {
lic := win.extra_map['np-lic']
dir := app.confg.workspace_dir
templ := win.extra_map['np-templ']

dump(lic)
dump(templ)

args := [name, des, ver, lic]

new_project(
Expand Down Expand Up @@ -108,7 +107,7 @@ fn make_license_section(window &ui.Window) &ui.VBox {
group.subscribe_event('mouse_up', fn (mut e ui.MouseEvent) {
e.ctx.win.extra_map['np-lic'] = e.target.text
})

group.setup()
hbox.pack()
return hbox
Expand All @@ -128,11 +127,11 @@ fn make_templ_section(window &ui.Window) &ui.VBox {
group.add(box)
hbox.add_child(box)
}

group.subscribe_event('mouse_up', fn (mut e ui.MouseEvent) {
e.ctx.win.extra_map['np-templ'] = e.target.text
})

group.setup()
hbox.pack()
return hbox
Expand Down
20 changes: 6 additions & 14 deletions src/tabs.v
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,8 @@ fn new_tab(mut window ui.Window, file string) {

lines := os.read_lines(file) or { ['ERROR while reading file contents'] }

mut code_box := ui.text_box(lines) // ui.textarea(window, lines)
// mut code_box := ui.textarea(window, lines)

// code_box.text_change_event_fn = codebox_text_change
// code_box.after_draw_event_fn = on_text_area_draw
// code_box.line_draw_event_fn = draw_code_suggest
// code_box.active_line_draw_event = text_area_testing
// code_box.hide_border = true
// code_box.padding_x = 8
// code_box.padding_y = 8
mut code_box := ui.text_box(lines)

code_box.set_bounds(0, 0, 620, 250)

mut scroll_view := ui.scroll_view(
Expand All @@ -126,7 +118,8 @@ fn new_tab(mut window ui.Window, file string) {
padding: 0
)

// scroll_view.after_draw_event_fn = on_runebox_draw
scroll_view.set_border_painted(false)

scroll_view.subscribe_event('draw', fn (mut e ui.DrawEvent) {
mut tb := e.ctx.win.get[&ui.Tabbox]('main-tabs')
e.target.width = tb.width
Expand All @@ -146,12 +139,12 @@ fn new_tab(mut window ui.Window, file string) {
} else if cb.height < min {
cb.height = min
}

// Do save
if cb.ctrl_down && cb.last_letter == 's' {
cb.ctrl_down = false
os.write_file(file, cb.lines.join('\n')) or {}

execute_syntax_check(file)
}
}
Expand All @@ -169,7 +162,6 @@ fn execute_syntax_check(file string) {
dump(res)
}


fn code_textarea_draw_line_event(mut e ui.DrawTextlineEvent) {
mut cb := e.target

Expand Down
6 changes: 2 additions & 4 deletions src/tree-list.v
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ fn make_tree2(fold string) &ui.TreeNode {
fn tree2_click(mut ctx ui.GraphicsContext, tree &ui.Tree2, node &ui.TreeNode) {
txt := node.text
dump(txt)
path := os.real_path(txt)
path := os.real_path(txt)
dump(path)

if !os.is_dir(path) {
new_tab(mut ctx.win, txt)
}
Expand All @@ -54,9 +53,8 @@ fn refresh_tree(mut window ui.Window, fold string, mut tree ui.Tree2) {
// TODO
dump('REFRESH')
tree.children.clear()

dump(fold)

dump(fold)
files := os.ls(fold) or { [] }
tree.click_event_fn = tree2_click

Expand Down
12 changes: 11 additions & 1 deletion src/verminal_commands.v
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ fn cmd_exec_unix(mut win ui.Window, mut tbox ui.Textbox, args []string) {

// Windows
fn cmd_exec_win(mut win ui.Window, mut tbox ui.Textbox, args []string) {
mut pro := os.new_process('cmd')
mut pro := os.new_process('C:\\Windows\\System32\\cmd.exe')

varg := args[1..].join(' ')

mut argsa := ['/min', '/c', args.join(' ')]
pro.set_args(argsa)
Expand All @@ -85,6 +87,14 @@ fn cmd_exec_win(mut win ui.Window, mut tbox ui.Textbox, args []string) {

for pro.is_alive() {
mut out := pro.stdout_read()
mut oute := pro.stderr_read()

if oute.len > 0 {
for line in oute.split_into_lines() {
tbox.lines << line.trim_space()
}
}

if out.len > 0 {
for line in out.split_into_lines() {
tbox.lines << line.trim_space()
Expand Down
4 changes: 2 additions & 2 deletions src/vide-theme.v
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn vide_dark_theme() &ui.Theme {
return &ui.Theme{
name: 'Vide Default Dark'
text_color: gx.rgb(230, 230, 230)
background: gx.rgb(37,37,39)//gx.rgb(40, 55, 71)
background: gx.rgb(37, 37, 39) // gx.rgb(40, 55, 71)
button_bg_normal: gx.rgb(10, 10, 10)
button_bg_hover: gx.rgb(70, 70, 70)
button_bg_click: gx.rgb(50, 50, 50)
Expand All @@ -50,7 +50,7 @@ pub fn vide_dark_theme() &ui.Theme {
dropdown_background: gx.rgb(83, 107, 138)
dropdown_border: gx.rgb(93, 135, 191)
textbox_background: gx.rgb(34, 39, 46)
textbox_border: gx.rgb(93, 135, 191)//gx.blue//gx.rgb(130, 130, 130)
textbox_border: gx.rgb(93, 135, 191) // gx.blue//gx.rgb(130, 130, 130)
checkbox_selected: gx.rgb(130, 170, 220)
checkbox_bg: gx.rgb(5, 5, 5)
progressbar_fill: gx.rgb(130, 130, 130)
Expand Down

0 comments on commit 4dc3884

Please sign in to comment.