Creating a context menu

I have two widgets, each containing a list of another widget. So if list A’s member is clicked, some options should appear and if list B’s member is clicked, some other options should appear.
In the future, there’s probably going to be more widgets or maybe even clickable actors.

So I thought that creating one widget to hold the options might be a good idea. But what is the logic or methodology behind a context menu? When I want to open the context menu, should I tell the clicked object “you should open the context menu”, and it sends a list of actions that can be done to that object to the context menu?
Or would each object have its own individual widget?

If anyone would like to share some insight, i’d appreciate it.

So the first thing I tried was pretty simple:
When something is clicked, a function executes that tells the clicked object to open the context menu.
Each object has an array of actions and sends that array.
The context menu creates buttons for each action, getting the button index that is clicked, sending back that index to the object.
The object, using that index, gets the index of the actions and performs that action.
Very simple and works really well.

However, often data is associated with options. So an action might be to go to a location. Well, then that location needs to be sent from the context menu to the object. Or it might have something to do with an actor, or another actor class. Getting that data back to the object proved difficult. Additionally, I didn’t want to clutter the context menu with methods, rather I wanted the button to know what is needed and only that.

So now, a button has a specific task - if it is clicked, get whatever data it is designed to get and send it directly to the object.
The Object still has the actions array. If the action requires data, a specific widget have been designed for that action and the context menu will add that widget.
If no data is needed, the previous method is used to send back the action index.

What I don’t like about this new method is that when the context menu is created, it creates each type of these special data-fetching widgets. So practically I have a context menu that has all possible actions that ANY object could make, it’s just not showing them. It feels like this defeats the purpose of a context menu, even if from a user perspective, it seems like any context menu.

Any thoughts on that would be appreciated.

Well, I have redesigned the implementation for a third time.
This time, there’s an actor component and an interface that returns the actor component. So now every actor that have a context menu, just have to have this actor component and interface.
In the actor component, is an “exposed to instance” list of the UObject class: Context Item. So that each actor can now add its context items that should be displayed in the context menu.
The actor component creates an instance of each UObject of the context items, which now hold its own logic for what needs to be done.

The problem I have run into now, is the context items that should have a submenu. For example a ‘Which waypoint to go to?’ item, which should reveal a submenu, showing each waypoint. The ‘Which waypoint to go to?’ context item needs to be aware of which sub item was selected.