Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearer UI syntax #573

Open
dudejj opened this issue Apr 19, 2024 · 5 comments
Open

Clearer UI syntax #573

dudejj opened this issue Apr 19, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@dudejj
Copy link

dudejj commented Apr 19, 2024

UI code as shown in demo example is more or less confusing, notably for beginner.
Same demo can be created like this, which syntax may be much more attractive and easier to grasp:

struct App {
mut:
	window     &ui.Window = unsafe { nil }
	first_name string
	last_name  string
}

fn main() {
	mut app := &App{}

	// components
	txtbox1 := ui.textbox(
		max_len: 20
		width: 200
		placeholder: 'First name'
		text: &app.first_name
	)

	txtbox2 := ui.textbox(
		max_len: 50
		width: 200
		placeholder: 'Last name'
		text: &app.last_name
	)

	// containers
	col := ui.column(
		width: 200
		spacing: 13
		children: [txtbox1, txtbox2]
	)

	row := ui.row(
		margin: ui.Margin{10, 10, 10, 10}
		children: [col]
	)

	// window
	app.window = ui.window(
		width: 600
		height: 400
		title: 'V UI Demo'
		children: [row]
	)

	ui.run(app.window)
}

Maybe clearer yet could be adding widgets and containers like this (which don't work at the moment):

col.children << [txtbox1, txtbox2]
row.children << [col]
app.window.children << [row]

@dudejj dudejj added the enhancement New feature or request label Apr 19, 2024
@Wajinn
Copy link

Wajinn commented Jul 13, 2024

A style where people might deem more comfortable for writing code on a single line and saving some space, can be seen with MUI. Of course it's going to come down to preferences. But it does show that the VUI can be built on top of and further tailored to particular tastes with other libraries.

Regardless, do think this is an interesting idea, to increase clarity.

@xandro0777
Copy link
Contributor

xandro0777 commented Jul 14, 2024 via email

@Wajinn
Copy link

Wajinn commented Sep 16, 2024

...does text input work as expected on all "supported" platforms in the meantime?
Last time I tried Android was a problem.

The comments do not appear related to this issue. Perhaps open a new issue or one at VAB, with an example and specific details.

@Wajinn
Copy link

Wajinn commented Nov 17, 2024

Rethinking this, from a user perspective, VUI's syntax is mostly fine (though not sure about spacings versus spacing). It's likely more a matter of documentation, examples, and the way it's often written that can cause issues or confusion.

Instead of always typing out components and widgets vertically, it might be better to show those horizontally and created first, to also save vertical space. Then place the widgets into the columns and rows, which can be typed out vertically (and helps to visualize). Thus, it all might be a matter of style versus actual syntax.

// psuedo
widget() // horizontal
widget() // horizontal
column(
	children: [
		widget
		widget
	]
)
window(children: [column])
run(window)

@medvednikov
Copy link
Member

Yeah, that's how I do it.

Sometimes you can just call ui.tetxbox(...), but often you need to store the object, to access it later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants