gtk4-rs icon indicating copy to clipboard operation
gtk4-rs copied to clipboard

book: No clear instructions in how to access and manage the imp struct from the public struct in Composite Templates

Open claudio4 opened this issue 2 years ago • 1 comments

The book does not clearly explain how to access the imp struct from the public struct. The todo app example does show how to access it, but it doesn't really stop to explain it, so it can be easily missed, especially if we consider how much information is packed in that example.

So, I would like to ask for a more detailed explanation of the subject, including how to mutate the state, as it seems like this last part can only be archived via interior-mutability, something that might not struck as obvious to everyone.

@Hofer-Julian

P.D: I really appreciate all the hard work the maintainers put in developing and documenting this vast library. Thank you.

Edited on 22/10/2021 to better reflect the issue.

claudio4 avatar Oct 14 '21 18:10 claudio4

I was consufed on this part as well. Would be cool if the book showed some best practices as where to define signal handlers.

I made a progress as soon as I realized, that the Impl part is a "backend" which has to be accessed from the definition part with ::from_instance call defined in gtk::subclass::prelude::*. I wouldn't hesitate to use terms as "public facing/frontend/" (you guys will come up with better ideas)

I would love to see some short comment on how to store the widget state (without gtk attributes), what's the role of RefCell, OnceCell. Which took me some time and digging through the examples as I do not have previous Rust experience.

P.S.: I am really glad for the book and all the examples! It's a great resource, thanks. As non-professional might terminology is just bad, if interesting I can try to explain more.

ondrejkolin avatar Oct 15 '21 08:10 ondrejkolin