Search Unity

Question How do I even use this TabButton and TabbedView?

Discussion in 'UI Toolkit' started by Sluggy, Mar 23, 2023.

  1. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    989
    Yesterday I had started working out the details of how to implement custom controls so that I could implement tabbed views when I suddenly discovered that such a thing already existed... sorta. Anyway I played around with the TabbedView and TabButtons for a bit and simply could not make heads nor tails of it. After reading through the source code I gave it a few more goes and got a little bit of progress but it still seems extremely convoluted and quite buggy. Elements keep disappearing and reappearing from both the editor view AND the hierarchy itself. Somtimes the tabbed buttons seem to work and other times they appear to do nothing. At the moment I can't even try to fix it because half of my controls are missing from the hierarchy. I've just been randomly clicking around and playing with things until they reappear at which point I can make one change before they go missing again. So what's the deal with these controls? Are they working properly? If so, can we get some kind of guide on how to use them?

    Also while I'm here I figure I'll give another slight minirant. Feel free to skip this part unless you are a Unity dev and interested in some feedback: Overall I like the idea of UIToolkit but it leaves a lot to be desired. I won't go into all of the details here but two major deficiencies go hand-in-hand with this post. 1) UIToolkit WOEFULLY under represents the number of UI controls needed to do any kind of serious work. There is no real GUI library in the world that would only give a handful of very basic controls and then tell its devs 'here you go, if you want more just make your own'. This is one of the serious mistakes that uGUI made. Let's not go down that road again, okay? 2) The work needed to make your own custom controls is absolutely absurd. This is especially true when you consider that devs will absolutely have to make their own controls due to the lack of default options. Maybe I'm just spoiled from years of using stuff like MFC, WinForms, and WPF but jeeze. I've never had to spend more than a few minutes in most cases writing the boilerplate for custom controls. Usually most of the work is the logic of the control itself but the hoops one needs to jump through in order to get a basic control capable of displaying and serializing data for the sake of the UIBuilder's inspector is way overboard. Assuming work ever resumes on UIToolkit and it doesn't just fall into the wastebin please consider giving another very serious pass to this aspect in particular.
     
  2. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Hi. I hadn't heard about UI Toolkit TabbedView and TabButton elements made by Unity, so this peaked my curiosity. All references I could find to these elements where in the Shader Graph package. If those are the elements you are talking about, I'm not sure it's a good idea to use them. It seems someone forgot to make that class internal; it's not even in a namespace. I feel like it merits a bug report, but I'm not sure about how easy it'd be to convince QA that it's a bug, as it technically doesn't break anything, even though it really feels like a mistake. If someone from Unity is reading this, I'd really appreciate some insight.

    Now, if you don't need the ability to remove tabs, I have a TabbedView on GitHub that could help you. Here's a link to a doc page with an example, and here's a link to the package's repo on GitHub. It doesn't have UXML support; I couldn't think of a nice way of having UXML support that didn't also require user code anyway, so I chose to make usage of this element with code as easy as possible instead.

    I'm curious about this. I've found it a bit tricky to learn sometimes, but once one learns this, I don't think it's that much work. I usually can write the code for a custom UITK element in a few minutes too. In case it helps, I've read somewhere that there's work being done on making adding UXML support to custom elements easier, I imagine this would be done with C# attributes on Elements and their C# members.
     
    Last edited: Mar 23, 2023
    Sluggy likes this.
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,929
    Worth noting UI toolkit is still in semi-early development. Most likely more will be added in time, though the devs are working on getting a lot of more pertinent foundational systems working if you check the roadmap.

    I don't agree with this either. Funnily enough I started working on my own tabbed view for runtime (I called it TabGroup though) and got it working in at least a basic level in only an evening of messing about. Even works vertically and horizontally.

    A lot of things with UI Toolkit did feel 'wrong' at the beginning, though I found out I had just not learned the ideal way to do certain things. The more I've learnt about it, the easier its been getting. It does have a much, much higher floor than uGUI, I'll admit.
     
  4. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    989
    I mean, it's been like four or five years now. Shouldn't we be way past the 'pertinent foundational systems' part of development? It gives me vibes similar to the new Input system all over again. lol

    As for the self-rolling solution - that's exactly what I ended up doing. In fact it took far less time to write my own than what I spent faffing about with the one provided (which I'm pretty sure was ad-hoc anyway since it appears to be under the shadergraph namespace of all things). And sure, it only took me a couple of hours of research and tinkering and, thankfully, a very helpful post. But again, this is all so that I can recreate a control that I would just expect to exist. And again, in something like WPF (which is considered a very high-barrier-to-entry) it takes about three lines of code to create a custom control and expose a property so I think it could be much simpler than it currently is (i.e. code-behind and generators). And since they are apparently still working in the foundational stuff, I don't see the harm in reconsidering this aspect in particular.

    Anyway, I did eventually kinda sort get the unity-provided tab buttons working. Exiting Unity and restarting it seems to have corrected the binding target issues for the views that each button controlled. And apparently when the views disappear I had to hit save in order to get things to work properly again. Unfortunately the styling of the tabbed buttons seems to be impervious to modification so I rolling my own ended up just being the only seemingly viable route to the end goal even after I figured out how to get the controls working on a mechanical level.