Giter Site home page Giter Site logo

rosettaui's Introduction

RosettaUI

Code-based UI library for development menu for Unity

public class ExampleSimple : MonoBehaviour
{
    public string stringValue;
    public float floatValue;
    public int intValue;
    public Color colorValue;

    
    void Start()
    {
        var root = GetComponent<RosettaUIRoot>();
        root.Build(CreateElement());
    }

    Element CreateElement()
    {
        return UI.Window(nameof(ExampleSimple),
            UI.Page(
                UI.Field(() => stringValue),
                UI.Slider(() => floatValue),
                UI.Row(
                    UI.Field(() => intValue),
                    UI.Button("+", () => intValue++),
                    UI.Button("-", () => intValue--)
                ),
                UI.Field(() => colorValue)
            )
        );
    }
}

Installation

This package uses the scoped registry feature to resolve package dependencies.

Edit > ProjectSettings... > Package Manager > Scoped Registries

Enter the following and click the Save button.

"name": "fuqunaga",
"url": "https://registry.npmjs.com",
"scopes": [ "ga.fuquna" ]

Window > Package Manager

Select MyRegistries in Packages:

Select RosettaUI - UI ToolKit and click the Install button

Input System(optional)

RosettaUI recommends using Input System.
See Tips.

Install according to the official documentation.
https://docs.unity3d.com/Packages/[email protected]/manual/Installation.html

How to use

  1. Put Packages/RosettaUI - UIToolkit/RosettaUIRootUIToolkit.prefab in the Hierarchy
  2. Write code to generate Element instance
  3. Call RosettaUIRoot.Build(Element) to generate the actual UI ( Example )

Examples are available in this repository. I recommend downloading and checking it out.

Functions

UI.Field()

UI.Slider()

UI.MinMaxSlider()

UI.List()

Layout elements

And more!

Please check the Examples

Enviroment

Platform Support
Windows
Mac Maybe(not tested)
Linux Maybe(not tested)
IL2CPP Suspended
UI Library Support
UI Toolkit
UGUI Suspended
IMGUI Not planned

Tips

Disable keyboard input when typing in UI

When using InputSystem, set RosettaUIRoot.disableKeyboardInputWhileUITyping=true (default) to disable keyboard input while typing in UI.

// false while typing in UI
if ( Keyboard.current[Key.A].wasPressedThisFrame )
{
    // do something
}

For LegacyInputSystem, refer to RosettaUIRoot.WillUseKeyInputAny().

if ( !RosettaUIRoot.WillUseKeyInputAny() && Input.GetKeyDown(KeyCode.A) )
{
    // do something
}

See also

PrefsGUI - Accessors and GUIs for persistent preference values using a JSON file

rosettaui's People

Contributors

fuqunaga avatar juh9870 avatar kaiware007 avatar semantic-release-bot avatar witalosk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rosettaui's Issues

.NetFramework4.x is not supported

If Api Compatibility Level use .Net Framework 4.x, will not work.

Library\PackageCache\[email protected]\Runtime\Reactive\ReactiveProperty.cs(37,37): error CS1503: Argument 1: cannot convert from 'System.Action' to 'System.IObserver'

Library\PackageCache\[email protected]\Runtime\Reactive\Observable.cs(59,41): error CS1503: Argument 1: cannot convert from 'System.Action' to 'System.IObserver'

Library\PackageCache\[email protected]\Runtime\Elements\ElementGroup\DynamicElement.cs(53,32): error CS1660: Cannot convert lambda expression to type 'IObserver' because it is not a delegate type

Float values limited?

Changing float values ​​seems to be limited to [-0.02f; 0.02f] when changing by holding down the mouse button.
Unity 2021.3.2f1
Rosetta UI 0.0.2 (last version from Package Manager)

P.s. In general, the framework looks very good, thank you very much)

Circular detection fails with arrays

Let's take code from #11 and change Start() function like this:

        private void Start()
        {
            Req.req = new And()
            {
                Operands = new[] { Req }
            };
            _root = GetComponent<RosettaUIRoot>();
            _root.Build(CreateElement());
        }

Running this code causes extreme lag and error spam cuz it tries to create an infinite UI
image

Request: event-based DynamicElement

It would be good to have a dynamic element that isn't updated every tick to check for condition, but rather listen to some event, and only triggers the rebuild function if a new value was emitted by that event. The main use case is to have DynamicElement that is tied to changes in some other field, without wasting resourced updating it every tick. Performance impact is negligible with one, but what about a dozen?

Circular reference detection is too aggressive

I was trying to make a simple boolean nodes calculator, but quickly ran into "Circular reference detected"

Code
    [RequireComponent(typeof(RosettaUIRoot))]
    public class RosettaUIExample : MonoBehaviour
    {
        [Serializable]
        public enum RequirementType
        {
            AlwaysTrue,
            And,
            Or,
            Not,
            Checkbox,
        }

        [Serializable]
        public abstract class Requirement : IElementCreator
        {
            public abstract bool CalculateOutcome();
            public bool Ignored = false;
            public abstract Element CreateElement(LabelElement label);
        }

        [Serializable]
        public class AlwaysTrue : Requirement
        {
            public override bool CalculateOutcome() => true;
            public override Element CreateElement(LabelElement label) => UI.Column();
        }

        [Serializable]
        public class And : Requirement
        {
            public RequirementNode[] Operands = Array.Empty<RequirementNode>();
            public override bool CalculateOutcome() => Operands.All(e => e.req.CalculateOutcome());
            public override Element CreateElement(LabelElement label) => UI.Field(() => Operands);
        }

        [Serializable]
        public class Or : Requirement
        {
            public RequirementNode[] Operands = Array.Empty<RequirementNode>();
            public override bool CalculateOutcome() => Operands.Any(e => e.req.CalculateOutcome());
            public override Element CreateElement(LabelElement label) => UI.Field(() => Operands);
        }

        [Serializable]
        public class Not : Requirement
        {
            public RequirementNode Operand = new RequirementNode();
            public override bool CalculateOutcome() => !Operand.req.CalculateOutcome();
            public override Element CreateElement(LabelElement label) => UI.Field(() => Operand);
        }

        [Serializable]
        public class Checkbox : Requirement
        {
            public bool Active;
            public override bool CalculateOutcome() => Active;
            public override Element CreateElement(LabelElement label) => UI.Field(() => Active);
        }

        public static class RequirementFactory
        {
            public static Requirement Create(RequirementType type)
            {
                return type switch
                {
                    RequirementType.AlwaysTrue => new AlwaysTrue(),
                    RequirementType.And => new And(),
                    RequirementType.Or => new Or(),
                    RequirementType.Not => new Not(),
                    RequirementType.Checkbox => new Checkbox(),
                    _ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
                };
            }
        }

        [Serializable]
        public class RequirementNode : IElementCreator
        {
            private RequirementType _requirementType;

            public RequirementType RequirementType
            {
                get => _requirementType;
                set
                {
                    if (_requirementType == value) return;
                    _requirementType = value;
                    req = RequirementFactory.Create(value);
                }
            }

            public Requirement req = new AlwaysTrue();

            public Element CreateElement(LabelElement label)
            {
                return UI.Column(
                    UI.Field(() => RequirementType),
                    UI.DynamicElementOnStatusChanged(() => RequirementType, _ => req.CreateElement(null))
                );
            }
        }

        public RequirementNode Req = new();
        private RosettaUIRoot _root;

        private void Start()
        {
            _root = GetComponent<RosettaUIRoot>();
            _root.Build(CreateElement());
        }

        private Element CreateElement()
        {
            return UI.Window(
                // ExampleTypes.Select(type => UI.WindowLauncher(type))
                UI.Field(() => Req),
                UI.Field("Outcome", () => Req.req.CalculateOutcome())
            );
        }
    }

This is the result I get in the UI
image
As you can see, all nodes are working normally, except for Not node that throws circular reference, even tho I clearly don't have any in my code.

Also, I have an unrelated question: Is there a better way to make an editor for this kind of data structure? Aka one "holder" that have a type field, and a body field that contains different classes depending on type. My current implementation requires to manually write UI controls for every possibly body class, and I'm concerned about performance implication of dozens of DynamicElements performing checks on type field every tick

Request: LazyFold element

Would be good to have a Fold element that doesn't create its content until it's first opened. Maybe also add an option to destroy content if it's closed. Main use case is to hide expensive to process but not always needed UI behind it

Compilation Error using this package

Library/PackageCache/[email protected]/Runtime/UnityInternalAccess/Custom/ListViewCustom.cs(104,41): error CS0507: 'ListViewCustom.CreateViewController()': cannot change access modifiers when overriding 'protected' inherited member 'ListView.CreateViewController()'

I use C# 9.0, .NET Framework 4.7.1 on macOS Unity 2022.1.9f1c1

Question about updates

Is there an option to make a field only update actual value after I finished typing and press ENTER/focus out of the current window?
Right now it seems like value changed event is emitted every time I type a symbol, which may cause some performance issues if value setter is not cheap.

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Missing package.json file.

A package.json file at the root of your project is required to release on npm.

Please follow the npm guideline to create a valid package.json file.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Extreme lag with array in nested layouts

Array fields cause extreme lag in nested layouts.
Here is an example code to replicate:

        public int[] Req3 = new int[0];
        private Element CreateElement()
        {
            return UI.Window(
                Recursive(UI.Field(() => Req3), 6)
            );
        }

        private Element Recursive(Element child, int count = 1)
        {
            while (count-- > 0)
            {
                child = UI.Fold("Recursion", UI.Box(child)).Open();
            }

            return child;
        }

With recursion count of 5, lag is already noticeable, and if you increase it, lag increases exponentially, up to ~13 seconds of freeze if you hover over "+" button with count of 8.
Other kinds of fields don't seem to have this lag, I can stack regular int field into high recursion counts without performance consequences, up to 26

Dragging windows tank performance

Dragging windows with a lot of fields cause constant layout recalculation (at least this is what I suspect based on profiler), dropping FPS from 300 to 10. I've used example scene windows to test it

Same thing happens when I'm rearranging array items by dragging them, which causes even worse performance drops, down to 5.

Question: faster listview?

Currently, when using lists, the whole list is generated at once, aka all of its elements are added to the tree, which may cause issues if there are a lot of elements, so my question:
Is there a UI element that allows me to create a list that only shows elements that are currently on-screen? Afaik, UI toolkit default ListView already have this functionality, so would it be possible to have a similar feature here? Maybe as a separate component even

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.