Skip to content
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

gtk/templates: Add missing traits for TemplateChild #1870

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

bilelmoussaoui
Copy link
Member

Fixes #1842

Only compile tested

cc @felinira @sdroege

@bilelmoussaoui bilelmoussaoui force-pushed the bilelmoussaoui/template-child-prop branch 2 times, most recently from 66717ef to 21cf62c Compare October 18, 2024 18:47
@bilelmoussaoui bilelmoussaoui force-pushed the bilelmoussaoui/template-child-prop branch from 21cf62c to d1393c8 Compare October 19, 2024 12:58
@@ -1211,12 +1211,12 @@ pub unsafe trait WidgetClassExt: ClassStruct {
unsafe impl<T: ClassStruct> WidgetClassExt for T where T::Type: WidgetImpl {}

#[derive(Debug, PartialEq, Eq)]
#[repr(transparent)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove the repr(transparent) as the struct contains an extra field now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope nothing was relying on it being the same representation as T :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this needs to be repr-C now so that we at least guarantee that the pointer is stored at the beginning? How is GtkBuilder filling this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this needs to be repr-C now so that we at least guarantee that the pointer is stored at the beginning? How is GtkBuilder filling this?

By calling gtk_widget_class_bind_template_child_full, which is used from rust with bind_template_child_with_offset. But yes, maybe it should be repr-C.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it currently works with the offset to TemplateChild so you need to make it repr-C at least

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, let us wait and see if @felinira got whatever use case they have working with this patch first. I tested it locally by changing one of the examples but still

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does fix #1842 for me, if that's what you wanted to know :)

I'm a little surprised why this needs a FromValue implementation though. Isn't this readonly?

Copy link
Member Author

@bilelmoussaoui bilelmoussaoui Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little surprised why this needs a FromValue implementation though. Isn't this readonly?

The requirement seems to come from ObjectExt::property

fn property<V: for<'b> FromValue<'b> + 'static>(&self, property_name: &str) -> V;

So it is expected? not sure why you are surprised about it, unless you meant the ToValue?

@bilelmoussaoui bilelmoussaoui force-pushed the bilelmoussaoui/template-child-prop branch from d1393c8 to 9d76133 Compare October 19, 2024 15:13
@bilelmoussaoui
Copy link
Member Author

As this fixes the issue, let us land it already, any further fixes could be done separately

@bilelmoussaoui bilelmoussaoui merged commit 35a3844 into main Oct 24, 2024
40 checks passed
@bilelmoussaoui bilelmoussaoui deleted the bilelmoussaoui/template-child-prop branch October 24, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TemplateChild doesn't work as property
3 participants