Giter VIP home page Giter VIP logo

advanced-layout-element's Introduction

advanced-layout-element

caption

Warning: Documentation is in development.

Overview

The Advanced Layout Element is a simple component that aims to give you more control when setting up a UI layout. The main feature of the component is that it allows you to source a Rect Transfrorm's desired height or width from another component in your scene. While the Advanced Layout Element is usually used in combination with a Layout Group, the Advanced Layout Element can be made to act indepedently of any Layout Group.

Override Types

Since the main feature of this component is to use values from other objects. Here is how the override functions with different types.

  • RectTransform

    • In the case of preffered or minumum properties the value will be retrieved from the transforms height or width respectively
    • In the case of flexible properties, it will retrieve the difference between the override's size and the element's size.
  • Layout Element

    • Components that extends the ILayoutElement interface will use the same interface to retrieve desired values.
  • TextMeshProUGUI

    • The text mesh pro text component extends ILayoutElement interface however the only the prefferred width or height seems to have relevant values
  • Images or other Graphic Components

    • Graphic Components all extend ILayoutElement interface however the only the prefferred width or height seems to have relevant values

Requirements

  • This project was made using 2022.2.8f1 but the Advanced Layout Element should work in older versions. Let me know if you have issues

Installation

Currently you can install this component by copying everything in the following directy directly into your own project.

Assets/Scripts/AdvancedLayoutElement

Since this project is really just one component, I did not make the code into a package. I can make the code into a package upon popular demand.

Known Issues

  • Property values cannot be animated with the Unity Animator, it is recommended that you use a tweening library when animating UI. If there is demand I will consider adding this functionality.

Accordian Menu Example

You can find an Accordian menu example located at: Assets/Scenes/AccordianDemo.Unity

In the Accordian demo each gameobject that utilizes the Advanced Layout Element is marked with a "*" in its name.

Editor Example

caption

Script Example

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AP.UI;

public class SimpleToggle : MonoBehaviour
{
    [SerializeField] bool m_IsEnabled;
    [SerializeField] RectTransform m_ArrowTransform;
    [SerializeField] AdvancedLayoutElement m_AnswerElement;


    //Called by a the OnClick event of a Button component
    public void Toggle()
    {
        m_IsEnabled = !m_IsEnabled;
    }
    

    void Start()
    {
        //Setting up the GUI elements to match the default enabled state.
        m_AnswerElement[LayoutProperty.PreferredHeight].Weight = m_IsEnabled ? 1 : 0;
        var angles = m_ArrowTransform.eulerAngles;
        angles.z = m_IsEnabled ? 0 : 90;
        m_ArrowTransform.eulerAngles = angles;
    }
    
    // Probably wouldn't modulate these values in update in a real app.
    // Would probably use a tweening library
    // but in a demo this is fine
    void Update()
    {
        var heightProp = m_AnswerElement[LayoutProperty.PreferredHeight];
        heightProp.Weight = Mathf.MoveTowards(heightProp.Weight, m_IsEnabled ? 1 : 0, .1f);

        var angles = m_ArrowTransform.eulerAngles;
        angles.z = Mathf.MoveTowardsAngle(angles.z, m_IsEnabled ? 0 : 90, 5f);
        m_ArrowTransform.eulerAngles = angles;
    }
}
Quick Start
Coming Soon

advanced-layout-element's People

Contributors

alexth939 avatar apilola avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

alexth939

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.