Skip to content

Commit

Permalink
Improvements to Settings modal & VPM Ui
Browse files Browse the repository at this point in the history
  • Loading branch information
pisaiah committed Apr 25, 2022
1 parent 7d793dc commit dcc8a10
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
.\v.exe symlink
cd iui
git clone https://github.com/isaiahpatton/vide
v -cc gcc -skip-unused -gc boehm vide
v -cc gcc -skip-unused -gc boehm -cflags -static vide
- name: Remove excluded
shell: msys2 {0}
run: |
Expand Down
Binary file added assets/JetBrainsMono-Regular.ttf
Binary file not shown.
Binary file removed assets/icons8-add-folder-24.png
Binary file not shown.
Binary file added assets/icons8-change-theme-24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/icons8-edit-48.png
Binary file not shown.
Binary file added assets/icons8-save-24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/icons8-save-48.png
Binary file not shown.
Binary file removed assets/icons8-themes-48.png
Binary file not shown.
2 changes: 1 addition & 1 deletion code_suggest.v
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub mut:
box &ui.TextArea
}

fn (mut this Hovermess) draw() {
fn (mut this Hovermess) draw(ctx &ui.GraphicsContext) {
mut mid := (this.x + (this.width / 2))
mut midy := (this.y + (this.height / 2))

Expand Down
4 changes: 2 additions & 2 deletions ide.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ fn main() {
file_img := $embed_file('assets/icons8-file-48.png')
edit_img := $embed_file('assets/icons8-edit-24.png')
help_img := $embed_file('assets/icons8-help-24.png')
save_img := $embed_file('assets/icons8-save-48.png')
theme_img := $embed_file('assets/icons8-themes-48.png')
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, 24)
edit_icon := ui.image_from_bytes(mut window, edit_img.to_bytes(), 24, 24)
Expand Down
143 changes: 67 additions & 76 deletions vpmlist.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import math
struct Pack {
ui.Component_A
mut:
win &ui.Window
label ui.Label
btn ui.Button
show bool
Expand All @@ -26,38 +27,54 @@ fn module_exists(name string) bool {
return exists
}

fn (mut this Pack) draw() {
if this.show {
ui.draw_with_offset(mut this.label, this.x, this.y)
ui.draw_with_offset(mut this.btn, this.x, this.y)
fn (mut this Pack) draw(ctx &ui.GraphicsContext) {
box := &ui.TextField(this.win.get_from_id('vpm-search'))
contain_search := this.label.text.to_lower().contains(box.text.to_lower())

this.btn.app.gg.draw_rounded_rect_empty(this.x - 4, this.y - 1, this.width, this.height + 3,
2, this.btn.app.theme.scroll_bar_color)
if !contain_search {
this.height = 0
return
} else {
this.height = ui.text_height(this.win, 'A{0|') * 2
}

this.win.draw_with_offset(mut this.label, this.x + 12, this.y + 8)
this.win.draw_with_offset(mut this.btn, this.x, this.y)

line_y := this.y + this.height
ctx.gg.draw_line(this.x, line_y, this.x + this.width, line_y, ctx.theme.scroll_bar_color)

// Change buttons

if !this.is_mouse_rele {
return
}

// Change buttons
installed := module_exists(this.label.text)
if installed && this.btn.text.contains('Install') {
create_cmd_btn(mut this.btn.app, 'remove', this.btn.extra, mut this)
if ui.point_in(mut this.btn, this.win.mouse_x - this.x, this.win.mouse_y - this.y) {
this.is_mouse_rele = false

btn_extra := this.btn.extra.split(' ')[1]

if this.btn.text.contains('Remove') {
update_cmd_btn(mut this.win, 'remove', btn_extra, mut this)
this.btn.text = 'Install'
} else {
if !installed && this.btn.text.contains('Remove') {
create_cmd_btn(mut this.btn.app, 'install', this.btn.extra, mut this)
if this.btn.text.contains('Install') {
update_cmd_btn(mut this.win, 'install', btn_extra, mut this)
this.btn.text = 'Remove'
}
}

if this.is_mouse_rele {
if ui.point_in(mut this.btn, this.btn.app.click_x - this.x, this.btn.app.click_y - this.y) {
this.btn.is_mouse_down = false
this.btn.is_mouse_rele = true
this.is_mouse_rele = false
}
}
this.btn.is_mouse_down = false
this.btn.is_mouse_rele = true
}
this.is_mouse_rele = false
}

fn vpm_click(mut win ui.Window, com ui.MenuItem) {
mut modal := ui.modal(win, 'V Package Manager (GUI)')
modal.set_id(mut win, 'vpm-modal')
modal.in_height = 400
modal.in_height = 420
modal.top_off = 10

v := get_v_exe(win)
Expand All @@ -78,6 +95,8 @@ fn vpm_click(mut win ui.Window, com ui.MenuItem) {
mut slbl := ui.label(win, 'Search: ')
mut tbox := ui.textfield(win, '')

mut vbox := ui.vbox(win)

tbox.draw_event_fn = fn (mut win ui.Window, mut box ui.Component) {
box.x = ui.text_width(win, 'Search: ') + 8
box.width = math.max(200, ui.text_width(win, box.text + 'a b'))
Expand All @@ -96,16 +115,17 @@ fn vpm_click(mut win ui.Window, com ui.MenuItem) {
if !txt.contains('[') {
continue
}
println(txt)

mut pack := &Pack{}
mut pack := &Pack{
win: win
}
name := txt.split('[')[1].split(']')[0]

mut lbl := ui.label(win, name)
lbl.pack()
pack.label = lbl

th := ui.text_height(win, 'A{0|') + 8
th := ui.text_height(win, 'A{0|') * 2
if name in installed_pack {
create_cmd_btn(mut win, 'remove', name, mut pack)
} else {
Expand All @@ -114,91 +134,62 @@ fn vpm_click(mut win ui.Window, com ui.MenuItem) {
pack.width = 370
pack.height = th

modal.add_child(pack)
vbox.add_child(pack)
}

mut slider := ui.slider(win, 0, 100, .vert)
slider.set_bounds(41, 10, 15, 200)
slider.set_bounds(41, 30, 15, 200)
slider.draw_event_fn = fn (mut win ui.Window, com &ui.Component) {
mut modal := &ui.Modal(win.get_from_id('vpm-modal'))
mut packs := modal.children.filter(it is Pack)

mut this := *com
vbox := modal.children.filter(it is ui.VBox)[0]
if mut this is ui.Slider {
mut sy := ui.text_height(win, 'A{0|') + 25
ms := ui.text_height(win, 'A{0|') + 10
max_show := ((400 - sy - (ms * 2)) / ms)

this.y = sy
this.cur = modal.scroll_i
this.height = (max_show + 1) * packs[0].height
this.max = win.extra_map['vpm-pl'].int()
this.y = vbox.y
this.x = vbox.x - this.width
this.height = vbox.height
this.cur = vbox.scroll_i
this.max = vbox.children.len
}
}
modal.add_child(slider)

modal.after_draw_event_fn = vpm_modal_draw
vbox.overflow = false
vbox.set_bounds(60, 40, 200, 348)
vbox.draw_event_fn = vpm_vbox_draw_border

modal.add_child(vbox)
win.add_child(modal)
}

fn create_cmd_btn(mut win ui.Window, cmd string, name string, mut pack Pack) {
mut btn := ui.button(win, cmd.title())
pack.btn = btn

update_cmd_btn(mut win, cmd, name, mut pack)
}

fn update_cmd_btn(mut win ui.Window, cmd string, name string, mut pack Pack) {
mut btn := pack.btn
btn.extra = cmd + ' ' + name
height := ui.text_height(win, 'A{') + 5
btn.set_bounds(250, 1, 100, height)
btn.set_click(fn (mut win ui.Window, btn ui.Button) {
v := get_v_exe(win)
res := os.execute(v + ' ' + btn.extra).output
println(res)
dump(res)
if btn.extra.starts_with('remove ') {
// 'v remove' leaves empty .git dir causing the
// module to still show as installed in 'v list'
path := os.real_path(btn.extra.replace_once('remove ', ''))
os.execute('cmd /c "rmdir /S /Q "' + path + '"')
}
})
pack.btn = btn
}

[deprecated: 'Replaced by ui.Slider']
fn draw_scrollbar(mut com ui.Modal, cl int, spl_len int, ep int) {
pack.btn = btn
}

fn vpm_modal_draw(mut win ui.Window, comp &ui.Component) {
mut com := *comp
if mut com is ui.Modal {
mut packs := com.children.filter(it is Pack)
mut i := 0
mut sy := ui.text_height(win, 'A{0|') + 25
ms := ui.text_height(win, 'A{0|') + 10
max_show := ((400 - sy - (ms * 2)) / ms)
if com.scroll_i > (packs.len - 1) {
com.scroll_i = packs.len - 1
}
mut pl := packs.len
for mut pack in packs {
if mut pack is Pack {
box := &ui.TextField(win.get_from_id('vpm-search'))
contain_search := pack.label.text.to_lower().contains(box.text.to_lower())
if box.text.len > 0 && !contain_search {
pack.show = false
pl--
continue
}
if i >= com.scroll_i && i < (com.scroll_i + max_show) {
pack.show = true
pack.set_pos(60, sy)
sy += ms
} else {
pack.show = false
}
i++
}
}
if com.scroll_i > (pl - 1) && com.scroll_i > max_show {
com.scroll_i = pl - max_show
}
win.extra_map['vpm-pl'] = pl.str()
}
fn vpm_vbox_draw_border(mut win ui.Window, com &ui.Component) {
win.draw_bordered_rect(com.rx, com.ry, com.width, com.height, 1, win.theme.textbox_background,
win.theme.textbox_border)
}

0 comments on commit dcc8a10

Please sign in to comment.