Merge branch 'honzapatCZ-ui-achorpopup-shiftctrl-modes' into 1.2
This commit is contained in:
@@ -39,6 +39,13 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
|
|
||||||
public bool IsSelected;
|
public bool IsSelected;
|
||||||
|
|
||||||
|
public bool SupportsShiftModulation;
|
||||||
|
|
||||||
|
private void OnPresetsChanged()
|
||||||
|
{
|
||||||
|
TooltipText = CustomEditorsUtil.GetPropertyNameUI(_presets.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
@@ -74,6 +81,15 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
borderColor = BorderColorHighlighted;
|
borderColor = BorderColorHighlighted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input.GetKey(KeyboardKeys.Shift) && SupportsShiftModulation)
|
||||||
|
{
|
||||||
|
backgroundColor = BackgroundColorSelected;
|
||||||
|
}
|
||||||
|
if (Input.GetKey(KeyboardKeys.Control) && SupportsShiftModulation)
|
||||||
|
{
|
||||||
|
borderColor = BackgroundColorSelected;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate fill area
|
// Calculate fill area
|
||||||
float fillSize = rect.Width / 3;
|
float fillSize = rect.Width / 3;
|
||||||
Rectangle fillArea;
|
Rectangle fillArea;
|
||||||
@@ -161,12 +177,17 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
const float DialogWidth = ButtonsSize * 4 + ButtonsMargin * 5 + ButtonsMarginStretch;
|
const float DialogWidth = ButtonsSize * 4 + ButtonsMargin * 5 + ButtonsMarginStretch;
|
||||||
const float DialogHeight = TitleHeight + ButtonsSize * 4 + ButtonsMargin * 5 + ButtonsMarginStretch;
|
const float DialogHeight = TitleHeight + ButtonsSize * 4 + ButtonsMargin * 5 + ButtonsMarginStretch;
|
||||||
|
|
||||||
|
bool SupportsShiftModulation = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="AnchorPresetsEditorPopup"/> class.
|
/// Initializes a new instance of the <see cref="AnchorPresetsEditorPopup"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="presets">The initial value.</param>
|
/// <param name="presets">The initial value.</param>
|
||||||
public AnchorPresetsEditorPopup(AnchorPresets presets)
|
/// <param name="supportsShiftModulation">If the popup should react to shift</param>
|
||||||
|
public AnchorPresetsEditorPopup(AnchorPresets presets, bool supportsShiftModulation)
|
||||||
{
|
{
|
||||||
|
SupportsShiftModulation = supportsShiftModulation;
|
||||||
|
|
||||||
var style = FlaxEngine.GUI.Style.Current;
|
var style = FlaxEngine.GUI.Style.Current;
|
||||||
Tag = presets;
|
Tag = presets;
|
||||||
Size = new Vector2(DialogWidth, DialogHeight);
|
Size = new Vector2(DialogWidth, DialogHeight);
|
||||||
@@ -214,6 +235,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
Parent = this,
|
Parent = this,
|
||||||
Presets = presets,
|
Presets = presets,
|
||||||
IsSelected = presets == (AnchorPresets)Tag,
|
IsSelected = presets == (AnchorPresets)Tag,
|
||||||
|
SupportsShiftModulation = SupportsShiftModulation,
|
||||||
Tag = presets,
|
Tag = presets,
|
||||||
};
|
};
|
||||||
button.ButtonClicked += OnButtonClicked;
|
button.ButtonClicked += OnButtonClicked;
|
||||||
@@ -273,7 +295,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
private void OnButtonClicked()
|
private void OnButtonClicked()
|
||||||
{
|
{
|
||||||
var location = _button.Center + new Vector2(3.0f);
|
var location = _button.Center + new Vector2(3.0f);
|
||||||
var editor = new AnchorPresetsEditorPopup(_button.Presets);
|
var editor = new AnchorPresetsEditorPopup(_button.Presets, true);
|
||||||
editor.VisibleChanged += OnEditorVisibleChanged;
|
editor.VisibleChanged += OnEditorVisibleChanged;
|
||||||
editor.Show(_button.Parent, location);
|
editor.Show(_button.Parent, location);
|
||||||
}
|
}
|
||||||
@@ -284,6 +306,29 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
return;
|
return;
|
||||||
SetValue(control.Tag);
|
SetValue(control.Tag);
|
||||||
}
|
}
|
||||||
|
/// <inheritdoc/>
|
||||||
|
protected override void SynchronizeValue(object value)
|
||||||
|
{
|
||||||
|
// Custom anchors editing for Control to handle bounds preservation via key modifiers
|
||||||
|
if (ParentEditor != null)
|
||||||
|
{
|
||||||
|
var centerToPosition = Input.GetKey(KeyboardKeys.Shift);
|
||||||
|
var setPivot = Input.GetKey(KeyboardKeys.Control);
|
||||||
|
var editedAny = false;
|
||||||
|
foreach (var parentValue in ParentEditor.Values)
|
||||||
|
{
|
||||||
|
if (parentValue is Control parentControl)
|
||||||
|
{
|
||||||
|
parentControl.SetAnchorPreset((AnchorPresets)value, !centerToPosition, setPivot);
|
||||||
|
editedAny = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (editedAny)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.SynchronizeValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Refresh()
|
public override void Refresh()
|
||||||
|
|||||||
@@ -491,7 +491,8 @@ namespace FlaxEngine.GUI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="anchorPreset">The anchor preset to set.</param>
|
/// <param name="anchorPreset">The anchor preset to set.</param>
|
||||||
/// <param name="preserveBounds">True if preserve current control bounds, otherwise will align control position accordingly to the anchor location.</param>
|
/// <param name="preserveBounds">True if preserve current control bounds, otherwise will align control position accordingly to the anchor location.</param>
|
||||||
public void SetAnchorPreset(AnchorPresets anchorPreset, bool preserveBounds)
|
/// <param name="setPivotToo">Whether or not we should set the pivot too, eg left-top 0,0, bottom-right 1,1</param>
|
||||||
|
public void SetAnchorPreset(AnchorPresets anchorPreset, bool preserveBounds, bool setPivotToo = false)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < AnchorPresetsData.Length; i++)
|
for (int i = 0; i < AnchorPresetsData.Length; i++)
|
||||||
{
|
{
|
||||||
@@ -583,6 +584,10 @@ namespace FlaxEngine.GUI
|
|||||||
}
|
}
|
||||||
SetBounds(ref bounds);
|
SetBounds(ref bounds);
|
||||||
}
|
}
|
||||||
|
if (setPivotToo)
|
||||||
|
{
|
||||||
|
Pivot = (anchorMin + anchorMax) / 2;
|
||||||
|
}
|
||||||
_parent?.PerformLayout();
|
_parent?.PerformLayout();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user