Jump to content

FindChild with name instead of text


Andy90
 Share

Recommended Posts

Hello :) based on the Discord conversation, I suggest modifying the FindChild function by recommending the use of a name variable instead of the text variable. The reason behind this suggestion is straightforward: Imagine you have a panel with 5 labels, and you want to change the texts of these labels. To achieve this, you would need to store all five labels individually, as using FindChild with the text variable might not work accurately when the text is modified. Additionally, the name variable typically remains unchanged, enhancing the reliability and simplicity of locating and modifying labels in a panel. 

Link to comment
Share on other sites

This just seems confusing to me. Why would you not use a variable, if you need a handle to that object?

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

It's more about being able to save, for instance, only the UI panels and then retrieve all other necessary objects from this single panel. While it's technically possible to store all variables in a global header, managing multiple variables for changes could become overwhelming. The idea is to streamline and minimize the number of global variables for improved organization and simplicity.

Link to comment
Share on other sites

I suggest using this UIElement class for handling groups of UI elements:
https://github.com/UltraEngine/Extras/tree/main/Code/Utilities

This is how I handle all the major "areas" in the editor interface. You create a derived class and store variables for all the widgets you create in the class, then call Listen() to intercept the events you want to process in your ProcessEvent override.

Note that UIElement is not a widget, it is just a container for storing widgets and responding to events.

class MainPanel : public UIElement
{
public:
	shared_ptr<Widget> panel, button;

	bool Initialize(int x, int y, int width, int height, shared_ptr<Widget> parent)
	{
		panel = CreatePanel(x, y, width, height, parent);
		button = CreateButton("TEST", 20, 20, 80, 30, panel);
		Listen(EVENT_WIDGETACTION, button);
		return true;
	}
      
	bool ProcessEvent(const Event& e)
	{
		if (e.id == EVENT_WIDGETACTION and e.source == button)
		{
			Print("PRESS");
			return false;// stop processing this event
		}
		return true;// allow other hooks to process the event
	}
};

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...