Rust UI?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
skyesp
Posts: 15
Joined: Sat Oct 16, 2021 11:57 am

Rust UI?

Post by skyesp »

Hey all. I'm currently trying to prototype a desktop environment for my kernel. The whole project is meant to be in Rust. The plan is to get that macOS 6 look & feel, but to have a modern kernel underneath with support for things like preemptive multitasking and the like. The kernel is already somewhat up and running, but I wanted to prototype the desktop and UI before I continue further. I have gotten the advice to make the graphics fully userspace, so I guess I will be emulating that (?)
However, after fighting with mini_gl_fb for hours, deciding to use minifb, and finally getting a window up and running which I can draw to (the plan is to use abstractions which I can later implement in my kernel), I have run into a fundamental issue: The design which I had in my head, widgets with other widgets as children, is either hard or impossible to properly do in Rust. I keep running into the issue of needing to use dynamically sized elements in structs etc. Does anyone have an idea on what other design I could use, what structure to store and process the UI?
Any help is greatly appreciated, thank you lovely people!

P.S. I know this is a very OO way of thinking, I am kinda new to Rust...
azblue
Member
Member
Posts: 147
Joined: Sat Feb 27, 2010 8:55 pm

Re: Rust UI?

Post by azblue »

What's an example where you need dynamically-sized elements? For GUI elements I'm thinking:

-x position
-y position
- width
- height
- type of GUI object
- sub type, flags, or other info
- parent
- child
- siblingNext
- siblingPrevious

If there are multiple children, a wiget will have a pointer to the first child, which will point to the next child via siblingNext ( the 2nd child will point back to the first with siblingPrevious). All fixed length thus far.

Something like the buffer for an input box or a canvas will vary in how much space it needs, but your widget's structure will just have:
- ptr to buffer
- buffer size

Again, fixed-length elements.

What are the contexts in which you're coming up with variable-length elements? Maybe we can figure out some fixed-length solutions.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Rust UI?

Post by iansjack »

Have you thought that the fact that you find it difficult to do what you want to in Rust may be an indication that you might have made the wrong choice of language? I’ve tried Rust for OS development and have found it a continual fight against the language, using lots of “unsafe” code to achieve things that are easy in C or C++. I think it’s a great language for general purpose-programming, but I’m fast coming to the conclusion that it’s too far removed from the machine for low-level stuff.
skyesp
Posts: 15
Joined: Sat Oct 16, 2021 11:57 am

Re: Rust UI?

Post by skyesp »

I quite like it so far, it's just that I didn't have a full knowledge of the trait/dyn Trait/impl trait for struct etc systems. I have managed to hack something together, it currently looks like this: https://imgur.com/a/GwfjnG7 but the basic things are there i guess :)
Post Reply