gtk-rs / gtk

DEPRECATED, use https://github.com/gtk-rs/gtk3-rs repository instead!
https://gtk-rs.org/
MIT License
1.25k stars 82 forks source link

Subclassing: Start implementing missing forall func for Gtk.Container #1035

Closed haecker-felix closed 4 years ago

haecker-felix commented 4 years ago

With this MR I try to implement the missing forall func in ContainerImpl.

Disclaimer: I have no idea what I'm doing right now :). Never worked with gtk-rs binding stuff before. To get this fully working, I need support from someone who knows how this stuff works in detail.

Help is appreciated :D

(Related issue: https://github.com/gtk-rs/gtk/issues/1036)

sdroege commented 4 years ago

Any updates here?

haecker-felix commented 4 years ago

Any updates here?

I was on vacation for 2 weeks, I'll try to finish this next weekend.

haecker-felix commented 4 years ago

I have tried to add some missing pieces to the puzzle - this is were I'm currently:

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
   --> src/subclass/container.rs:140:17
    |
140 |                 f(
    |                 ^ expected 4 arguments
141 |                     container.to_glib_none().0,
    |                     --------------------------
142 |                     include_internals,
    |                     -----------------
143 |                     callback.to_glib_none().0,
    |                     ------------------------- supplied 3 arguments

error[E0599]: no method named `to_glib_none` found for type parameter `P` in the current scope
   --> src/subclass/container.rs:143:30
    |
143 |                     callback.to_glib_none().0,
    |                              ^^^^^^^^^^^^ method not found in `P`
    |
    = note: `callback` is a function, perhaps you wish to call it
    = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `to_glib_none`, perhaps you need to restrict type parameter `P` with it:
    |
130 |     fn parent_forall<P: glib::translate::ToGlibPtr + FnMut(&Widget)>(
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: no method named `cb` found for reference `&subclass::container::Callback` in the current scope
   --> src/subclass/container.rs:268:18
    |
268 |             self.cb(widget.to_glib_none().0, self.user_data);
    |                  ^^----------------------------------------- help: remove the arguments
    |                  |
    |                  field, not a method

error: aborting due to 3 previous errors

If anyone wants to finish this for me, please feel free to do so. I have the feeling I will have to struggle with this PR for a long time, since this is kinda black magic for me. 🪄

sdroege commented 4 years ago

If anyone wants to finish this for me, please feel free to do so.

I'll take a look at finishing this some time later today. But you'll have to tell me if it actually works as expected :)

sdroege commented 4 years ago

This should work fine now. @haecker-felix can you confirm?

@GuillaumeGomez @EPashkin can you review?

GuillaumeGomez commented 4 years ago

The code looks good to me. However: my knowledge of subclassing is close to 0 so my opinion isn't worth much here. :)

sdroege commented 4 years ago

Ok, then let's get it in and have @haecker-felix confirm that it solves whatever he's trying to do later :) Thanks!

haecker-felix commented 4 years ago

My use case doesn't exist anymore, I implemented my widget directly in C / libhandy since it wasn't possible in Rust earlier.

https://gitlab.gnome.org/GNOME/libhandy/-/merge_requests/562

I just glued a small test together, and it seems that it works. Thanks a lot @sdroege for finishing this. I'll try to make a simple Gtk.Container subclassing example later.