Is there any better way of "hard-coding" GUIs in low level languages?

Say, for example, that I have a GUI library whose API solely offers functionality for drawing text boxes, buttons, labels, etc. No fancy layout utilities.

For a simple use case, one might just hard-code the size and coordinates of a certain button, or even a small bunch of them, but once the layout starts to clutter, it's a better choice to give some organization. When there is no visual GUI editor, you either make one, or code your own layout API. Either option is obviously very time consuming, and the latter doesn't tend to be very flexible.

Is there any way/standard for "programmatically" giving a layout to a gui? For example in web, I've seen how people use html, css and json to specify certain behaviors, styles and that. How could that be applied here? In my case, I'm using the raygui lib (which isn't really standalone since its meant to be a gui utility for games)

3 points · 2 comments · view on lemmy.world

2 Comments

6nk06@sh.itjust.works · 2 pts · 1y

There is no standard GUI and no standard language. You could find a library that dynamically creates GUIs with JSON, or use a LUA wrapper in your application, or use QML. But there is no standard.

You can even write your own DSL with Lua or any embedded language for raylib. Anything is possible.

Also remember that most web devs don't write standard JS anymore, they always use a framework like ReactJS and they technically dont act and program the pages anymore.

Ephera@lemmy.ml · 1 pts · 1y

GUI libraries are unfortunately really not standardized at all. For low-level languages, you may want to consider alternatives, like a CLI or just a config file.

One interesting option is also TUIs. Many of them are based on the ncurses library, which is by itself fairly simple, but you can find layouting libraries on top of it.
For Rust, there's a pretty cool higher-level library: https://ratatui.rs/

To be honest, these choices are hardly more standardized than GUI libraries (well, except for config files maybe, where you've got TOML, YAML etc.), but they are much simpler, so more libraries will offer a complete package.