/* * Copyright 2022 Peter Han * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; using UnityEngine; namespace PeterHan.PLib.UI { /// /// A class representing the size sets of a particular component. /// internal struct LayoutSizes { /// /// The flexible dimension value. /// public float flexible; /// /// If true, this component should be ignored completely. /// public bool ignore; /// /// The minimum dimension value. /// public float min; /// /// The preferred dimension value. /// public float preferred; /// /// The source of these values. /// public readonly GameObject source; internal LayoutSizes(GameObject source) : this(source, 0.0f, 0.0f, 0.0f) { } internal LayoutSizes(GameObject source, float min, float preferred, float flexible) { ignore = false; this.source = source; this.flexible = flexible; this.min = min; this.preferred = preferred; } /// /// Adds another set of layout sizes to this one. /// /// The size values to add. public void Add(LayoutSizes other) { flexible += other.flexible; min += other.min; preferred += other.preferred; } /// /// Enlarges this layout size, if necessary, using the values from another. /// /// The minimum size values to enforce. public void Max(LayoutSizes other) { flexible = Math.Max(flexible, other.flexible); min = Math.Max(min, other.min); preferred = Math.Max(preferred, other.preferred); } public override string ToString() { return string.Format("LayoutSizes[min={0:F2},preferred={1:F2},flexible={2:F2}]", min, preferred, flexible); } } }