Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Signal connection wth Builder #359

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andy128k
Copy link
Contributor

Addresses #128

Implementation is similar to #266

This looks not very useful. FromValue is not implemented for a glib::Object (and gtk::Widget), so handler's arguments are limited to primitive types.

@sdroege
Copy link
Member

sdroege commented Mar 16, 2021

This looks not very useful. FromValue is not implemented for a glib::Object (and gtk::Widget), so handler's arguments are limited to primitive types.

This should be less of a problem once I finally finished #31 . Then you can treat all the types the same without the distinction of nullable/non-nullable types like now.

Copy link
Member

@sdroege sdroege left a comment

Choose a reason for hiding this comment

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

Looks generally like going in the right direction, thanks a lot :)

match values[#index].get_some() {
Ok(value) => value,
Err(error) => {
glib::g_critical!("builder handler", "Handler {} expects an argument of type {} but received `{:?}`: {}.", #handler_name, stringify!(#arg_type), values[#index], error);
Copy link
Member

Choose a reason for hiding this comment

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

This should be a panic in one way or another. Returning None can easily cause memory safety issues in the C code calling this signal handler.

gtk/tests/builder_handlers.rs Show resolved Hide resolved
quote_spanned! { info.sig.span() =>
#signal => Some({
#[allow(unused_variables)]
Box::new(glib::clone!(@weak self as this => move |values: &[glib::Value]| {
Copy link
Member

Choose a reason for hiding this comment

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

I think instead of having to work with a struct Foo(Widget) kind of type, it would make more sense to integrate this with subclassing and especially composite templates.

That way you could have the macro on the impl struct, and use the ObjectSubclass::from_instance() / ::get_instance() functions to get to a widget and back.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants