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::GestureDrag and retrieving x,y coordinates #60

Open
gummybears opened this issue Nov 2, 2023 · 6 comments
Open

Gtk::GestureDrag and retrieving x,y coordinates #60

gummybears opened this issue Nov 2, 2023 · 6 comments

Comments

@gummybears
Copy link

Working on interactive constraints and trying to call methods
to get the point where the drag started

def start_point(x : Float64 | Nil, y : Float64| Nil) : Bool
end

and to get the offset from the start point.

def offset(x : Float64 | Nil, y : Float64 | Nil ) : Bool

If the gesture is active, this function returns true and fills in x and y with the drag start coordinates, in surface-relative coordinates

These x,y parameters are passed by value and not by reference, so not sure how these x,y values are returned.

The compiler complains with error

In lib/gi-crystal/src/auto/gtk-4.0/gesture_drag.cr:115:21

 115 | Float64.null
@gummybears
Copy link
Author

The code with the interactive constraints is found at

https://github.com/gummybears/gtk4_with_crystal/blob/master/lesson008/interactive_grid.cr

The compiler error message got truncated


In lib/gi-crystal/src/auto/gtk-4.0/gesture_drag.cr:141:21

 141 | Float64.null
               ^---
Error: undefined method 'null' for Float64.class

@gummybears
Copy link
Author

It seems one has to use callback functions to retrieve the (x,y) coordinates when a widget is dragged

drag = Gtk::GestureDrag.new
drag.drag_begin_signal.connect(->drag_begin_callback(Float64,Float64))
drag.drag_update_signal.connect(->drag_update_callback(Float64,Float64))
drag.drag_end_signal.connect(->drag_begin_callback(Float64,Float64))

@hugopl
Copy link
Owner

hugopl commented Dec 11, 2023

I see, it's another issue from the fact that GI-Crystal just ignore the out parameters.

It's on my queue to touch this on GI-Crystal and let every method that have out parameters to return a Tuple {return_value, out_param1, out_param2, ...}

@gummybears
Copy link
Author

I am also seeing methods where a parameter of type Pointer(Void) has to be specified e.g

class Gdk::Clipboard
  ....
  def read_value_async(type : UInt64, io_priority : Int32, cancellable : Gio::Cancellable?, callback : Gio::AsyncReadyCallback?, user_data : Pointer(Void)?) : Nil
   ....
end

but reading the Gi-Crystal doc, it says I should ignore user_data ??

@hugopl
Copy link
Owner

hugopl commented Dec 12, 2023

Yes, what the binding generator uses this user_data pointer to pass a Crystal ::Box object with the closure, so you can pass a Crystal callback for it.

All these _async methodw from GTK follow the same pattern, so I think will be possible to even create better a crystallized API for them.

@gummybears
Copy link
Author

For the moment I will skip some of the Gtk4 examples as the API is still work in progress.

PS I am not familiar with ::Box object with closures.

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

No branches or pull requests

2 participants