public void Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute() { Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true))); var t = Application.Top; var w = new Window("w") { X = Pos.Left(t) + 2, Y = Pos.At(2) }; var v = new View("v") { X = Pos.Center(), Y = Pos.Percent(10) }; w.Add(v); t.Add(w); t.Ready += () => { v.LayoutStyle = LayoutStyle.Absolute; Assert.Equal(2, v.X = 2); Assert.Equal(2, v.Y = 2); }; Application.Iteration += () => Application.RequestStop(); Application.Run(); Application.Shutdown(); }
public void At_Equal() { var n1 = 0; var n2 = 0; var pos1 = Pos.At(n1); var pos2 = Pos.At(n2); Assert.Equal(pos1, pos2); }
public void At_SetsValue() { var pos = Pos.At(0); Assert.Equal("Pos.Absolute(0)", pos.ToString()); pos = Pos.At(5); Assert.Equal("Pos.Absolute(5)", pos.ToString()); pos = Pos.At(-1); Assert.Equal("Pos.Absolute(-1)", pos.ToString()); }
public Panel(string title) : base(title) { textView = new TextView { X = Pos.At(0), Y = Pos.At(0), Width = Dim.Fill(), Height = Dim.Fill(), ReadOnly = true }; this.Add(textView); }
public void ArrangeSubviews() { Layout.IsInNativeLayout = true; for (var i = 0; i < ElementController.LogicalChildren.Count; i++) { if (!(ElementController.LogicalChildren[i] is VisualElement child)) { continue; } IVisualElementRenderer renderer = Platform.GetRenderer(child); if (renderer == null) { continue; } Rectangle bounds = child.Bounds; View nativeView = renderer.GetNativeElement(); // Set child size var height = Convert.ToInt32(Math.Max(0, bounds.Height / SizeConverter)); if (height <= 0) { height = 1; } nativeView.Height = Dim.Sized(height); var width = Convert.ToInt32(Math.Max(0, bounds.Width / SizeConverter)); if (width <= 0) { width = 1; } nativeView.Width = Dim.Sized(width); // Set child position int x = Convert.ToInt32(bounds.X / SizeConverter); int y = Convert.ToInt32(bounds.Y / SizeConverter); nativeView.X = Pos.At(x); nativeView.Y = Pos.At(y); } Layout.IsInNativeLayout = false; }
void DimPosChanged(View view) { if (view == null) { return; } try { switch (_xRadioGroup.Selected) { case 0: view.X = Pos.Percent(_xVal); break; case 1: view.X = Pos.AnchorEnd(_xVal); break; case 2: view.X = Pos.Center(); break; case 3: view.X = Pos.At(_xVal); break; } switch (_yRadioGroup.Selected) { case 0: view.Y = Pos.Percent(_yVal); break; case 1: view.Y = Pos.AnchorEnd(_yVal); break; case 2: view.Y = Pos.Center(); break; case 3: view.Y = Pos.At(_yVal); break; } switch (_wRadioGroup.Selected) { case 0: view.Width = Dim.Percent(_wVal); break; case 1: view.Width = Dim.Fill(_wVal); break; case 2: view.Width = Dim.Sized(_wVal); break; } switch (_hRadioGroup.Selected) { case 0: view.Height = Dim.Percent(_hVal); break; case 1: view.Height = Dim.Fill(_hVal); break; case 2: view.Height = Dim.Sized(_hVal); break; } } catch (Exception e) { MessageBox.ErrorQuery("Exception", e.Message, "Ok"); } UpdateTitle(view); }
public void New_Initializes() { // Parameterless var r = new View(); Assert.NotNull(r); Assert.Equal(LayoutStyle.Computed, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=0,Height=0})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 0, 0), r.Bounds); Assert.Equal(new Rect(0, 0, 0, 0), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.Equal(Dim.Sized(0), r.Width); Assert.Equal(Dim.Sized(0), r.Height); // FIXED: Pos needs equality implemented Assert.Equal(Pos.At(0), r.X); Assert.Equal(Pos.At(0), r.Y); Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Empty Rect r = new View(Rect.Empty); Assert.NotNull(r); Assert.Equal(LayoutStyle.Absolute, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=0,Height=0})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 0, 0), r.Bounds); Assert.Equal(new Rect(0, 0, 0, 0), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); // All view Dim are initialized now, Assert.NotNull(r.Height); // avoiding Dim errors. Assert.NotNull(r.X); // All view Pos are initialized now, Assert.NotNull(r.Y); // avoiding Pos errors. Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Rect with values r = new View(new Rect(1, 2, 3, 4)); Assert.NotNull(r); Assert.Equal(LayoutStyle.Absolute, r.LayoutStyle); Assert.Equal("View()({X=1,Y=2,Width=3,Height=4})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 3, 4), r.Bounds); Assert.Equal(new Rect(1, 2, 3, 4), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); Assert.NotNull(r.Height); Assert.NotNull(r.X); Assert.NotNull(r.Y); Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Initializes a view with a vertical direction r = new View("Vertical View", TextDirection.TopBottom_LeftRight); Assert.NotNull(r); Assert.Equal(LayoutStyle.Computed, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=1,Height=13})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 1, 13), r.Bounds); Assert.Equal(new Rect(0, 0, 1, 13), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); // All view Dim are initialized now, Assert.NotNull(r.Height); // avoiding Dim errors. Assert.NotNull(r.X); // All view Pos are initialized now, Assert.NotNull(r.Y); // avoiding Pos errors. Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.TopBottom_LeftRight, r.TextDirection); }
public static Button CreateButton(string Content, int X, int Y, Dim W, Dim H, Delegate act) { return(CreateButton(Content, Pos.At(X), Pos.At(Y), W, H, act)); }
public static Label CreateLabel(string Content, int X, int Y) { return(CreateLabel(Content, Pos.At(X), Pos.At(Y))); }
public static Label CreateLabel(string Content, int X, int Y, Dim W, Dim H) { return(CreateLabel(Content, Pos.At(X), Pos.At(Y), W, H)); }