Logo
UI Elements

Distribution Bar

Display relative values as horizontal or vertical bar segments

Overview

Distribution Bar divides a bar into ordered segments based on their share of the total. It supports horizontal and vertical layouts, optional value or percentage text, and smoothed value changes.

Values do not need to add up to 100. For example, values of 30 and 20 produce shares of 60% and 40%.

Preview

Usage

Use the Evo UI Create menu and choose Progress Bar → Distribution (Two Sides) or Distribution (Three Sides).

Edit Segments, assigning a label, value, and separate Fill Rect for each entry. Assign optional Value Text references for numeric labels.

Choose Direction, then configure Text Display, Display Format, and Minimum Text Percentage.

Enable Smoothing and set its duration and curve. Update values through SetValue() or SetValues() at runtime.


Notes

  • All fill rectangles should share the same parent, without a Layout Group controlling them. The bar drives their anchors and offsets. Assign a different fill and text reference to each segment.
  • Set each segment's color on its fill graphic. Label identifies the segment in the Inspector; Value Text displays its number or percentage.
  • Minimum Text Percentage hides text for small shares in both text display modes. Zero-value text is always hidden.
  • Negative and non-finite values are treated as 0. When the total is 0, all fills collapse and value text is hidden.
  • Smoothing uses unscaled time. Changes to or from an empty distribution, or changes to the segment list structure, apply immediately.
  • Call Refresh() after directly editing segments, references, or settings at runtime. It updates immediately by default and does not invoke the value event. Use Refresh(false) to request smoothing when possible.

Public API

Use DistributionBar in the Evo.UI namespace.

Properties

NameTypeDescription
SegmentCountintNumber of entries in the segment list. Read-only.
TotalValuedoubleSum of finite, positive segment values. Read-only.

Fields

NameTypeDescription
segmentsList<DistributionBar.Segment>Ordered segment values and UI references.
directionDistributionBar.DirectionLeftToRight, RightToLeft, BottomToTop, or TopToBottom.
textDisplayDistributionBar.TextDisplayPercentage or Value.
displayFormatNumberDisplayFormatShared number format for value text.
minimumTextPercentagefloatShare threshold for showing text, from 0 to 100.
enableSmoothingboolAnimates value changes when possible.
smoothingDurationfloatAnimation duration in seconds.
smoothingCurveAnimationCurveCurve used for value animation.

Segment Fields

Each DistributionBar.Segment contains:

NameTypeDescription
labelstringSegment name shown in the Inspector.
valuefloatSegment value before normalization.
fillRectRectTransformFill rectangle controlled by the bar.
valueTextGraphicOptional numeric text for the segment, from any text provider.

Methods

NameParametersDescription
GetValue()int indexReturns the nonnegative, finite value, or 0 for an invalid index.
GetNormalizedValue()int indexReturns the segment's share from 0 to 1, or 0 when no share exists.
SetValue()int index, float value, bool sendCallback = true, bool instant = falseUpdates one segment. Invalid indices are ignored.
SetValues()IReadOnlyList<float> values, bool sendCallback = true, bool instant = falseUpdates all values with one refresh and at most one value event. Requires one value per segment.
Refresh()bool instant = trueApplies direct edits without invoking the value event.

SetValues() throws ArgumentNullException for a null list and ArgumentException when the value count does not match SegmentCount. Getters return the stored target values and shares, even while the display is animating.

Events

NameTypeDescription
onValuesChangedUnityEventInvoked when a setter changes values and sendCallback is true. Has no arguments and does not wait for smoothing to finish.

Example

DistributionBarExample.cs
using UnityEngine;
using Evo.UI;

public class DistributionBarExample : MonoBehaviour
{
    [SerializeField] private DistributionBar target;

    private void Start()
    {
        // Use a two-segment bar with its fill references assigned.
        if (target.SegmentCount != 2)
            return;

        target.direction = DistributionBar.Direction.LeftToRight;
        target.textDisplay = DistributionBar.TextDisplay.Percentage;
        target.SetValues(new float[] { 70f, 30f }, instant: true);
    }

    public void UpdateShares(float first, float second)
    {
        if (target.SegmentCount == 2)
            target.SetValues(new float[] { first, second });
    }
}

On this page