Skip to content

Commit

Permalink
Improve settings layout
Browse files Browse the repository at this point in the history
  • Loading branch information
pisaiah committed Feb 2, 2023
1 parent a61a918 commit f44e3fd
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 362 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
| IDE | Disk | RAM |
|---------|---------|---------|
| | | |
| Vide | < 5MB | ~ 60MB |
| Vide | < 5MB | ~ 70MB |
| VS Code | 300MB | ~ 300MB |
| | | |
8 changes: 4 additions & 4 deletions src/code_suggest.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
28 changes: 15 additions & 13 deletions src/config.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
'workspace_dir = ~/vide/workspace',
'v_flags = -skip-unused',
].join_lines()
config = make_config()
)

// Make Config as a 'Fake' Component
Expand All @@ -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() {
Expand All @@ -52,26 +50,30 @@ 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()
}
}
}
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
Expand Down
2 changes: 1 addition & 1 deletion src/draw_events.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions src/ide.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import os
import hc

const (
version = '0.0.13-dev'
version = '0.0.14-dev'
)

struct App {
Expand Down Expand Up @@ -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()
}
Expand All @@ -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())

Expand All @@ -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
Expand All @@ -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
Expand All @@ -122,7 +119,7 @@ fn main() {
h1: 70
h2: 20
bounds: ui.Bounds{
y: 28
y: 30
x: 4
}
)
Expand All @@ -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 { [] }
Expand Down
5 changes: 2 additions & 3 deletions src/menus.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 2 additions & 5 deletions src/new_file.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {}

Expand Down
20 changes: 11 additions & 9 deletions src/new_proj.v
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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)
})

Expand All @@ -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
Expand Down
Loading

0 comments on commit f44e3fd

Please sign in to comment.