Adding a DTextEntry to a DMenu

Does anyone know how to add a DTextEntry to a DMenu and have it able to receive text input? I’ve tried all that I can imagine would do it and nothing works. For instance:

a = DermaMenu()
f = a:AddSubMenu(“asdf”)

Makes the thing look correct and your mouse turns into a text-editing type of cursor, but the flashing bar does not appear in the DTextEntry and you cannot type into it.

Does anybody know of a solution?


Apparently, for DTextEntry panels to work, they need to be parented to a DFrame and the frame needs be MakePopup’d. Otherwise they won’t have proper mouse/keyboard input.

If you do what you said, MakePopup() makes the window go to the top left corner of the screen and it is still unable to receive input.

Make an invisible DFrame, parent your panel to it and then parent the DTextEntry to the panel.

That’s exactly what I’m doing, but it still doesn’t work.

If you’ve still got a problem when I get back, ask me on Steam. Will be away for around an hour - two hours. I’d post code though, so someone else can help.

I think the solution is going to be this:

When you add your options to the DMenu, you do it all before the submenus are actually opened. So what I think is going to have to be done is to overwrite the equivalent of the SubMenu’s “OnCursorEntered” function to add the options at that time, instead of adding them to the submenu at the time that the main menu is created. Since I’ll be gone for a while, can somebody figure out the sequence of keys to get to the OnCursorEntered function for a submenu? You can use panel:GetTable() to experiment. If no one’s done it by the time I finish, I’ll try it and post the results.

[lua]local Lolentry = vgui.Create( “DTextEntry”, ParentPanelHere )
Lolentry:SetPos( 20, 30 )
Lolentry:SetTall( 20 )
Lolentry:SetWide( 160 )
Lolentry:SetEnterAllowed( true )
Lolentry.OnEnter = function()
–Code to do when player presses enter
This should do it

You have no idea what we’re talking about.

On another note, I kinda got it to work. You must :AddSubMenu on your DMenu without adding any options to it, then you have to overwrite the OnCursorEntered function of the item that has the little side-arrow on it (which are stored in and accessed by dmenu.Panels) to

  1. Execute the old OnCursorEntered function
  2. Create a DTextEntry without a parent (you can parent it if you want to but it doesn’t make a difference)
  3. MakePopup the DTextEntry
  4. Set it’s position in screen coordinates by using :LocalToScreen on self

And then overwrite the OnCursorExited function of the item to

  • Snipped, read the edit

And remember, what is returned by dmenu:AddSubMenu is the DMenu that is opened when you mouse over the main dmenu’s new submenu that you have just created. It is not the entry that has the little arrow on it, and it is not what you want. You have to access the thing by going through the member table Panels of the dermamenu, which stores all the dmenu’s items.

So it’s kinda cheating because you’re not really adding an DTextEntry to a DMenu, you’re just overwriting the onmouseover to open one. But if you do add it as any items to the new SubMenu, it will draw on top of the DTextEntry even if you set it as the parent, etc. which is a wierd bug. dtextentry:SetZPos(9999) doesn’t help either.

I hope this helps somebody in the future.


Actually, if you want to be able to move your mouse over the dtextentry without it closing, instead of overwriting the OnCursorExited function to close the DTextEntry, make a method on the DTextEntry called Hide() and in Hide, do


and then, in OnCursorEntered, as the last thing you do, do