Search Unity

Show TextField on double click on Foldout (like in Hierarchy)

Discussion in 'Immediate Mode GUI (IMGUI)' started by androshchuk-vladyslav, Sep 14, 2017.

  1. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    Hi Guys,
    I need to realize the feature like in Hierarchy view: When click on Label (Foldout) change it to TextField (and focus it) than if lose focus change to Label back.

    I tried different ways but all of they not perfect. Thanks a lot!
     
  2. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Maybe you can get some inspiration from the UnityDecompiled repository hosted by MattRix. You can see how the built-in GameObject hierarchy renaming is implemented in there. It actually has quite a few moving parts.

    The `TreeViewGUI.cs` has some functions called `BeginRename`, `EndRename`, and `DoRenameOverlay`. There's also the `RenameOverlay.cs` class which handles most of the functionality. The renaming is triggered by `TreeView.cs`. The triggering happens by pressing F2. It also passes mouse up clicks to the `RenameOverlay` with a delay, and if there isn't another click and the delay timer expires, it will show the TextField.

    The main GameObject tree code is in `GameObjectTreeViewGUI.cs`.

    Sorry I don't have an easy answer, but it isn't a super easy thing to implement. It isn't exactly hard I think, but there are a lot of parts to it!

    -sam