// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System.ComponentModel; namespace FlaxEngine.GUI { /// /// Helper control class for other panels. /// /// public abstract class PanelWithMargins : ContainerControl { /// /// The panel area margins. /// protected Margin _margin = new Margin(2.0f); /// /// The space between the items. /// protected float _spacing = 2; /// /// The auto size flag. /// protected bool _autoSize = true; /// /// The control offset. /// protected Float2 _offset; /// /// The child controls alignment within layout area. /// protected TextAlignment _alignment = TextAlignment.Near; /// /// Gets or sets the left margin. /// [HideInEditor, NoSerialize] public float LeftMargin { get => _margin.Left; set { if (!Mathf.NearEqual(_margin.Left, value)) { _margin.Left = value; PerformLayout(); } } } /// /// Gets or sets the right margin. /// [HideInEditor, NoSerialize] public float RightMargin { get => _margin.Right; set { if (!Mathf.NearEqual(_margin.Right, value)) { _margin.Right = value; PerformLayout(); } } } /// /// Gets or sets the top margin. /// [HideInEditor, NoSerialize] public float TopMargin { get => _margin.Top; set { if (!Mathf.NearEqual(_margin.Top, value)) { _margin.Top = value; PerformLayout(); } } } /// /// Gets or sets the bottom margin. /// [HideInEditor, NoSerialize] public float BottomMargin { get => _margin.Bottom; set { if (!Mathf.NearEqual(_margin.Bottom, value)) { _margin.Bottom = value; PerformLayout(); } } } /// /// Gets or sets the child controls spacing. /// [EditorOrder(10), Tooltip("The child controls spacing (the space between controls).")] public float Spacing { get => _spacing; set { if (!Mathf.NearEqual(_spacing, value)) { _spacing = value; PerformLayout(); } } } /// /// Gets or sets the child controls offset (additive). /// [EditorOrder(20), Tooltip("The child controls offset (additive).")] public Float2 Offset { get => _offset; set { if (!Float2.NearEqual(ref _offset, ref value)) { _offset = value; PerformLayout(); } } } /// /// Gets or sets the value indicating whenever the panel size will be based on a children dimensions. /// [EditorOrder(30), DefaultValue(true), Tooltip("If checked, the panel size will be based on a children dimensions.")] public bool AutoSize { get => _autoSize; set { if (_autoSize != value) { _autoSize = value; PerformLayout(); } } } /// /// Gets or sets the value indicating whenever the panel can resize children controls (eg. auto-fit width/height). /// [EditorOrder(35), DefaultValue(true), Tooltip("If checked, the panel can resize children controls (eg. auto-fit width/height).")] public bool ControlChildSize { get; set; } = true; /// /// Gets or sets the panel area margin. /// [EditorOrder(40), Tooltip("The panel area margin.")] public Margin Margin { get => _margin; set { if (_margin != value) { _margin = value; PerformLayout(); } } } /// /// Gets or sets the child controls alignment within layout area. /// [EditorOrder(50), VisibleIf(nameof(AutoSize), true)] public TextAlignment Alignment { get => _alignment; set { if (_alignment != value) { _alignment = value; PerformLayout(); } } } /// /// Initializes a new instance of the class. /// protected PanelWithMargins() : base(0, 0, 64, 64) { AutoFocus = false; } /// public override void OnChildResized(Control control) { base.OnChildResized(control); PerformLayout(); } /// public override bool ContainsPoint(ref Float2 location, bool precise = false) { if (precise && BackgroundColor.A <= 0.0f) // Go through transparency return false; return base.ContainsPoint(ref location, precise); } } }