Digital Native Studios

TextMeshPro => Feature Requests => Topic started by: Jasper Flick on February 04, 2016, 06:19:17 AM

Title: TextMesh Pro Dropdown List
Post by: Jasper Flick on February 04, 2016, 06:19:17 AM
Stephan and I have created an alternative for the Unity UI dropdown list (http://docs.unity3d.com/Manual/script-Dropdown.html). It uses TextMesh Pro labels instead of standard Text labels. The package contains a script for the component and another script for its editor support. It was made with TexMesh Pro 0.1.52 beta 3.1 and Unity 5.3.1.

You can create a default dropdown via GameObject / UI / TextMeshPro Dropdown. Its menu position is right above the default dropdown. This gives you a dropdown with three items and scrolling support, the same as Unity's default.

The dropdown component is Unity's own code (https://bitbucket.org/Unity-Technologies/ui) with minimal tweaks. Some other code needed to be copied as well, because it's not accessible outside Unity's own DLLs.

Note that the dropdown isn't very memory friendly. It creates and destroys objects and starts corourtines when interacted with. Not really an issue for desktops, but something to keep in mind for mobiles.
Title: Re: TextMesh Pro Dropdown List
Post by: Ha7den on February 04, 2016, 07:14:08 PM
Wow I was just logging on to suggest this! Thank you guys.
Title: Re: TextMesh Pro Dropdown List
Post by: timothyallan on February 06, 2016, 05:47:23 PM
Fantastic, going to work with this very soon.
Title: Re: TextMesh Pro Dropdown List
Post by: Henning on April 08, 2016, 07:45:39 AM
Love it :) Saved me a lot of time... Again. :D

I do have a small question, is it the implementation you did that is having problems with masks? or is it Unity and multiple masks within a canvas hierarchy?
[attach=1]
As you can see the main object of the Dropdown follows the mask as expected, but the Dropdown part, ignores the mask, and the text is gone as soon as I activate a mask on a parent object.

I'll keep digging for answers, but any feedback would be appreciated :)
Title: Re: TextMesh Pro Dropdown List
Post by: Jasper Flick on April 09, 2016, 09:09:10 AM
When using a Mask component, a nested dropdown list will ignore the mask when opened. This happens because it overlays a new canvas which overrides the sorting order. If you don't want that, you can use a RectMask2D component instead of a Mask. It uses stencil clipping instead of masking. Unity does apply the stencil to the overlaid canvas, even when it overrides the sorting order. Whether this difference is intentional or a bug, I do not know.

Unity's UI is unfortunately inconsistent and buggy when masking is involved. TextMesh Pro is rather vulnerable to the masking shenanigans, but Unity's own stuff also runs into consistent trouble. I have submitted another bug report relevant to this issue.
Title: Re: TextMesh Pro Dropdown List
Post by: Henning on April 10, 2016, 05:05:34 AM
Thanks for the feedback :)

RectMask2D solved my problem, as I only need rect mask for this project.


Title: Re: TextMesh Pro Dropdown List
Post by: callguinness on May 29, 2016, 03:47:06 PM
Thanks so much for this Dropdown add-on.

FYI this broke in the Unity 5.4 betas (TextMeshProUGUI MissingReferenceException as soon as you select anything).

Edit: It seems they removed an IsActive() check from Graphic.cs for some reason?
Title: Re: TextMesh Pro Dropdown List
Post by: Stephan B. on May 30, 2016, 03:22:53 PM
Thanks so much for this Dropdown add-on.

FYI this broke in the Unity 5.4 betas (TextMeshProUGUI MissingReferenceException as soon as you select anything).

Edit: It seems they removed an IsActive() check from Graphic.cs for some reason?

I am looking to see where they shifted this IsActive().
Title: Re: TextMesh Pro Dropdown List
Post by: Stephan B. on June 01, 2016, 02:45:52 PM
Gah! Just spend two days tracking down this issue due to changes Unity made to the GraphicRegistry handling and caching of the Canvas as the Dropdown changes parenting of objects.

This is now fixed on my end. I have also included the Dropdown into TextMesh Pro so it will no longer be necessary to download this version separately.
 
Title: Re: TextMesh Pro Dropdown List
Post by: callguinness on June 02, 2016, 01:58:01 PM
Awesome, you're the best.
Title: Re: TextMesh Pro Dropdown List
Post by: patrick_c on June 04, 2016, 09:18:38 PM
Thanks very much for this, I just purchased TMP this morning, and before evening I was able to convert the whole project (2 1/2 years of work) to TMP, and rip out every instance of UIText/UIInputField/UIDropdown.
Freedom!
Title: Re: TextMesh Pro Dropdown List
Post by: fisj on June 21, 2016, 12:24:47 PM
Hi Stephan,

Having some issues getting TMPro text to actually show in the dropdown options tmpro text if its inside a scrollview. It looks like this is related to masks and the sort order. If the parent scroll view doesn't have a mask the TMPro dropdown shows the text fine, but using a Mask or 2DRect mask, the text won't display. Similarly, disabling the sort order on the dropdown canvas works also, but that's also undesirable.

I'm using TMPro 0.1.54b3, Unity 5.3.3.3p3.

PS. We love TMPro, it's seriously saved our bacon on our game UI. Huge thanks for all your hard work.

(http://www.deadhold.com/wp-content/uploads/2016/06/masked_sorting_issue.jpg)

Title: Re: TextMesh Pro Dropdown List
Post by: Jasper Flick on June 21, 2016, 12:59:38 PM
Using a RectMask2D on the viewport should work, at least for Unity 5.3.4 and up. Unfortunately, Unity's new UI isn't mature yet and can change a lot between point releases.
Title: Re: TextMesh Pro Dropdown List
Post by: fisj on June 21, 2016, 01:27:07 PM
I just tried 5.3.4 as per your suggestion, and sure enough the Rect Mask 2D works. You're right, I am surprised that a single point release was that much of a change, but happy to have it work. Much obliged!
Title: Re: TextMesh Pro Dropdown List
Post by: patrick_c on June 25, 2016, 06:19:17 PM
I noticed a small thing, not sure if the standard Unity dropdown behaves the same way or not.
We have a pretty long drop-down, players select an option somewhere in the middle after scrolling a few pages.
Next time they open the drop-down again, it's all the way up-top, and if they want to select the next option to the one they have currently selected, they have to scroll all the way down again, and so on.
I added this at the bottom of the Show() method in TMP_Dropdown.cs to change it so it auto-scrolls down to the currently selected item:
Code: [Select]
contentRectTransform.anchoredPosition = new Vector2(0, m_Value * itemSize.y);

Just thought someone might find it useful, could be nice to have it as an option in the Dropdown (ex: "Auto-scroll to selected item when opening" or similar).

Thanks!
Title: Re: TextMesh Pro Dropdown List
Post by: Stephan B. on June 25, 2016, 06:27:19 PM
I noticed a small thing, not sure if the standard Unity dropdown behaves the same way or not.
We have a pretty long drop-down, players select an option somewhere in the middle after scrolling a few pages.
Next time they open the drop-down again, it's all the way up-top, and if they want to select the next option to the one they have currently selected, they have to scroll all the way down again, and so on.
I added this at the bottom of the Show() method in TMP_Dropdown.cs to change it so it auto-scrolls down to the currently selected item:
Code: [Select]
contentRectTransform.anchoredPosition = new Vector2(0, m_Value * itemSize.y);

Just thought someone might find it useful, could be nice to have it as an option in the Dropdown (ex: "Auto-scroll to selected item when opening" or similar).

Thanks!

Good suggestion. I'll take a look at adding the option.
Title: Re: TextMesh Pro Dropdown List
Post by: patrick_c on July 02, 2016, 03:29:52 PM
A quick follow-up on the above, I had forgotten to check for the maximum bounds, so when pre-selecting the last few elements it would look weird.
Replaced with:
Code: [Select]
float yOffset = m_Value * itemSize.y;
yOffset = Mathf.Clamp(yOffset, 0, contentRectTransform.sizeDelta.y - dropdownRectTransform.sizeDelta.y);
contentRectTransform.anchoredPosition = new Vector2(0, yOffset);
Title: Re: TextMesh Pro Dropdown List
Post by: LutzTH on August 27, 2016, 08:57:06 PM
Using a RectMask2D on the viewport should work, at least for Unity 5.3.4 and up. Unfortunately, Unity's new UI isn't mature yet and can change a lot between point releases.

It seems this doesn't work on 5.3.5, at least for me. Any suggestions?
Title: Re: TextMesh Pro Dropdown List
Post by: Stephan B. on August 27, 2016, 11:44:49 PM
Using a RectMask2D on the viewport should work, at least for Unity 5.3.4 and up. Unfortunately, Unity's new UI isn't mature yet and can change a lot between point releases.

It seems this doesn't work on 5.3.5, at least for me. Any suggestions?

What version of TextMesh Pro are you using and what specific issue are you running into? (The version # is located in the header of the TextMeshPro.cs file)

Can you provide the steps to reproduce this issue?
Title: Re: TextMesh Pro Dropdown List
Post by: LutzTH on August 28, 2016, 07:43:35 AM
I think I solved it. There was a mask on the panel in which hierarchy the dropdown was. Changed the panel to RectMask2D.
It`s a bit annoying, because if you turn Override Sorting off in the dropdown, it works with a normal mask on this panel. That's tricked me in the first place.

TextMeshPro Version is btw 1.0.54. The latest from the asset store.
 
Title: Re: TextMesh Pro Dropdown List
Post by: ARafay on September 04, 2016, 03:15:27 AM
Hi Stephan,
I'm using TMPro Dropdown in an app and some time when i click dropdown to select an item, it doesnt show all the items, but when i click on side dropdown edges and scroll then it layout its item fine. Please see the attached gif.
Thanks
http://www.giphy.com/gifs/l0MYwxizsIUppXBjW
Title: Re: TextMesh Pro Dropdown List
Post by: Stephan B. on September 04, 2016, 03:24:17 AM
Hi Stephan,
I'm using TMPro Dropdown in an app and some time when i click dropdown to select an item, it doesnt show all the items, but when i click on side dropdown edges and scroll then it layout its item fine. Please see the attached gif.
Thanks
http://www.giphy.com/gifs/l0MYwxizsIUppXBjW

Since the Dropdown is based on Unity's own Dropdown, I will have to check if they might have fixed some of those issue in the Unity 5.4 release.

Since it is almost 3:30 AM, I will have to check tomorrow but in case you feel adventurous, here is a link to the source code of their Dropdown (https://bitbucket.org/Unity-Technologies/ui/src/df1947cdc2e411670a57f07fc1510023ade05925/UnityEngine.UI/UI/Core/Dropdown.cs?at=5.4&fileviewer=file-view-default) where you might be able to find the potential source / solution.
Title: Re: TextMesh Pro Dropdown List
Post by: ARafay on September 05, 2016, 01:53:34 AM
Hi Stephan,
I'm using TMPro Dropdown in an app and some time when i click dropdown to select an item, it doesnt show all the items, but when i click on side dropdown edges and scroll then it layout its item fine. Please see the attached gif.
Thanks
http://www.giphy.com/gifs/l0MYwxizsIUppXBjW

Since the Dropdown is based on Unity's own Dropdown, I will have to check if they might have fixed some of those issue in the Unity 5.4 release.

Since it is almost 3:30 AM, I will have to check tomorrow but in case you feel adventurous, here is a link to the source code of their Dropdown (https://bitbucket.org/Unity-Technologies/ui/src/df1947cdc2e411670a57f07fc1510023ade05925/UnityEngine.UI/UI/Core/Dropdown.cs?at=5.4&fileviewer=file-view-default) where you might be able to find the potential source / solution.

I leave this in your capable hands :)
Just so you know im using Horizontal Layout Group and DropDown is inside it, i have applied LayoutElement with ignoreLayout = true to DropDown's List So it appears on clicking.
Title: Re: TextMesh Pro Dropdown List
Post by: Stephan B. on September 05, 2016, 01:55:56 AM
Hi Stephan,
I'm using TMPro Dropdown in an app and some time when i click dropdown to select an item, it doesnt show all the items, but when i click on side dropdown edges and scroll then it layout its item fine. Please see the attached gif.
Thanks
http://www.giphy.com/gifs/l0MYwxizsIUppXBjW

Since the Dropdown is based on Unity's own Dropdown, I will have to check if they might have fixed some of those issue in the Unity 5.4 release.

Since it is almost 3:30 AM, I will have to check tomorrow but in case you feel adventurous, here is a link to the source code of their Dropdown (https://bitbucket.org/Unity-Technologies/ui/src/df1947cdc2e411670a57f07fc1510023ade05925/UnityEngine.UI/UI/Core/Dropdown.cs?at=5.4&fileviewer=file-view-default) where you might be able to find the potential source / solution.

I leave this in your capable hands :)
Just so you know im using Horizontal Layout Group and DropDown is inside it, i have applied LayoutElement with ignoreLayout = true to DropDown's List So it appears on clicking.

So I don't have to spent too much time trying to reproduce the setup / behavior, can you provide me with a simply Repro Scene?
Title: Re: TextMesh Pro Dropdown List
Post by: ARafay on September 07, 2016, 04:36:21 AM
Hi Stephan,
I'm using TMPro Dropdown in an app and some time when i click dropdown to select an item, it doesnt show all the items, but when i click on side dropdown edges and scroll then it layout its item fine. Please see the attached gif.
Thanks
http://www.giphy.com/gifs/l0MYwxizsIUppXBjW

Please ignore this issue for now as i tried reproducing it but failed.
I hope you can share a beta with input fixes soon. thanks
Since the Dropdown is based on Unity's own Dropdown, I will have to check if they might have fixed some of those issue in the Unity 5.4 release.

Since it is almost 3:30 AM, I will have to check tomorrow but in case you feel adventurous, here is a link to the source code of their Dropdown (https://bitbucket.org/Unity-Technologies/ui/src/df1947cdc2e411670a57f07fc1510023ade05925/UnityEngine.UI/UI/Core/Dropdown.cs?at=5.4&fileviewer=file-view-default) where you might be able to find the potential source / solution.

I leave this in your capable hands :)
Just so you know im using Horizontal Layout Group and DropDown is inside it, i have applied LayoutElement with ignoreLayout = true to DropDown's List So it appears on clicking.

So I don't have to spent too much time trying to reproduce the setup / behavior, can you provide me with a simply Repro Scene?
Title: Re: TextMesh Pro Dropdown List
Post by: pixpusher on September 11, 2016, 07:46:27 AM
Hi there,

I just recently tried using TMP's Dropdown and seem to have encountered the same old Unity Dropdown bug. The bug was fixed in later Unity versions but seems to have cropped up in TMP's version this time.

The issue was that Dropdown only worked a single time when Time.timeScale has been set to zero (game paused). Subsequent clicks on it doesn't pop up the list anymore.

Looking at the TMP_Dropdown.cs file, I noticed that line 617 has been commented out. Enabling it and commenting out line 616 fixed the issue on TMP since I'm running on 5.4.

Just letting you know. Cheers
Title: Re: TextMesh Pro Dropdown List
Post by: Stephan B. on September 11, 2016, 12:22:45 PM
Hi there,

I just recently tried using TMP's Dropdown and seem to have encountered the same old Unity Dropdown bug. The bug was fixed in later Unity versions but seems to have cropped up in TMP's version this time.

The issue was that Dropdown only worked a single time when Time.timeScale has been set to zero (game paused). Subsequent clicks on it doesn't pop up the list anymore.

Looking at the TMP_Dropdown.cs file, I noticed that line 617 has been commented out. Enabling it and commenting out line 616 fixed the issue on TMP since I'm running on 5.4.

Just letting you know. Cheers

Thanks for reporting the issue and looking into it as well.

I'll take a look and make the necessary changes.
Title: Re: TextMesh Pro Dropdown List
Post by: caio_lib on February 16, 2017, 11:42:14 AM
Hi!
I'm having the same problem but I can not replace Mask for RectMask2D because the mask does not work in the same way.
I made a package to show an example but using TextMesh Pro, I'm not sure if I could upload the package.
The version of TextMesh I use 1.0.54.

Could someone help me? Thank you!
Title: Re: TextMesh Pro Dropdown List
Post by: Stephan B. on February 16, 2017, 12:12:33 PM
Hi!
I'm having the same problem but I can not replace Mask for RectMask2D because the mask does not work in the same way.
I made a package to show an example but using TextMesh Pro, I'm not sure if I could upload the package.
The version of TextMesh I use 1.0.54.

Could someone help me? Thank you!

You can safely upload the package here or just email it to me at Support@DigitalNativeStudios.com
Title: Re: TextMesh Pro Dropdown List
Post by: caio_lib on February 16, 2017, 12:37:59 PM
Hi Stephan B.,

Thank you very much for your quick response!

Package attached!