Getting the position of a Widget inside an AdwOverlaySplitView content

Hi,

I have a ScrolledWindow with a Widget (Image) placed inside the content property of an AdwOverviewSplitView.
I want to draw on top of the Widget, but I can’t seem to get the positional offset of the Widget inside the parent.

gtk_widget_compute_bounds (self->content, widget, &bounds)

returns 0 for the position, but there is a visible gap at the top (not on the left though).

I know this sounds like an easy to solve problem,
but I could not find anything related and would appreciate if anyone can point me in the right direction.

Hi,

For the offset, use Gtk.Widget.compute_point
(or the old method Gtk.Widget.translate_coordinates )

Thanks, I will try that, but my solution for now was to draw the Texture with gtk_snapshot_append_texture.

Thank you anyway

So I tested it now and in theory this should work, but I get (0,0) for the point
EDIT: self is the parent widget for both widgets visible in the resource file.

this is my test code:

graphene_point_t point;
graphene_point_init (&point, 0.f, 0.f);
gtk_widget_compute_point (self->content, GTK_WIDGET (self), &point,
                          &self->content_position);
printf ("Content position: %f, %f\n", self->content_position.x,
        self->content_position.y);

and this is the part of the resource file:

 <object class="GtkBox">
 <property name="hexpand">TRUE</property>
 <property name="vexpand">TRUE</property>
   <child>
     <object class="GtkImage" id="content">
       <property name="hexpand">TRUE</property>
       <property name="vexpand">TRUE</property>
     </object>
   </child>
</object>

hm, is that box a direct child of the AdwOverlaySplitView?
if both the image and the box are set to expand, then they will occupy all the available space, so the resulting offset will be zero (even if the image may appear smaller and centered, the margins around are still part of the widget).

It’s not a child of the AdwOverlaySplitView anymore, I removed it to test it and had the same result, sorry for the confusion (should’ve done that before). The problem (for me) seems to be how the GtkImage is displayed (like you said).
It seems that GtkImage is not the right choice me, because I didn’t find a way to get the position of the internal Image.

You may try to set the GtkImage’s hexpand/vexpand properties to “false”, and its valign/halign properties to “center”, to avoid claiming the extra space around.

I mean, I don’t want to center it. I would prefer to align it to the start, but both resulted in having a margin/padding.
I think I’m happy with drawing with in the snapshot virtual method. There I have more control over what is happening.

Edit: to add, I set the expands to false in my test just now

Edit2: To explain, what I’m trying to do in general:
I want to create an application where I can edit dot files/ Graphviz files in a userfriendly way, without having to use the scripting method. So I calculate the positions of the Nodes for mouse selection and show the rendered file. This all will have to be correctly aligned and scaled, to work properly

Thanks for your advice on my problem. I really appreciate the fast solution oriented answers in this forum.

Thanks for the details!
In that case, that’s indeed better to implement your own snapshot function (like you seem to do now), instead of trying to position a GtkImage or other widgets.

1 Like

For anyone looking to do something similar: I found you could also use a GtkFixed and put a GtkPicture inside. That way one does not have to think about the implementation for the size, when putting it e.g. inside a GtkScrolledWindow.
It’s much easier, more intuitive and maintainable.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.