Made the pop up TextTab work much better

Made a PopOutManager class to make it easier to create lots of pop outs.
This commit is contained in:
larsbrubaker 2014-12-23 12:41:56 -08:00
parent 057c13d88f
commit f532d8cdf8
4 changed files with 223 additions and 124 deletions

View file

@ -27,33 +27,26 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using MatterHackers.VectorMath;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.Transform;
using MatterHackers.Agg.VertexSource;
using MatterHackers.VectorMath;
using MatterHackers.MatterControl;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.MatterControl;
using System;
using System.IO;
namespace MatterHackers.Agg.UI
{
public class PopOutTextTabWidget : Tab
{
SystemWindow systemWindow = null;
PopOutManager popOutManager;
public PopOutTextTabWidget(TabPage tabPageControledByTab, string internalTabName)
: this(tabPageControledByTab, internalTabName, 12)
public PopOutTextTabWidget(TabPage tabPageControledByTab, string internalTabName, Vector2 minSize)
: this(tabPageControledByTab, internalTabName, minSize, 12)
{
}
public PopOutTextTabWidget(TabPage tabPageControledByTab, string internalTabName, double pointSize)
public PopOutTextTabWidget(TabPage tabPageControledByTab, string internalTabName, Vector2 minSize, double pointSize)
: base(internalTabName, new GuiWidget(), new GuiWidget(), new GuiWidget(), tabPageControledByTab)
{
RGBA_Bytes selectedTextColor = ActiveTheme.Instance.PrimaryTextColor;
@ -67,6 +60,8 @@ namespace MatterHackers.Agg.UI
tabPageControledByTab.TextChanged += new EventHandler(tabPageControledByTab_TextChanged);
SetBoundsToEncloseChildren();
popOutManager = new PopOutManager(TabPageControlledByTab, minSize, tabPageControledByTab.Text, internalTabName);
}
public override void OnMouseDown(MouseEventArgs mouseEvent)
@ -118,7 +113,10 @@ namespace MatterHackers.Agg.UI
}
Button popOut = new Button(0, 0, new ButtonViewStates(new ImageWidget(popOutImage), new ImageWidget(popOutImageClick), new ImageWidget(popOutImageClick), new ImageWidget(popOutImageClick)));
popOut.Click += popOut_Click;
popOut.Click += (sender, e) =>
{
popOutManager.ShowContentInWindow();
};
popOut.Margin = new BorderDouble(3, 0);
popOut.VAnchor = VAnchor.ParentTop;
leftToRight.AddChild(popOut);
@ -127,113 +125,6 @@ namespace MatterHackers.Agg.UI
widgetState.AddChild(leftToRight);
widgetState.SetBoundsToEncloseChildren();
widgetState.BackgroundColor = backgroundColor;
OpenOnFristAppDraw();
}
GuiWidget currentTopParent;
void OpenOnFristAppDraw()
{
currentTopParent = this;
ParentChanged += FindParentSystemWindow;
}
void FindParentSystemWindow(object sender, EventArgs e)
{
if (currentTopParent.Parent != null)
{
currentTopParent.ParentChanged -= FindParentSystemWindow;
while (currentTopParent != null && currentTopParent.Parent != null)
{
currentTopParent = currentTopParent.Parent;
}
SystemWindow topParentSystemWindow = currentTopParent as SystemWindow;
if (topParentSystemWindow != null)
{
topParentSystemWindow.DrawAfter += ShowOnFirstSystemWindowDraw;
}
else // keep tracking
{
currentTopParent.ParentChanged += FindParentSystemWindow;
}
}
}
void ShowOnFirstSystemWindowDraw(GuiWidget drawingWidget, DrawEventArgs e)
{
UiThread.RunOnIdle((state) =>
{
popOut_Click(null, null);
});
currentTopParent.DrawAfter -= ShowOnFirstSystemWindowDraw;
}
public override void OnClosed(EventArgs e)
{
if (systemWindow != null)
{
systemWindow.CloseAndRemoveAllChildren();
systemWindow.Close();
}
base.OnClosed(e);
}
void popOut_Click(object sender, EventArgs e)
{
if (systemWindow == null)
{
systemWindow = new SystemWindow(640, 400);
systemWindow.AlwaysOnTopOfMain = true;
systemWindow.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
systemWindow.Closing += systemWindow_Closing;
if (TabPageControlledByTab.Children.Count == 1)
{
GuiWidget child = TabPageControlledByTab.Children[0];
TabPageControlledByTab.RemoveChild(child);
TabPageControlledByTab.AddChild(CreatTabPageContent());
systemWindow.AddChild(child);
}
systemWindow.ShowAsSystemWindow();
}
else
{
systemWindow.BringToFront();
}
}
GuiWidget CreatTabPageContent()
{
GuiWidget allContent = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
Button bringBackToTabButton = new Button("Bring Back");
bringBackToTabButton.AnchorCenter();
bringBackToTabButton.Click += (sender, e) =>
{
UiThread.RunOnIdle((state) =>
{
GuiWidget systemWindow = this.systemWindow;
systemWindow_Closing(null, null);
systemWindow.Close();
});
};
allContent.AddChild(bringBackToTabButton);
return allContent;
}
void systemWindow_Closing(object sender, WidgetClosingEnventArgs closingEvent)
{
if (systemWindow.Children.Count == 1)
{
GuiWidget child = systemWindow.Children[0];
systemWindow.RemoveChild(child);
TabPageControlledByTab.RemoveAllChildren();
TabPageControlledByTab.AddChild(child);
}
systemWindow = null;
}
}
}