-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Code generation for composite templates #86
Comments
Shouldn't be needed because we do support composite template in gtk4-rs, see the following example https://github.com/gtk-rs/gtk4-rs/blob/master/examples/src/bin/composite_template.rs |
If such a script provides more than that and makes things easier, the best approach would probably be to make it a proc macro (you can read the .ui files from the macro code) so it can be directly integrated into the Rust code instead of having external code generation via build.rs (which is rather suboptimal build-system-wise). |
Yes, rewriting it as macros was the idea. I just didn't want to do it before getting feedback about it. Composite templates don't check your actual ui files for any errors or typos, do they? These errors are only caught at runtime which makes it impossible to catch by CI etc. And you still need to write the template files. |
Definitely, see my suggestion in #77, Vala does exactly the same thing by having an attribute to specify either a resource uri or a file path and it does check the types at build time that way. |
Ah yes that looks like a good way to do it. I guess three LOC per template file are a good compromise between magic and not having to write a lot of code. I can look into it. |
Sounds great, thanks for looking into this :) |
Over at gnome gitlab @sophie-h created a python script that automatically generates composite template code for bindings from the ui files by parsing the xml, extracting the objects and creating fields (or functions in this case but that's an easily changed implementation detail) for every object that has an id.
I then rewrote it as a rust build script. It could also be reworked as a macro or something similar. You would only need to use the macro, specify a folder that contains your .ui files and it would automatically generate template code for you.
This has several advantages to manually writing template bindings:
Would this be a good addition to gtk-rs? If so, does anyone have any feedback on how to integrate it best? @bilelmoussaoui @sophie-h
The text was updated successfully, but these errors were encountered: