Simplify rules and rename to clarify behavior of SetInterval hook

- Issue MatterHackers/MCCentral#3004
Redundancy seems unnecessary
This commit is contained in:
John Lewin 2018-03-29 17:58:17 -07:00
parent 048caeffab
commit cff26ed09a

View file

@ -44,6 +44,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
base.Visible = false;
double pointSize = 12;
numberDisplay = new TextWidget(defaultSizeString, 0, 0, pointSize, justification: justification)
{
Visible = false,
@ -52,6 +53,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
Text = "0",
};
AddChild(numberDisplay);
numberEdit = new NumberEdit(0, 50, 50, pointSize, pixelWidth: numberDisplay.Width, allowNegatives: true, allowDecimals: true)
{
Visible = false,
@ -79,7 +81,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
VAnchor = VAnchor.Fit;
HAnchor = HAnchor.Fit;
UiThread.SetInterval(CheckControlsVisibility, .1, () => !HasBeenClosed);
UiThread.SetInterval(HideIfApplicable, .1, () => !HasBeenClosed);
}
public Color TextColor { get; set; } = Color.Black;
@ -181,29 +183,21 @@ namespace MatterHackers.MatterControl.CustomWidgets
base.OnMouseDown(mouseEvent);
}
private void CheckControlsVisibility()
private void HideIfApplicable()
{
if (!this.Editing)
if (this.Visible)
{
if (timeSinceMouseUp.IsRunning)
if (!this.Editing
&& timeSinceMouseUp.IsRunning
&& timeSinceMouseUp.ElapsedMilliseconds > SecondsToShowNumberEdit * 1000)
{
if (timeSinceMouseUp.ElapsedMilliseconds > SecondsToShowNumberEdit * 1000)
{
if (this.Editing)
{
}
else if (timeSinceMouseUp.IsRunning)
{
Visible = false;
}
}
Visible = false;
}
else if (this.ForceHide?.Invoke() == true)
{
// Hide if custom ForceHide implementations say to do so
this.Visible = false;
}
}
if (Visible && ForceHide?.Invoke() == true)
{
// If the user is hovering on a different control
Visible = false;
}
}
}