protected void TestAcceptanceFor(IRenderer renderer, IGuiElement guiElement) { var hardware = new NullHardware(1024, 768); var stage = new GuiStage(); stage.AddChild(guiElement); // Layout and Render stage.CalculateLayout(hardware); stage.ProcessInteraction(hardware); stage.Render(renderer); var processingData = guiElement.GetLayoutProcessingData(); // drawing geometry Assert.AreEqual(processingData.DrawingGeometry.X, 50); Assert.AreEqual(processingData.DrawingGeometry.Y, 75); Assert.AreEqual(processingData.DrawingGeometry.Width, 100); Assert.AreEqual(processingData.DrawingGeometry.Height, 200); // absolute geometry Assert.AreEqual(processingData.AbsoluteGeometry.X, 50); Assert.AreEqual(processingData.AbsoluteGeometry.Y, 75); Assert.AreEqual(processingData.AbsoluteGeometry.Width, 100); Assert.AreEqual(processingData.AbsoluteGeometry.Height, 200); // clip rect Assert.AreEqual(processingData.ClipRect.X, 50); Assert.AreEqual(processingData.ClipRect.Y, 75); Assert.AreEqual(processingData.ClipRect.Width, 100); Assert.AreEqual(processingData.AbsoluteGeometry.Height, 200); }
/// <summary> /// Set the stage on the container and all its children. /// </summary> /// <param name="stage"></param> public override void SetStage(GuiStage stage) { base.SetStage(stage); foreach (var child in GetChildren()) { child.SetStage(stage); } }
public static T FindDescendantByProperty <T>(this GuiStage Stage, Func <T, bool> Property = null) where T : class { if (Property == null) { Property = new Func <T, bool>(t => true); } return(findDescendantByPropertyTemplate <T>(Stage.Children, Property)); }
public override void UpdateGui() { if (Event.current.type == EventType.Layout) { GuiStage.CalculateLayout(Hardware); GuiStage.ProcessInteraction(Hardware); } else { GuiStage.Render(Renderer); } }
// Use this for initialization void Start() { TweenSharkUnity3D.Initialize(this); // make sure that this object always stay in the scene DontDestroyOnLoad(this); _renderer = new UnityGuiRenderer(GuiSkin.ToSkin()); _hardware = new UnityHardware(); _stage = new GuiStage(); _stage.AddChild(new GuiMain()); _stage.SetDebugMode(true); }
public void HorizontalAlignTest() { var renderer = Substitute.For <NullRenderer>(); // mock the renderer var hardware = new NullHardware(1024, 768); var stage = new GuiStage(); var box = new VBox(); stage.AddChild(box); // makes a size of 60x40 just through padding var spacerNone = new Spacer(100, 100).SetHAlign(HorizontalAlign.None); box.AddChild(spacerNone); var spacerLeft = new Spacer(100, 100).SetHAlign(HorizontalAlign.Left); box.AddChild(spacerLeft); var spacerCenter = new Spacer(100, 100).SetHAlign(HorizontalAlign.Center); box.AddChild(spacerCenter); var spacerRight = new Spacer(100, 100).SetHAlign(HorizontalAlign.Right); box.AddChild(spacerRight); // we add one child that will free up some width box.AddChild(new Spacer(400, 100)); stage.CalculateLayout(hardware); // layout // since we have not set a height on the hBox yet we expect all children to be not vertically aligned Assert.That(box.GetLayout().GetCalculatedWidth(), Is.EqualTo(400)); Assert.That(box.GetLayout().GetCalculatedContentWidth(), Is.EqualTo(400)); Assert.That(spacerNone.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(0)); // NONE stays on top Assert.That(spacerLeft.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(0)); // TOP stays on top Assert.That(spacerCenter.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(150)); // MIDDLE 400 / 2 - 100 / 2 Assert.That(spacerRight.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(300)); // BOTTOM 400 - 100 // new we set a height and then we expect the children to be aligned box.SetWidth(800); stage.CalculateLayout(hardware); // layout Assert.That(box.GetLayout().GetCalculatedWidth(), Is.EqualTo(800)); Assert.That(box.GetLayout().GetCalculatedContentWidth(), Is.EqualTo(400)); Assert.That(spacerNone.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(0)); // NONE stays on top Assert.That(spacerLeft.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(0)); // TOP stays on top Assert.That(spacerCenter.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(350)); // MIDDLE 800 / 2 - 100 / 2 Assert.That(spacerRight.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(700)); // BOTTOM (800 - 100) }
public void VerticalAlignTest() { var renderer = Substitute.For <NullRenderer>(); // mock the renderer var hardware = new NullHardware(1024, 768); var stage = new GuiStage(); var box = new HBox(); stage.AddChild(box); // makes a size of 60x40 just through padding var spacerNone = new Spacer(100, 100).SetVAlign(VerticalAlign.None); box.AddChild(spacerNone); var spacerTop = new Spacer(100, 100).SetVAlign(VerticalAlign.Top); box.AddChild(spacerTop); var spacerMiddle = new Spacer(100, 100).SetVAlign(VerticalAlign.Middle); box.AddChild(spacerMiddle); var spacerBottom = new Spacer(100, 100).SetVAlign(VerticalAlign.Bottom); box.AddChild(spacerBottom); // we add one child that will free up some height box.AddChild(new Spacer(100, 400)); stage.CalculateLayout(hardware); // since we have not set a height on the hBox yet we expect all children to be not vertically aligned Assert.That(box.GetLayout().GetCalculatedHeight(), Is.EqualTo(400)); Assert.That(box.GetLayout().GetCalculatedContentHeight(), Is.EqualTo(400)); Assert.That(spacerNone.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(0)); // NONE stays on top Assert.That(spacerTop.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(0)); // TOP stays on top Assert.That(spacerMiddle.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(150)); // MIDDLE 400 / 2 - 100 / 2 Assert.That(spacerBottom.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(300)); // BOTTOM 400 - 100 // new we set a height and then we expect the children to be aligned box.SetHeight(800); stage.CalculateLayout(hardware); Assert.That(box.GetLayout().GetCalculatedHeight(), Is.EqualTo(800)); Assert.That(box.GetLayout().GetCalculatedContentHeight(), Is.EqualTo(400)); Assert.That(spacerNone.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(0)); // NONE stays on top Assert.That(spacerTop.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(0)); // TOP stays on top Assert.That(spacerMiddle.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(350)); // MIDDLE 800 / 2 - 100 / 2 Assert.That(spacerBottom.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(700)); // BOTTOM (800 - 100) }
/// <summary> /// Set the elements stage /// </summary> /// <param name="stage"></param> public virtual void SetStage(GuiStage stage) { var previousStage = _stage; if (stage != previousStage) { _stage = stage; if (stage != null) { DispatchAddedToStage(); } else { DispatchRemovedFromStage(); } } }
public void VerticalLayoutTest() { var renderer = Substitute.For <NullRenderer>(); // mock the renderer var hardware = new NullHardware(1024, 768); var stage = new GuiStage(); var hBox = new VBox().SetX(10).SetY(20).SetPadding(10, 20, 30, 40); // makes a size of 60x40 just through padding stage.AddChild(hBox); stage.CalculateLayout(hardware); // layout Assert.That(hBox.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(10, 20, 60, 40))); // add a child var spacer1 = new Spacer(200, 100); hBox.AddChild(spacer1); // should increase the size by 200x100 stage.CalculateLayout(hardware); // layout Assert.That(hBox.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(10, 20, 260, 140))); // check the absolute position of spacer1 Assert.That(spacer1.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 30, 200, 100))); // add another child var spacer2 = new Spacer(300, 200); hBox.AddChild(spacer2); // should increase the size by 200x100 stage.CalculateLayout(hardware); // layout Assert.That(hBox.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(10, 20, 360, 340))); // check the absolute position of spacer1 Assert.That(spacer1.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 30, 200, 100))); // check the absolute position of spacer1 Assert.That(spacer2.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 130, 300, 200))); // check setting the spacing hBox.SetSpacing(100); stage.CalculateLayout(hardware); // layout Assert.That(hBox.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(10, 20, 360, 440))); // check the absolute position of spacer1 Assert.That(spacer1.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 30, 200, 100))); // check the absolute position of spacer1 Assert.That(spacer2.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 230, 300, 200))); }
public override void Initialize() { if (!(GuiElement is IDraggable)) { // throw new ArgumentException("The GuiElement has to implement IDraggable!"); } GuiStage = GuiElement.GetStage(); DragAndDropStrategy.Initialize(GuiElement); PossibleDropTargets = DragAndDropStrategy.FindPossibleDropTargets(GuiElement.GetStage()); HighlightingStrategy.Highlight(PossibleDropTargets); DragAndDropStrategy.Grab(); // UnityEngine.Debug.Log("start drag and drop - targets: " + PossibleDropTargets.Count); }
public static T FindById <T>(this GuiStage Stage, string Id) where T : class { return(findByIdTemplate <T>(Id, Stage.FindById)); }
public void SetRemoteStage(GuiStage stage) { _remoteStage = stage; }
public static T FindByName <T>(this GuiStage Stage, string Name) where T : class { return(findByNameTemplate <T>(Name, Stage.FindByName)); }
public static T FindChildByProperty <T>(this GuiStage Stage, Func <T, bool> Property = null) where T : class { return(findChildByPropertyTemplate <T>(Stage.Children, Property)); }
public static IEnumerable <T> FindDescendantsByProperty <T>(this GuiStage Stage, Func <T, bool> Property = null) where T : class { return(findDescendantsByPropertyTemplate <T>(Stage.Children, Property)); }
public void RPC_setGUIStage(int stage) { this.guiStage = (GuiStage) stage; }
public static IEnumerable <T> FindAllByName <T>(this GuiStage Stage, string Name) where T : class { return(findAllByNameTemplate <T>(Name, Stage.FindAllByName)); }
public static T FindByNameEx <T>(this GuiStage Stage, string Name, int TypeId) where T : class { return(findByNameExTemplate <T>(Name, TypeId, Stage.FindByNameEx)); }