x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Dynamically set widget position on canvas panel?

I have been using SetRenderTransform and AddToViewport on my context menu until now, which pops up wherever you hold the right button. The problem is that there is nothing to stop the menu from extending beyond the viewport limits. I tried to clamp the render transform using the widget's DesiredSize, but it's always zero.

Then I figured it might be best to attach the menu to a "global" canvas panel filling out the whole screen and enable "Clip To Bounds" on it, so the whole thing is handled automatically. But no matter what I do, the menu always shows up on the very top-left corner.

How can I position it at my original render transform?

Product Version: UE 4.20
Tags:
more ▼

asked Oct 20 '18 at 12:34 PM in Using UE4

avatar image

MaxPower42
643 67 82 118

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Dynamically set widget position on canvas panel?

Get widget > As Canvas Slot - set Size / Position.

more ▼

answered Oct 20 '18 at 01:33 PM

avatar image

Everynone
15.2k 77 25 62

avatar image MaxPower42 Oct 20 '18 at 01:50 PM

Now the position gets set, but the menu still extends beyond the edge of the viewport...

avatar image Everynone Oct 20 '18 at 01:53 PM

Can you show the hierarchy so we're both sure what we're dealing with. And what is the desired result, exactly? A full screen widget the size of the canvas?

Also, are you using anchors at all?

edit: I can swear I just saw your name on the forums

avatar image MaxPower42 Oct 20 '18 at 04:08 PM

The hierarchy is: I have a kind of root-widget that all other UserWidget-derived widgets are either a part of, or they get dynamically attached to and removed from a panel of it. The root-panel of everything is a canvas in this root-widget. Like I described in the original question, I was hoping I could stop my context menus from being partly off-screen when clicking near the right or bottom edge by using the panel's "Clipping" property. They are rather small, not full screen. I don't know how to use anchors dynamically. The only function I found related to anchors was "Set Anchors In Viewport" and I'm not sure how to use it.

... and you probably saw my name here : https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/120495-widget-out-of-screen-when-opened-with-an-event

avatar image Everynone Oct 20 '18 at 04:19 PM

They are rather small, not full screen. I don't know how to use anchors dynamically. The only function I found related to anchors was "Set Anchors In Viewport" and I'm not sure how to use it.

Does not need to be dynamic. Let's say I need this element to always be in the bottom right corner, no matter the size:

alt text

Click the anchor normally, then shift-click it, and then control-click it. This will set all the pivots and alignment automatically so you do not need to punch it in manually.


If for some reason you need to use it dynamically, you can get access to the canvas slot (as in the original answer) and set the anchors and other slot related settings.

But setting the pivots should just work fine. Even for elements that resize dynamically. An expandable menu in the bottom right corner of a screen:

Image from Gyazo

Does it help?

untitled.png (37.7 kB)
avatar image MaxPower42 Oct 20 '18 at 04:30 PM

My context menus open in a way that their upper left corner is at the mouse cursor (with a margin so that the cursor is on top of it). I only want to shift them when they would otherwise escape the screen, so using a bottom-right anchor for all wouldn't be much help, I think. And then I would have the same problem in the upper left corner. But your forum reply should have the solution for me.

avatar image Everynone Oct 20 '18 at 04:33 PM

Ah, I see. Then yes, you should be able to predict the the desired size with force prepass and offset it accordingly.


Alternatively, you can read the location of the cursor and compare it to viewport size. If the location of the cursor + widget size would exceed the dimensions of the screen, offset the widget position by the desired distance from the screen edge.

The above is a decent method if you want the icons to stick to the edge of the screen - like indicators for objects that have moved off-screen. Or for keeping a widget inside the screen space even if the object has left it.


Anyhow, glad you found a solution.

Good luck with the rest!

avatar image MaxPower42 Oct 20 '18 at 05:10 PM

Yes, I just clamped the final position (top-left corner) to viewport size minus widget size. Works as expected. And thanks again!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question