~eliasnaur/gio

3 2

How to get widget position?

Details
Message ID
<NedBXZL--3-9@tutanota.com>
DKIM signature
pass
Download raw message
I want to draw circle inside some area(widget.Border) at point where user made mouse click.
After reading documentation I was able to find how handle mouse events inside widget, 
but position of event seems related to window itself. 
So what is right way to obtain widget-related position? (directly or via shifting "global" position).

My current code:
https://pastebin.com/QmPypGKb
Details
Message ID
<CAFcc3FTwBy44OTj4qh1qkVG0oZi1uJx2Zo6ktbFmsgFCEbDN2Q@mail.gmail.com>
In-Reply-To
<NedBXZL--3-9@tutanota.com> (view parent)
DKIM signature
pass
Download raw message
On Mon, Sep 18, 2023 at 1:02 PM <gdaarb@tutanota.com> wrote:
>
>
> I want to draw circle inside some area(widget.Border) at point where user made mouse click.
> After reading documentation I was able to find how handle mouse events inside widget,
> but position of event seems related to window itself.
> So what is right way to obtain widget-related position? (directly or via shifting "global" position).

The pointer.Event.Position field is a coordinate relative to the
origin of the clipping area that registered the input handler.

More concretely, the most recent clipping area pushed when you do
`pointer.InputOp{}.Add()` will define the coordinate space for the
input events routed to that input handler. The point (0,0) is the
drawing origin of that clipping area (not of the window) for the
emitted pointer events.

In your example, you define that area on line 142 by setting the
dimensions of the clipping area to gtx.Constraints.Max. This will make
the coordinates similar to the global window
coordinates, though they should be shifted downwards by your buttons.
(as a side note, your input area will have effectively-infinite
height, as a vertical list provides an effectively-infinite max Y
constraint).

Does that help?
Chris
Details
Message ID
<NeddC7n--B-9@tutanota.com>
In-Reply-To
<CAFcc3FTwBy44OTj4qh1qkVG0oZi1uJx2Zo6ktbFmsgFCEbDN2Q@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
Ok, I got it, I should move drawCircle part onto Area.Layout. Now it works, many thanks.
Sep 18, 2023, 20:21 by christopher.waldon.dev@gmail.com:

> On Mon, Sep 18, 2023 at 1:02 PM <gdaarb@tutanota.com> wrote:
>
>>
>>
>> I want to draw circle inside some area(widget.Border) at point where user made mouse click.
>> After reading documentation I was able to find how handle mouse events inside widget,
>> but position of event seems related to window itself.
>> So what is right way to obtain widget-related position? (directly or via shifting "global" position).
>>
>
> The pointer.Event.Position field is a coordinate relative to the
> origin of the clipping area that registered the input handler.
>
> More concretely, the most recent clipping area pushed when you do
> `pointer.InputOp{}.Add()` will define the coordinate space for the
> input events routed to that input handler. The point (0,0) is the
> drawing origin of that clipping area (not of the window) for the
> emitted pointer events.
>
> In your example, you define that area on line 142 by setting the
> dimensions of the clipping area to gtx.Constraints.Max. This will make
> the coordinates similar to the global window
> coordinates, though they should be shifted downwards by your buttons.
> (as a side note, your input area will have effectively-infinite
> height, as a vertical list provides an effectively-infinite max Y
> constraint).
>
> Does that help?
> Chris
>
Details
Message ID
<CAFcc3FR7b1ewN+g2Ymb6ZU+WBBAbQo3Cxsd7qmpJPHmmNdWbAg@mail.gmail.com>
In-Reply-To
<NeddC7n--B-9@tutanota.com> (view parent)
DKIM signature
pass
Download raw message
On Mon, Sep 18, 2023 at 2:54 PM <gdaarb@tutanota.com> wrote:
>
> Ok, I got it, I should move drawCircle part onto Area.Layout. Now it works, many thanks.

Precisely! I'm sorry for not putting it more clearly. I made a
cleaned-up version that may be useful as a reference. I basically
removed layout code that didn't really have an impact on the final
layout:

https://go.dev/play/p/YfanMNBgMbN

Cheers,
Chris
Reply to thread Export thread (mbox)