-
I'm writing a simple chat app that has a main window, plus a sidebar where you can select who you're chatting with, and a Rectangle "MessageArea" which contains the chat messages for that user. I understand, from looking at the printerdemo code, how to "swap" them in and out by making one visible at a time. However, I'm not sure how to instantiate the MessageArea components as needed from the Rust code. The compiler doesn't give me a struct to instantiate, since it doesn't inherit Window. I've tried using a callback, but I can't return a MessageArea from a callback (it says it's an invalid type). Basically, I need the Rust code to instantiate the MessageArea, and get some sort of handle back so it can send messages to it, and also so it can make it visible when the user clicks on it in the sidebar (although I imagine I could do that from the Slint side as well). Any ideas? This seems like a simple thing to do, but I can't seem to figure out how to do it in Slint. Thanks! -Jack |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Never mind. I think I'm still getting used to the Slint way of doing things. For those who come across this, you basically create a global property with an array of structs containing the values that the component needs, which starts out empty, and a for loop over the property array which instantiates the components using the provided struct data. On the Rust side, you connect the property with, say, a VecModel, like here, and then you can push new items onto the model, as done here. The for loop you set up in the Slint code will then automagically update the UI with the new component(s). Please, anyone who knows more about this feel free to correct/expand on my explanation. |
Beta Was this translation helpful? Give feedback.
Never mind. I think I'm still getting used to the Slint way of doing things.
For those who come across this, you basically create a global property with an array of structs containing the values that the component needs, which starts out empty, and a for loop over the property array which instantiates the components using the provided struct data. On the Rust side, you connect the property with, say, a VecModel, like here, and then you can push new items onto the model, as done here. The for loop you set up in the Slint code will then automagically update the UI with the new component(s).
Please, anyone who knows more about this feel free to correct/expand on my explanation.