#🧰┃ui-toolkit

1 messages · Page 11 of 1

gusty estuary
#

no

#

but it's definetely will cause problems with compatibility

#

in case someone else would like to use dependency

#

which includes System.CompilerServices.Unsafe

#

so I think how to fix that

gusty vapor
#

yeah, it's not portable enough sadly kekwait

gusty estuary
#

either I use openupm dependency

#

and my package requires about 4 lines

#

or I use both options via compilation constraints

#

but honestly, I just want nugget

#

🥲

gusty vapor
gusty estuary
gusty vapor
gusty estuary
gusty vapor
#

can we just tuck in stuffs in manifest.json and be done or is it not possible?

#

man, if only jsonutility or even Unity's newtonsoft weren't suck so bad

gusty estuary
#

jsonutility is good when serializing game objects

gusty vapor
#

yeah, can't be used in Unity

#

dynamic il

gusty estuary
#

Dont think I use it

gusty vapor
#

didn't your mvvm toolit built using windows comminity toolkit?

gusty estuary
#

Not windows one

gusty vapor
#

where did you get the nuggete?

gusty estuary
#

from nugget

#

kekw

gusty vapor
#

yes that's the same dude who created it

gusty estuary
#
gusty vapor
#

he's the creator

gusty estuary
#

I know

gusty vapor
#

mic employee.. active member of c# disc too

gusty estuary
#

I know

#

kekw

gusty vapor
#

did you check his PolySharp repo as well?

gusty estuary
#

no

gusty vapor
#

I wonder tho, if we can use that in unity

gusty estuary
#

not sure on usage tbh

small wigeon
gusty estuary
#

openupm is 1000 times better

gusty vapor
#

the creator is Unity staff apparently kekwait

#

he's one of c# engineers in Unity

small wigeon
#

lol openupm's nuget support uses UnityNuGet

gusty vapor
#

proly different internals... also makes sense bcos as said he's Unity's employee

small wigeon
#

UnityNuGet is a service that converts nuget packages to unity packages automatically, it doesn't matter how you consume them (git or openupm)

gusty vapor
#

I'm so happy that my vscripting is leak free now UnityChanThumbsUp

small wigeon
#

If there's something on nuget you want you can just add it to their registry

gusty vapor
#

scoped registry packages are almost not the best experience

#

they're not portable

small wigeon
#

what do you mean by portable?

gusty vapor
#

you'd have to add them manually via project settings

small wigeon
#

better than shipping dlls from nuget in your package and causing problems with other packages

gusty vapor
#

if they're dependency free dlls, shouldn't be an issue.. and I prefer that any day

gusty estuary
gusty vapor
#

xoofx

small wigeon
#

if you're talking about dependencies of your own package then using a registry doesn't matter because the user doesn't have to do anything?

gusty estuary
#

it does

#

in openupm you have specify all dependencies (sadly)

#

in nuget package you don't

#

but nuget package also breaks all the time

trail oasis
#

with the 2d painter can the shape generated detect mouse events

trail oasis
#

nevermind im going to use a texture instead

#

writing code for every shape i need is going to take forever

trail oasis
#

is there a way to stop :hover etc from activating if mouse is over the transparent part of the background texture

gusty vapor
trail oasis
#

yeah i cant use the painter though wont let me use textures

#

so what about transparency on sprites

gusty vapor
#

it can

trail oasis
#

since when ? docs says you can't texture the painter atm

gusty vapor
#

anything regular visualelement can do, it can do it too

trail oasis
#

i think it would still be more performant just using a premade sprite of my shape though

#

than generating a mesh

gusty vapor
#

they're vector graphic in a sense, so they consist of just vector lines, similar like in SVG

#

to texture it, you assign to your wrapper class

#

which is a VisualElement

#

painter2d lives in your MeshGenerationContext...

#

MGC is what forms your visualElement's meshes (the order kinda important to understand here)

gusty vapor
#

I tested this intensively when I made my shape gen tool with vector api

gusty vapor
trail oasis
#

is there no way to stop that happening

#

because i dont want hover to occur over the whole visual element

#

in ugui you could set a alpha threshold so it didnt detect mouse over if over transparent pixels on the texture

#

i cant find something similar in ui toolkit

gusty vapor
trail oasis
#

i see

gusty vapor
#

also they're in progress implementing texture atlas in VectorImage class, you can see this if you peek at some of the internal stuffs in VectorImage class

#

so proly custom shader after that 🥹 .. * fingerCrossed

#

vector api + custom shader.. boy many cool stuffs can be done with it 🥹

trail oasis
#

i just hate that we have to write so much code atm

#

i want a hexagon shaped icon

#

i got to fiddle with painter to do it

#

all painter has is arc and line - it needs a collection of basic shapes built in at the very least

#

polygon(radius,numsides) would be nice for hexagons/octogons etc

gusty vapor
trail oasis
#

true

#

been around since 2018 and its still not ready

#

crazy

gusty vapor
#

lmao

gusty vapor
#

and the best of all, making custom editors now are billion-light-years wayy easier with uitk.. it's splendid 🥹

trail oasis
#

easier but more work most likely

gusty vapor
#

that's a valid statement, no lie..😂

gusty vapor
#

even the good ole System.Drawing did it like that too

gusty estuary
trail oasis
#

in a custom element script how do i query for a child element

#

i need to change the width of the child element for a progress bar

#

or is that not possible

gusty estuary
trail oasis
#

how do i setup the references

gusty estuary
#

during element creation

trail oasis
#

i want to be controlling the width of the child element since its a progress bar

#

yes i know but the syntax i meant

#

i cant use Q<T>

gusty estuary
#

query works, but during constructor you don't even need to use it

trail oasis
#

so how do you do it then

#

if query works i dont seem to have access to it in the constructor

gusty estuary
#

MyElement(){
_label = new Label();
Add(_label);
}

trail oasis
#

what?

#

im not trying to create new elements on the fly

#

it already exists

gusty estuary
#

?

#

from uxml?

trail oasis
#

no in a custom element class

gusty estuary
#

then you gotta create it on the fly

trail oasis
#

thats absurd

gusty estuary
#

why

#

that's how all elements are created in uitk

trail oasis
#

because whats the point of templates if i have to create it

gusty estuary
#

templates are for hierarchies

#

not custom controls

trail oasis
#

my CC i want to include the heiarachy so i can control the size of the child element

gusty estuary
#

if you really want to use one

#

load it via Resources

trail oasis
#

so theres no getChild(0) or anything useful like that

gusty estuary
#

during constructor element is empty until you fill it yourself

trail oasis
#

so id have to apply all the styles aswell

gusty estuary
#

only class names

#

take a look at any built in control

#

for example Button

trail oasis
#

that seems a step backwards compared to prefabs they use for gameobjects which work fine

gusty estuary
#

I'd disagree

#

they exist on completely different levels

#

custom control = custom logic

trail oasis
#

do you not make any of your ui modular

#

because its not easy to do it modular

gusty estuary
#

it's not asset

trail oasis
#

because you have to make shit on the fly - writing scripts all day instead of actually making a game

gusty estuary
#

you create all modular controls you need and create hierachies out of them?

#

I mean, I only had a need in one custom control in total

#

square element

#

because there is no such built in functionality

#

everything else I just use built in

trail oasis
#

the way i have it is:

progressbar-background¬
progressbar-foreground

i want the custom element to control width % of the progressbar-foreground

#

so i need to reference to it as a child

gusty estuary
#

then create it via code

#

don't bother with uxml

#

the only way to load uxml like that is via resources

#

and you can imagine how painful that'd be

trail oasis
#

i really dont want to hard code it all encase i change my design weeks later

#

thats so damn silly

#

it might be great for custom tools but it forces you to hard code it all

#

you lose the ability to adapt quickly for new design

gusty vapor
#

some default controls can be accessed directly here's from Toggle class

#

they're available as properties

trail oasis
#

are they creating them in constructor ?

gusty estuary
#

only hierarchy

#

just take a look at Button constructor

trail oasis
#

but hierarchy is the layout and layout changes

#

just as much as styles can

gusty estuary
#

it simply defines all class names

#

and relies on global stylesheet

gusty estuary
#

you can change hierarchy completely

#

but keep frontend same

trail oasis
#

yeh but if you wrote it all in code you have to edit the scripts

gusty estuary
#

that's why it's custom control

#

not template

#

if you want template - just use template

#

by defining custom control you define MonoBehaviour in comparison to game objects, not prefab

trail oasis
#

so like this:

        VisualElement _ele;
        public ProgressBar()
        {
            generateVisualContent += Refresh;
            _ele = new();
            _ele.style.flexGrow = 0;
            _ele.style.height = Length.Percent(100);
            Add(_ele);
        }
        protected virtual void Refresh(MeshGenerationContext context) => _ele.style.width = Length.Percent(_progress);
``` ?
gusty estuary
#

uuugh, why are you using refresh

trail oasis
#

because unity does it ?

gusty estuary
#

just modify it directly in property

#

it's for generating shapes

trail oasis
#

the override uses the context for painter

gusty estuary
#

not for modifying high level api

#

and you don't seem to use painter

trail oasis
#

i do in the override

#

RadialProgressBar : ProgressBar

gusty estuary
#

_ele.style.width = Length.Percent(_progress);

trail oasis
#

that uses painter

gusty estuary
#

just don't do this

trail oasis
#

why not ?

gusty estuary
#

if it wasn't the same value it'd be recursive

trail oasis
#

🤔

gusty estuary
#

you simply write value again

#

causing layout to recalculate again

trail oasis
#

to the child element

gusty estuary
#

but luckily it's smart enough not to do it

gusty estuary
trail oasis
#

unity does the same thing though

#

so you saying i should just apply it in the property setter

gusty estuary
#

yes

#

that's how Label does it

trail oasis
#

hm

#

i see

#

that would break the radial progress bar since that doesn't change width

#

that overrides the refresh method

gusty estuary
#

you override refresh only when you need specifically refresh logic

#

making custom shapes

#

when you modify width - you schedule changes to engine

trail oasis
#

i see

#

so generateVisualContent for displaying the change but not applying any changes

gusty estuary
#

use callbacks for drawing only for drawing

#

if you progress bar is only about modifying width

#

then do it in property setter

#

later in frame layout will do all drawing callbacks

#

if you have those

trail oasis
#

do i not need MarkDirtyRepaint();
in the property then if i change the style width

#

is that redundant?

gusty estuary
#

no, I don't think so

#

just change width

trail oasis
#

okay

gusty vapor
#

if it's related to changing the context, you'd use markdirty otherwise don't

trail oasis
#

wdym by changing the context

gusty estuary
#

I don't follow either

gusty vapor
#

changing shapes, changing visual appearance(physically) that modify the mesh

#

like in TextElement

gusty estuary
#

ah

gusty vapor
#

for common controls, you'd never want to use that

gusty estuary
#

when you don't do width change, no recalculation is scheduled

gusty vapor
#

correct

gusty estuary
#

and if you need to recalculate shape - gotta mark as dirty

trail oasis
#

so my radial bar that uses painter i should use it to redraw the arc?

gusty estuary
#

if your radial bar has constant size and when you change progress you don't apply any styles

#

you should mark as dirty

#

so it makes a generate callback

#

if your progress bar is literally just width

#

you do it in progress property and that's it

trail oasis
#

i see

#

so MarkAsDirty() makes the generateVisualContent invoke

gusty estuary
#

yes, same as any style changes

#

(hopefully unity is smart enough to know what styles modify layout)

gusty vapor
gusty estuary
#

👴

#

omg

#

wtf is that

gusty vapor
#

just use your common sense to understand it, nothing to see there.. lmao

gusty estuary
gusty vapor
#

lmao

trail oasis
#

ah thats a pain i cant apply a class in ui builder for the child i made in the constructor =/

#

so i dont have much freedom to change the style easily

gusty estuary
#

you apply classes during construction

trail oasis
#

i want to change them based on what ever im building not having them applied in the code

gusty estuary
#

usually all relevant custom elements of custom control have unique names

trail oasis
#

its a progress bar for many things

gusty estuary
trail oasis
#

you just said applied in code

gusty estuary
#

you never access style

trail oasis
#

i dont want to write code for every custom progress bar

gusty estuary
#

you only use AddClass

trail oasis
#

yeah but thats code

#

i want to add a class to it in ui builder

gusty estuary
#

why?

#

you can just write styles for that class

trail oasis
#

because im designing my layout in builder

gusty estuary
#

and apply locally

#

so different applications of progress bar have it's own styles

trail oasis
#

i dont want to write code all day for all the combinations of progress bar styles i want

gusty estuary
#

you don't

#

you only apply classes

trail oasis
#

but i cant see it in the ui builder

gusty estuary
#

actually you can

trail oasis
#

without writing code to apply them all so its not easy to swap between classes to try them out

gusty estuary
#

it's just broken

#

kekw

#

you can inspect all classes that exist on element via debugger too

#

but since it's your own

#

you know all classes

#

so just make stylesheets

#

using them

gusty estuary
trail oasis
#

well how else do you change the width lol

gusty estuary
#

via stylesheet

trail oasis
#

but its related to game code

gusty estuary
#

no

trail oasis
#

player health etc

gusty estuary
#

wat

#

player health is not style

#

it's value

trail oasis
#

if i want to have a blue progress bar i cant simply just change it to blue

#

id have to write it in code

#

thats moronic

gusty estuary
#

uugh

#

that's really much more complex

trail oasis
#

it shouldnt be though

gusty estuary
#

well, it is

trail oasis
#

(╯°□°)╯︵ ┻━┻

gusty estuary
#

I know the trick though

trail oasis
#

this is what i was saying by unity over complicating this

gusty estuary
#

you define 2 visual element

#

0 sized

#

(this can be hardcoded too)

#

apply to them your class names

#

for example

trail oasis
#

why does unity's controls let you do it but our own do not

gusty estuary
#

.color-health-full
and
.color-health-low

#

and then in your progress bar code you read colors of those elements

#

to modify visuals

#

when you change Health property

gusty estuary
#

I am just telling you how to do it properly, so you can easily switch styles via stylesheets

trail oasis
#

why cant they just let us do this

#

then i can change the colour so easily in ui builder

gusty estuary
#

because it's custom control

trail oasis
#

and thats a custom class

#

why cant custom classes go on custom controls

gusty estuary
#

just add .bar-foreground in constructor

#

and override it in your uss

#

that's it

trail oasis
#

it seems to be custom controls are also restricted by style aswell which is utterly stupid

#

its all well and good adding it to constructor but i to test different classes to see how they look

#

so i have to edit the code every time

gusty estuary
#

class is just a tag

#

style is actual data about visuals

trail oasis
#

but you need a class to define unique styles

gusty estuary
#

so define it

trail oasis
#

eg player health, loading progress bar etc

gusty estuary
#

add both your classes in constructor

#

and use stylesheet

#

to apply styles

#

look at Button implementation, sir

trail oasis
#

wheres the source code for button

gusty estuary
#

ctrl + click

trail oasis
#

i meant the c# source code not the uxml stuff

gusty estuary
#

ctrl + click

#

both VS and Rider should do it

trail oasis
#

i think i understand

#

i have to create a matching class in the uss then i can edit it

#

so for unity's built in one i have to create a class with the exact name they have defined

#

or add one that matches one i made in game code

gusty estuary
trail oasis
#

yeh i just dont know why game code can add a class to a custom control but the ui builder will not let us it seems like a pointless restriction no?

gusty estuary
#

and try to find element you want to add custom class to

#

and you won't find it because it's created in runtime, not during uxml authoring stage (what UI builder is)

trail oasis
#

i see

rough scarab
gusty vapor
#

Yes UnityChanThumbsUp
yeah, I rarely did that, I just linked what came out 1st on my search engine UnityChanOops

trail oasis
#

when i google docs it still gives me unity 5 docs some times

#

very annoying then when you click latest version it takes you to main page not the actual page i was on

gusty vapor
#

yeah, that's why I never bothered.. it's been like that for years

small wigeon
#

can I use a PropertyField in a settings panel?

#

It's showing up blank

rough scarab
small wigeon
#

on the root VisualElement?

rough scarab
#

The Bind() extension method sets up an entire hierarchy of visual elements with specified bindingPath properties. You can call the Bind() method on a single element or the parent of the hierarchy that you want to bind. For example, you can call Bind() on the rootVisualElement of an Editor window. This binds all child elements with specified bindingPath properties.

Don’t call Bind() from the Editor.CreateInspectorGUI() or PropertyDrawer.CreatePropertyGUI() override. These overrides are called automatically on the visual elements that these methods return.

small wigeon
#

cheers, that works perfectly

#

Unity packages seem to create settings panels a different way each time

gusty estuary
#

you mean between UITK and uGUI?

small wigeon
#

just between the UITK ones, some load uxml, a variation of different ways added from code

#

the entities package has some serious ui framework too

gusty estuary
#

oooh, you mean specific panel

#

I thought you meant PanelSettings asset

small wigeon
#

ah yeah, that's confusing too 😅

cobalt nimbus
#

How can I query this element? (screen attached)

code below returns null

var spriteField = root.Q<ObjectField>("unity-input-RegisterSpriteData.Sprite");

and when I try to print all root's children names I get only 14 children with names like PropertyField:Sprite (which I believe corresponds to just class field). Why I see different names in debugger and in console?

foreach (var child in root.Children())
  Debug.Log($"{child.name}");

full code

using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

namespace NSprites.Editor
{
    [CustomEditor(typeof(SpriteRendererAuthoring))]
    public class SpriteRendererAuthoringEditor : UnityEditor.Editor
    {
        private const string SpriteFieldName = "unity-input-RegisterSpriteData.Sprite";

        public override VisualElement CreateInspectorGUI()
        {
            var root = new VisualElement();
            InspectorElement.FillDefaultInspector(root, serializedObject, this);

            foreach (var child in root.Children())
                Debug.Log($"{child.name}");

            var spriteField = root.Q<ObjectField>(SpriteFieldName);
            if (spriteField == null)
            {
                Debug.LogException(new NSpritesException($"{nameof(SpriteRendererAuthoringEditor)} can't find field named {SpriteFieldName}, which supposed to be {nameof(Sprite)} field"));
                return root;
            }

            spriteField.RegisterValueChangedCallback((context) => { Debug.Log(context.newValue); });

            return root;
        }
    }
}
gusty estuary
#

why do you need DrawDefaultInspector()?

#

wouldn't imgui conflict with uitk?

gusty vapor
gusty estuary
#

they already fully switched to UITK in 2022?

gusty vapor
cobalt nimbus
gusty vapor
small wigeon
#

the dot in the name seems suspect to me

gusty estuary
#

I'm curious if ObjectField field exists by the time you query

#

you sure there isn't any scheduled behaviour?

gusty vapor
#

I doubt they'd remove it at all

#

tons of projects rely on IMGui still

cobalt nimbus
gusty estuary
#

not both

gusty estuary
#

just gotta figure

cobalt nimbus
#

it should be delayed then

gusty estuary
#

where does it exists (and possibly when?)

#

YOu could use debugger

#

and try to inspect hierarchy

cobalt nimbus
#

ugh I hate how things designed

gusty estuary
#

allthough it's painful

#

VisualElement has like 200 properties

cobalt nimbus
#

debugger says that I do all right 🙂

gusty estuary
#

I mean

#

code debugger

#

via breakpoint

gusty vapor
#

or do it the dumb way, tuck in dummy data to userData

gusty estuary
#

hold up

#

you fill default

#

using this editor

#

isn't this recursive?

cobalt nimbus
gusty vapor
#

what default?

gusty estuary
#

InspectorElement.FillDefaultInspector(root, serializedObject, this);

cobalt nimbus
gusty estuary
#

but by the end of this method your call should finish

gusty vapor
#

it may be contained in uitk host via IMGuiContainer which is fine..

gusty estuary
#

and yet it's not even created yet

gusty vapor
#

OnInspectorGui is special method

gusty estuary
#

public override VisualElement CreateInspectorGUI() I am talking about this

gusty vapor
#

that's correct

cobalt nimbus
gusty estuary
#

you specify Editor this

cobalt nimbus
rough scarab
#

It's not recursive.

gusty estuary
#

🤔

cobalt nimbus
#

just another great experience with unity's great package

cobalt nimbus
#

It seems I can access serialized property by querying PropertyField:FieldName but field I want access is inside a serialized subclass and when I try to access children unity says that child count is 0. Fantastic!
InspectorElement.FillDefaultInspector(root, serializedObject, this); let me do complex things for u little programmer, but oops, names are not the same at init time then in runtime... and also there is no hierarchy... so pls do dirty tricks and wait for next frame in Editor

gusty estuary
#

not really dirty

cobalt nimbus
gusty estuary
#

quite literally either use schedule of ve

#

or register panel event callback

#

which you unregister during callback

#

Schedule allows for specific time frame awaits

#

and callback is... callback 😅

cobalt nimbus
#

yeah, but what is Schedule in UITK and what is AttachToPanelEvent?

gusty estuary
#

schedule is property with scheduler

#

and events are registered via RegisterCallback

cobalt nimbus
#

@gusty estuary I already make root.RegisterCallBack<GeometryCgangeEvent>() to react to "all is ready". Is it what you mean?

wanton solar
#

Hi guys, sorry to interrupt but i'm kinda new. If a have a specific graph view question can i ask for it in this channel? should i do something or can i just drop the question here? thanks for the help and sorry again 🙏

vast maple
#

Hi, I have a problem with layering. I have a row of bookmarks, which need to be hidden by a book layer. The problem with this approach is that they aren't clickable as the book's background covers the entirety of the document. Is there a way to get around this?

trail oasis
#

for custom elements should i put public methods that provide animation or should i do animations in game code on the visual element what would you typically choose in terms of clean design ?

#

i can either do ele.schedule or ele.Animate() which is my own function

#

not sure what would be a smarter design

trail oasis
rough scarab
trail oasis
#

for a progress bar with text how can i have the text overlay the inner progress bar

#

my current solution is to use absolute position for text so its on top of the progress bar

#

but not sure if thats a good solution even though it currently works

#

seems to work even though the docs says not to use absolute position where ever possible but i cant see a better way

rough scarab
trail oasis
#

it doesnt say not to use it just not to use it where ever possible

#

but i dont see any other way to layer the text on top

rough scarab
#

I think that's a pretty silly recommendation, definitely not one to take whole heartedly as advice to not use it where possible.

#

That page is not present in the new documentation, so I've no idea if they removed the advice

trail oasis
#

ah so i see

#

2023.2 has Absolute-position elements appear on top of any siblings that are Relative-position. so i guess i am doing it correctly

rough scarab
#

Ah, the page still exists under a different name and they have removed the nonsense advice

trail oasis
#

nah they just moved the nonsense under a new heading lol

rough scarab
#

Yeah... mmrrrr

trail oasis
#

ill stick with absolute for now until a problem arises

#

i think their own progress bar used absolute for text label too

rough scarab
#

I submitted some feedback on the page in the hope that they'll clarify the advice some more. I believe they're practically just not advising it for typical layout, similar to how it's silly to try to do everything via absolute positions in UGUI

#

To me, it's a tool like any other. You bring out the tool where it makes sense, it's not discouraged to use the tool under those scenarios, in fact it'd be silly not to.

gusty estuary
#

So that for game logic nothing regarding ui framework is not exposed

copper solar
#

Could anyone help. Because my game have guest and logged in user, I create button events on enable. and then once more when user logins, as behavior changes of some buttons. But as it has already registered call back, it registers it again and I get double call of the button. what is best practice to remove visual elements click callbacks?

 visualElement.RegisterCallback<ClickEvent>(ev => ToggleButton(buttonAction));
#

visualElement.UnregisterCallback<ClickEvent>(ev => ToggleButton(buttonAction)); does not work, as it does not have correct reference and maybe because I pass parameter. not sure tbh

gusty estuary
#

lamda cannot be unregistered unless yoy store it by value

copper solar
#

so if I would write this way I could remove the call back? or how should I write it?

 visualElement.RegisterCallback<ClickEvent>(ToggleButton(buttonAction));
 private EventCallback<ClickEvent> ToggleButton(Action buttonAction) {
        throw new NotImplementedException();
    }
rough scarab
#
private EventCallback<ClickEvent> _example;
...
_example = ev => ToggleButton(buttonAction);
visualElement.RegisterCallback(_example);
...
visualElement.UnregisterCallback(_example);
gusty vapor
#

or proly self unregistering via detachpanel + local function

        public static T OnPointerOut<T>(this T visualElement, EventCallback<PointerOutEvent> callback, TrickleDown trickleDown = TrickleDown.NoTrickleDown) where T : VisualElement
        {
            void Unreg(DetachFromPanelEvent x)
            {
                visualElement.UnregisterCallback<PointerOutEvent>(callback, trickleDown);
                visualElement.UnregisterCallback<DetachFromPanelEvent>(Unreg, trickleDown);
            }

            visualElement.RegisterCallback<DetachFromPanelEvent>(Unreg, trickleDown);
            visualElement.RegisterCallback<PointerOutEvent>(callback, trickleDown);
            return visualElement;
        }
#

untested, but the local function should capture it properly

Also may not be suitable for the dude, just an idea I've for a while due to how my uitk projects always bloated with registering/unregistering callbacks

#

another neat usage of local function, love it

small wigeon
#

what's the difference between Button.clicked += func and visualElement.RegisterCallback<ClickEvent>(func); ?

gusty vapor
#

button.clicked uses pooled event (if any) and automatically stopping the propagation
The latter doesn't, you'd need to handle those manually (if you prefer to do so)

#

no reason not to use button.clicked, if it's already a Button

copper solar
copper solar
gusty estuary
trail oasis
#

how do you get the pixel width of a visual element

#

i tried resolved width but it doesn't seem correct

gusty estuary
trail oasis
#

on the context redraw

gusty estuary
#

it's still calculating then

trail oasis
#

i see

#

can attributes be set by the class selectors etc?

#

or can that only be set by binding

gusty estuary
#

no

#

attributes are only via uxml

trail oasis
#

so i have to write the uxml or can it be done in ui builder at all

#

because custom element using painter is kinda weird we can't use themes for it

gusty estuary
#

UI Builder creates inspector for them

#

but you need proper factory

trail oasis
#

ive setup the factory so i can see them in inspector

#

but i wanted to change the colour and line width via the usual style class setup

#

because it uses the painter2d

gusty estuary
#

there are tricks for it

#

the one I mentioned earlier

trail oasis
#

yeh i didnt understand the trick tbh

gusty estuary
#

define custom 0 sized element

#

with specific class

#

and then read it's value

trail oasis
#

@gusty estuaryis there a performance cost if i keep making ui documents of each ui elements and then making a ui document and using lots of ui documents to build the overall result

#

im using ui documents as a sort've prefab idea

#

but i dunno if i am going a bit overboard with it 😄

gusty estuary
#

the bigger your current hierarchy - more it costs to recalculate

#

but if you disable some parts of it via

#

Display style

#

then they are ignored (fully disabled)

#

I personally keep only one UIDocument usually

#

and just add all screens to it

#

fully premade hierarchy on startup

#

and then when I need to navigate between menus I simply switch display style

#

everything via classes btw

trail oasis
#

oh i see

#

so you make a controller which switches what you want to display

#

i was making lots of templates of different elements

#

then creating my overall ui with all the templates essentially

#

so i can copy paste a lot of it if that makes sense

#

but if lots of templates hurts performance i'll avoid it

gusty estuary
#

I almost never use template instances

#

find them rather difficult to work with

trail oasis
#

interesting do you not have similar elements used through out though

gusty estuary
#

I use basic elements mostly

trail oasis
#

i see templates kinda like prefabs in gameobject world

gusty estuary
#

they are

trail oasis
#

i am noticing performance problems thats why i ask

#

my painter2d is a bit laggy when animating the progress bar

#

but that could just be ui toolkit being not fully optimised generally rather than my setup

gusty estuary
#

just profile it

#

no need to guess

wanton solar
#

I'll just try asking for it: i have created a kind of dialogue tool with the experimental graphview, but since that the Node class does not inherits from an object, i can't really implements all of the "undo", "duplicate" or this similar stuff. I don't know if i have to create other classes which inherits from some object one or just give up lol

gusty vapor
#

fun fact: Unity staff seem to despise this api 😄

#

look up for these

                this.deleteSelection += DeleteSelectedVNodes;
                this.serializeGraphElements += VNodeCaches;
                this.unserializeAndPaste += PasteVNodes;
                this.canPasteSerializedData += AllowCopy;
#

Serialization, Undo, Redo, copy, paste all common editor stuffs are handled internally by GraphView class

#

easy mode with this api!

(they are undocumented like most GraphView apis, look at ShaderGraph/VFXgraph source to learn them)

trail oasis
#

had a phantom space in a selector name - took me ages wondering why it wasn't working

unborn bluff
#

Any suggestions on how to change the scroll speed?ScrollView.verticalPageSize doesn't seem to work I am using unity 2021.3.18

gusty vapor
#

add this --unity-metrics-single_line-height: 500px; or whatever pixel value. If it's not working, you add it to your parent stysheet instead.

#

known issue, they fixed the verticalPageSize in later versions

unborn bluff
gusty vapor
#

just do it as told...

gusty estuary
#

should be fixed in 2022 btw

gusty vapor
#

I had to do it too to my current project

gusty vapor
#

the magic of Unity!

gusty estuary
#

2022.2 latest is fixed for sure

#

it was fixed somwhere in 10f+

unborn bluff
#

Still doesn't work even with the suggestions from the post🙁

#

Guess I'll just drop the scrolling and have pages that swap with a button click

#

One of the suggested workarounds works but it scrolls out of bounds and I need to fix that too. Which is an overkill for just a list at this point

wanton solar
gusty vapor
#

just look at ShaderGraph/VFXGraph source code, should be easy to learn all those undocumented apis

#

those two use graphView api

wanton solar
#

ok, many thanks, you literally saved my project

gusty vapor
#

I'm not saving anything just yet 😅, unless you're successfully implementing it to your project 😄

wanton solar
gusty vapor
#

goodluck..

small wigeon
small wigeon
#

cause my ui root has this:

    public void SetUIState(UIState newUiState)
    {
        if (uiState == newUiState)
        {
            return;
        }

        HUD.Root.style.display = DisplayStyle.None;
        MainMenu.Root.style.display = DisplayStyle.None;

        switch (newUiState)
        {
        case UIState.HUD:
            HUD.Root.style.display = DisplayStyle.Flex;
            break;
        case UIState.MainMenu:
            MainMenu.Root.style.display = DisplayStyle.Flex;
            break;
        }

        this.uiState = newUiState;
    }
gusty estuary
#
.mvvmtk-root, .mvvmtk-root-view-embedded {
    flex-grow: 1;
}

.mvvmtk-root-view-base {
    height: 100%;
    width: 100%;
    position: absolute;
}

.mvvmtk-enabled {
    display: flex;
}

.mvvmtk-disabled {
    display: none;
}
#

here's how I do it

#

so I just dynamically add mvvmtk-enabled

#

or disabled

#

and remove accordingly

#

this lets me be able to create styles for both

#

enabled and disabled

small wigeon
#

why do you want styles for both?

small wigeon
#

is there a way to add custom attributes to any element in uxml?

gusty estuary
gusty estuary
#

attributes must be defined in associated factory

#

what I just started to wonder though is whether there's a way to define factories for built in elements

#

🤔

small wigeon
#

there is actually a property bag on visual element, but it's private

gusty estuary
#

is it stored on element?

#

if it is, holy shit

small wigeon
#

private List<KeyValuePair<PropertyName, object>> m_PropertyBag;

gusty estuary
#

holy shit

#

gotta check it

small wigeon
#

my bad, GetProperty/SetProperty are internal, not private

gusty estuary
#

even easier then

#

can't see internal ones

#

where are they?

small wigeon
#

on VisualElement

gusty estuary
#

I know, but I just don't see anything that exposes m_PropertyBag with internal access

small wigeon
#

SetProperty is internal and calls SetPropertyInternal which accesses it

gusty estuary
#

oh

#

ah, I see

#

nah, this is exposing it in not very nice fashion

#

BUT

#

this is what I have been looking for

#

a way to figure whether element is created from UXML

#

created via code will not have one

small wigeon
#

I just want all the unused attributes to get dumped in there

gusty estuary
#

you could check if it does it

small wigeon
#

it does not, there's no way to tell what attributes were used anyway

gusty estuary
#

just foreach list

small wigeon
#

I don't see a way to get a list of possible attributes

gusty vapor
gusty estuary
#

namings are confusing 😅

gusty vapor
#

oh, I thought you mentioned that we can't intantiate an interface ||to answer that, we can with COM hacks)||

gusty estuary
#

oh well

#

now with managed ptr magic

#

with ability to know what elements are created from uxml

#

I can say that collection binding is possible

#

doable

#

and is very efficient

#

aside from that

#

I can also implement binding to fields

#

(without value changed notifications though)

errant harbor
#

Anyone have a simple example of how to actually use these transitions and how they work?

gusty estuary
#

when element changes those values (let's say changes it's classes)

#

they animate according to animation styles

#

so if you define .unity-button:hover selector for style, add animation values to it - when you hover over built in buttons it will animate

#

to clearly see it define that style with some bright red background color

bronze iron
#

I'm rendering a panel to a render texture, but it seems to be one frame behind compared to my camera update. Has anyone experienced this?
It's very easy to notice because my visual elements move based off the main camera's position

trail oasis
#

any one know why this happens: dont know how to fix it

#

it should expand its parent but it doesn't

#

the setup is:

VisualElement¬
Label

#

both have grow 1 and are set to auto for size

#

the text i tested was Test<br>Test<br>Test<br>Test

gusty vapor
#

Labels by default will auto stretch it's own container

#

are you sure you're not using flex-item stretch on your parent?

trail oasis
#

this is my parent settings

#

can you try reproduce with the same setup i typed to see if it happens for you

#

i wonder if its the <br> thats causing a miscalculation ?

gusty vapor
#

man, I despise UIBuilder, it's the clunkiest UIUX I've ever used in my entire life.. I will never use that until they fix it, sorry kekwait

#

I won't open that shitty thing

trail oasis
#

even if you type it out its going to result in the same thing

gusty vapor
#

nope, they're working fine via uss/uxml as long as you're not doing what I said above

trail oasis
#

whether i have stretch on or off its the same for me though

#

can you show me the uxml

#

ill try replicate it

#

to what i have

gusty vapor
#

it's the same default 😄 ...

#

just woke up, not even running unity

trail oasis
#

tbh the uxml is way harder to debug than the builder

#

it seems to be the actual label element thats not expanding

#

not the parent

#

thats all default so that must be a bug

gusty estuary
#

Nah, it's just an overflow

#

Can't remember how to cull it

trail oasis
#

if i turn off overflow it will cut the font out

#

i want it to expand based on the text

gusty estuary
#

Disable grow

#

Also make sure all parents can expand too

trail oasis
#

for the label its already 0

gusty vapor
#

To test it out, create empty parent. don't set the styles (flexes most importantly), then add Label to it

gusty estuary
gusty vapor
#

by default it should expand as you wanted to

gusty estuary
#

Or do you want something else to expand?

trail oasis
#

i want the label and the parent to expand

gusty estuary
#

What

#

How label should expand

trail oasis
#

based on the ever increasing amount of text in the label

gusty estuary
#

It's default

trail oasis
#

huh ?

gusty estuary
trail oasis
#

its dynamic text so i want the label to grow when i add text

gusty vapor
#

one more time.. (they're expanding, by default, it's just you must fulfill certain criterias)

#

aigh, just woke up, making coffee now

trail oasis
#

ive literally changed the grow like you said nothing is fixing it

#

ive tried all combinations

gusty estuary
#

Show uxml

gusty vapor
gusty estuary
#

For whole hierarchy

trail oasis
#

the uxml is kinda massive

gusty vapor
#

the auto expanding/growing is default bahavior in Labels, what makes it not behave as it's intended to, usually flexes

#

on your parent

trail oasis
#

the parent is also default so that should grow aswell no ?

gusty estuary
#

any fixed size disables expansion

#

Because it needs auto

trail oasis
#

it is both auto except with is 100%

gusty estuary
#

inspect every element

#

From bottom to top

#

And find what's limiting

trail oasis
#

it seems removing the parent fixes it

#

no idea why though

#

the parent was the red border but ive just put the red border on the actual label itself instead

gusty vapor
#

bcos what I just said multiple timessssss

#

🥹

trail oasis
#

sure but its still a child of another element

#

just a different one and now it works ¯_(ツ)_/¯

gusty estuary
#

You had grow

trail oasis
#

i turned that off i said this i tried many combinations

gusty estuary
#

That's why you should always paste relevant uxml

trail oasis
#

the uxml is ugly its all inlined

gusty estuary
#

everything else is just guesswork

trail oasis
#

this isnt easier to debug imo lol

gusty estuary
#

It is 100 times better then blind guess

trail oasis
#

i turned grow off

gusty estuary
#

Is that full hierarchy?

#

Kinda doubt that

trail oasis
#

for the error box yeah

gusty estuary
#

Then it's not enough

trail oasis
#

i saved it as a template

#

i can add the parent panel aswell if you want

#

for the main menu

gusty estuary
#

I need full one to see where you added grow or height 😅

trail oasis
#

grow is on the panel element

#

i think

#

oh no its off even on that too

#

the first element Screen has grow = 1

#

i use that so i can center the menu

#

setting screen grow = 0 does nothing however

gusty estuary
#

Or height...

#

Sir

#

Element can only expand to it's parent size

#

So figure it out on your own

#

Yoy have debugger

#

Highlights

trail oasis
#

wdym

#

the parent box should expand based on the label

gusty estuary
#

jsut hover mouse over hierarchy and fi d bottlenck

trail oasis
#

ive been doing that before i asked for help

gusty estuary
trail oasis
#

but how does it have a max size

#

ive not set a max size for height its auto

#

so should it not keep growing

#

as i add more content

gusty estuary
#

it matter for parent of parent

#

Recursively

trail oasis
#

which element you referring to ?

gusty estuary
#

All of them

trail oasis
#

panel or screen ?

#

none of them have max heights

#

screen has 100% height but im not any where near the bottom of the screen yet

gusty estuary
#

Then go hover mouse over each

#

And find element

#

Which has limited size

#

Topmost element

#

This is likely where problem is

trail oasis
#

well its getting cut off by the bottom of "#panel" but that has an auto height because its suppose to expand based on its children

gusty estuary
#

If it gets cut off at whatever you call panel

#

Then you don't need to look further

#

It's already limited by that point

trail oasis
#

okay so panel is the issue

#

but why doesnt panel expand ? it does when i add other elements but not when i add more text to a label

gusty estuary
#

(don't use panel for names, this is extremely confusing)

trail oasis
#

ok call it main menu then

gusty estuary
trail oasis
#

i did

#

oh shit i never updated it

#

i thought i posted the full uxml 🤦‍♂️ my bad

gusty estuary
#

You could paste just that element

gusty vapor
#

simple logic is like this, 600 x 400 pixels parent (this applies to ancestors too), then that 600 x 400 pixel will be your child 100%

gusty estuary
#

Unless padding...

trail oasis
trail oasis
#

other than the very most parent which is 100% to camera

gusty estuary
#

You have grow

gusty vapor
#

have you checked the ancestors too?

gusty estuary
#

Bruh

trail oasis
#

grow on which element ?

gusty estuary
#

Pa el

gusty vapor
#

then that, yeah

trail oasis
#

its 0

#

how do i have grow?

gusty estuary
#

Unset it

trail oasis
#

then its 1 again

gusty estuary
#

What

trail oasis
#

if i unset grow it will be 1 again

#

which means it is on

#

0 = no grow

gusty estuary
#

Why is it 1 by default lol

trail oasis
#

ask unity

gusty estuary
#

No

#

That's on you

#

Default is 0

trail oasis
#

VEs default is on 1 when you import it to ui builder

gusty estuary
#

just unset it

#

Bruh

trail oasis
#

ok now its set to 1

gusty estuary
#

It imports inlined

trail oasis
#

now its grown my menu to the full height of my camera

#

which i dont want

gusty estuary
#

If it defaults unset to 1

#

Then you have some style

#

That does it

trail oasis
#

yes the default by unity is 1

gusty estuary
#

It's not -_-

trail oasis
#

do you want me to record a gif?

gusty estuary
#

No

trail oasis
#

im using inlines as you can see from the uxml

#

not styles

gusty estuary
#

unity default is 0 🤷‍♂️

#

Open empty project and see for yourself

trail oasis
#

its always 1

gusty estuary
#

You didn't unset it

trail oasis
#

why would be setting it theres no class assigned to it

gusty estuary
#

It's ui builder thing

#

It just adds a buch of inlined

trail oasis
#

and unsetting it sets it to 0 which brings me back to this image:
its already unset in my uxml

#

when you said i had grow on which i dont

gusty estuary
#

Dude

#

Remove it completely

#

It must not be highlighted

trail oasis
#

ok done

#

no change

#

because its still 0

gusty estuary
#

But that's a start

trail oasis
#

no its not

#

it was set to 0 unsetting it kept it at 0

#

that wasnt the issue

gusty estuary
#

now you also have a bunch of aling styles

#

That affect children sizing

trail oasis
#

which element do you refer to

gusty estuary
#

Same

#

Panel

#

Remove them all

#

To see if it does anything to size

trail oasis
#

if i remove all then it will break the panel size

rough scarab
#

I really feel like you'd be having a much nicer time with UIToolkit if you weren't inlining so many styles, you should aim to only inline things in rare cases

trail oasis
#

well i inline then export to class using the button once im happy with the layout

#

its what unity's pdf said to do lol

rough scarab
#

Yeah, that's fine, I would just unset things before starting work unless you want them

trail oasis
#

half of it doesn't really make a lot of sense to me

gusty estuary
#

Then unset it

trail oasis
#

if i add an element the panel expands but if i add text it doesn't

gusty estuary
#

If it didn't what you want

trail oasis
#

unset what specifically ive got a lot of things set

gusty estuary
#

you keep them and then it adds up

rough scarab
#

is the element set to grow?

gusty estuary
#

Messing your final layout

trail oasis
#

im not unsetting width here

#

i need the width to be that width

trail oasis
#

grow is 0 on all atm

#

the issue the panel needs to expand down when i add text but it refuses

#

adding a different element it will happily expand down

#

but not for text

#

unless unity doesn't recalculate label correctly when text is added i dunno

gusty estuary
#

Wait

#

Did label expand?

trail oasis
#

no

gusty estuary
#

bruh, I didn't realize you wert adding new line text

trail oasis
#

its a fixed size

gusty estuary
#

I mean errors

gusty estuary
#

Label

trail oasis
gusty estuary
#

something to do with label first

#

To make sure it expands properly

#

I think you disabled overflow expansion

trail oasis
#

ive not touched overflow

#

wouldnt that show in the uxml

gusty estuary
#

Show uxml for label

trail oasis
#

component label?

gusty estuary
#

Just inline here pls

#

the one that does not expand

trail oasis
#
            <ui:Label tabindex="-1" text="&lt;u&gt;Component&lt;/u&gt;" display-tooltip-when-elided="true" name="component-label" style="-unity-font-style: bold; font-size: 20px; margin-left: 0; margin-right: 0; margin-top: 10px; margin-bottom: 0; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; width: 50%; -unity-text-align: upper-center;" />
            
gusty estuary
#

What

trail oasis
#

you on about the one with the component label or the error label

gusty estuary
#

I don't get what is your problem now, I thought this convo about error labels

trail oasis
#
                <ui:Label tabindex="-1" text="Label&lt;br&gt;Test&lt;br&gt;Test&lt;br&gt;Test" display-tooltip-when-elided="true" name="error-output" style="color: rgb(149, 41, 41); font-size: 16px; width: 100%; -unity-font-style: bold; -unity-text-align: middle-left; margin-left: 0; margin-right: 0; margin-top: 10px; margin-bottom: 0; padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; flex-grow: 0;" />

#

i thought you meant the component label at the top lol

gusty estuary
#

You don't have proper overflow

#

Set

trail oasis
#

you told me to unset everything

gusty estuary
#

Since you use new line

trail oasis
#

so what should overflow be set to

gusty estuary
#

Check overflow option

trail oasis
#

i tried both options

#

nothing happens

gusty estuary
#

does label expand though?

trail oasis
#

yeh kinda

rough scarab
#

what is all that space above your element coming from

trail oasis
#

those are unrelated elements ive turned off atm

gusty estuary
#

So now it's up to panel and error container

#

Check aling, justify styles

#

They are usually relevant for layout too

trail oasis
#

the container gets cut short by the panel for sure

#

thats where the problem is

rough scarab
trail oasis
#

yeh i removed siblings that are not related to the heirarchy to isolate it

#

can a sibling effect the layout of its siblings? cant image how

gusty estuary
#

It can take over parent

#

Leaving no space for other

trail oasis
#

theres no overlapping thats for sure

gusty estuary
trail oasis
#

i know its related to those 2 but i dont know why

rough scarab
#

You should try to reduce the times you're setting the size and just let the layout handle it

trail oasis
#

other than width im not setting size of height

gusty estuary
#

Just experiment and learn how they affect layout

trail oasis
#

because it needs to auto expand

rough scarab
#

why are you setting things to width 50% or 100%

trail oasis
#

because i was told % is better than pixels

rough scarab
#

when you can just use align-items: stretch; or something else

gusty estuary
#

And you most definetely need to use less useless inlines

trail oasis
#

then nothing was fixing the problem then i get attacked for experimenting with things lol

gusty estuary
#

definetely not for experimenting

trail oasis
gusty estuary
#

Sounds like encouraging for experimenting, no? 😅

#

I doubt there's good enough explanation on all styles

#

So just playing with them is best option to figure them

trail oasis
#

the only fix is setting a height but thats no good because it needs to grow auto as i add text

#

auto should resize based on its children no?

gusty estuary
#

What if you remove all align styles

trail oasis
#

well then i lose the 100% width from stretch

gusty estuary
#

Ang instead make error cont absolute pos, 0 bottom

rough scarab
trail oasis
#

you are missing a container though

#

that goes around label and output

#

oh wait scratch that

#

i meant around the output not the first label

rough scarab
#

What does that container do? Because adding an element there will change nothing

trail oasis
#

so its :

Container¬
Error title - will center this font
Errors - list of errors left aligned

#

container creates the red border

rough scarab
#

Can you copy your whole thing again? I couldn't use the last one because it had invalid characters in it

#

(< instead of &lt;, and I ain't about to go fixing that)

trail oasis
#

yeh i dunno why it has those though

#

or how to remove them

gusty estuary
#

use uxml 😅

trail oasis
#

it was the uxml

#

do you want me to include all the siblings that add the empty space?

gusty estuary
#

But you wrote text via ui builder

trail oasis
#

what ?

#

oh yeh i used the text label attribute

gusty estuary
#

It's best to use both

rough scarab
#

UIBuilder parses things correctly in newer versions than whatever you're using, it has been unreliable in the past

trail oasis
#

im on unity 2022.2.20

#

so i dunno

#

so do you want me to include its sibling elements in the uxml

#

that will make the uxml horrible to read however

rough scarab
#

newest is best (thank god I never have to use the full context menu ever again)

#

I don't care what it looks like, I just want to fix your issue

gusty estuary
#

Whoah

trail oasis
#

ok though it might not compile because of custom controls

#

which you wont have

trail oasis
#

it probably wont compile

#

i stripped it down earlier to the isolated problem

rough scarab
#

It's got to do with one of your elements taking up 35% of the space

#

if you remove that the problem goes away

trail oasis
#

the radial one?

rough scarab
#

item_container

gusty vapor
trail oasis
#

wait why would a sibling be effecting how the error container expands based on its children its kinda weird to me

#

shouldnt it just push everything down equally

#

item container does seem to be the problem i dont fully understand why though

gusty vapor
#

if it's related to aspect ratios, tons

#

you can see how % can f'd up your layout from perfect-square aspect ratio, to wide-square aspect ratio.. just a tiny example

rough scarab
#

I think the way % works is that it will calculate the total height of the parent element excluding the % elements

#

then it will set the height of that element to the % of that height

trail oasis
#

oh so it becomes an infinite loop of resizing

rough scarab
#

No, what you get is: the parent height is set to the height it would be if item_container's height was 0

#

then you get item_container set to 35% of that height

#

and it pushes the label off the bottom because it doesn't fit

trail oasis
#

oh i see

#

ok so probably best never to use % at all then

rough scarab
#

Not as a part of a flex layout

#

unless you know there's already space allocated for it

trail oasis
#

ok i see, thanks for explaining i would've been there all day not thinking the sibling was some how involved

#

the docs emphasised heavily that layouts were depending on parents and children but didnt mention siblings can cause issues too

gusty estuary
#

padding/margin seem to be using whole screen size

#

when set to %

trail oasis
#

why would it do that

gusty vapor
#

padding/margin uses their own space yeah

trail oasis
#

ill just use pixels and make settings use same pixel size i guess

#

scaling makes everything too small in editor

gusty estuary
gusty estuary
trail oasis
#

well i cant use % so what else can i use lol

gusty vapor
#

I'm not using % in most of my projects, I've my own aspectratio helper..

#

pixels all the way!

gusty estuary
#

wdym you can't use %

trail oasis
#

% was literally the cause of current problem

#

as vertx highlighted

gusty estuary
#

what did you use it for?

trail oasis
#

to set a height of an element

#

in the panel