// Start is called before the first frame update void Start() { mesh = GetComponent <MeshFilter>().mesh; if (!mesh) { return; } mesh.MarkDynamic(); Vector3[] vertices = mesh.vertices; uvs = mesh.uv; triangles = mesh.triangles; points = new Point[vertices.Length]; pointsPrevious = new Point[vertices.Length]; forceAccumulator = new Vector3[vertices.Length]; thisFrameForce = new Vector3[vertices.Length]; constraints = new Constraint[vertices.Length * 2]; Bounds bounds = mesh.bounds; Vector3 anchorDistance = (bounds.max - bounds.min) * 0.5f * drift; for (int i = 0; i < vertices.Length; i++) { points[i] = new Point(vertices[i]); pointsPrevious[i] = new Point(vertices[i]); forceAccumulator[i] = new Vector3(); thisFrameForce[i] = new Vector3(); constraints[i * 2] = new BoxConstraint(points[i], bounds); constraints[i * 2 + 1] = new AnchorConstraint(points[i], anchorDistance); } }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var pt = GetOffset(constraint); var shrink = constraint.Shrink(pt.X, pt.Y).Loosen(); var childSize = Child.Draw(new Point(pt.X + offset.X, pt.Y + offset.Y), shrink, context); return(GetUsedSize(constraint, childSize)); }
public Size Measure(BoxConstraint constraint) { var pt = GetOffset(constraint); var shrink = constraint.Shrink(pt.X, pt.Y).Loosen(); var childSize = Child.Measure(shrink); return(GetUsedSize(constraint, childSize)); }
public Size Measure(BoxConstraint constraint) { var lines = TextArray(constraint.GetMaxSize(), WrapContent, true); var max = lines.DefaultIfEmpty(string.Empty).Max(l => l.Length); return(constraint.Tighten(max, lines.Length).GetMinSize()); }
public Size Measure(BoxConstraint constraint) { var x = Padding.Left + Padding.Right; var y = Padding.Top + Padding.Bottom; var shrink = constraint.Shrink(x, y); var childSize = Child.Measure(shrink); return(new Size(childSize.Width + x, childSize.Height + y)); }
public static void Serialize(BoxConstraint instance, global::Improbable.Worker.CInterop.SchemaObject obj) { { global::Improbable.Coordinates.Serialization.Serialize(instance.Center, obj.AddObject(1)); } { global::Improbable.EdgeLength.Serialization.Serialize(instance.EdgeLength, obj.AddObject(2)); } }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { foreach (var child in Children) { child.Draw(offset, constraint, context); } return(constraint.GetMaxSize()); }
public static unsafe void Write(global::Improbable.Worker.Internal.GcHandlePool _pool, BoxConstraint _data, global::Improbable.Worker.Internal.Pbio.Object *_obj) { { global::Improbable.Coordinates_Internal.Write(_pool, _data.center, global::Improbable.Worker.Internal.Pbio.AddObject(_obj, 1)); } { global::Improbable.EdgeLength_Internal.Write(_pool, _data.edgeLength, global::Improbable.Worker.Internal.Pbio.AddObject(_obj, 2)); } }
private Point GetOffset(BoxConstraint constraint) { var c = Child.Measure(constraint.Loosen()); int x = HorizontalAlignment.GetOffset(constraint.MinWidth, c.Width); int y = VerticalAlignment.GetOffset(constraint.MinHeight, c.Height); return(new Point(x, y)); }
public static unsafe void Write(global::Improbable.Worker.Internal.GcHandlePool _pool, BoxConstraint _data, global::Improbable.Worker.CInterop.SchemaObject _obj) { { global::Improbable.Coordinates_Internal.Write(_pool, _data.center, _obj.AddObject(1)); } { global::Improbable.EdgeLength_Internal.Write(_pool, _data.edgeLength, _obj.AddObject(2)); } }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var x = Padding.Left + Padding.Right; var y = Padding.Top + Padding.Bottom; var shrink = constraint.Shrink(x, y); var pt = new Point(offset.X + Padding.Left, offset.Y + Padding.Top); var childSize = Child.Draw(pt, shrink, context); return(new Size(childSize.Width + x, childSize.Height + y)); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var size = constraint .Constrain(Size); var childSize = Child.Draw(offset, size, context); return(constraint .Tighten(childSize) .GetMinSize()); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var layout = GetLayout(constraint); foreach (var item in layout.Elements) { DrawItem(MainAxis, item, offset, context); } return(layout.Size); }
public Size Measure(BoxConstraint constraint) { var size = constraint .Constrain(Size); var childSize = Child.Measure(size); return(constraint .Tighten(childSize) .GetMinSize()); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var pt = Absolute ? Location : new Point(offset.X + Location.X, offset.Y + Location.Y); // TODO what should we do with the constraints?? // the resulting size would be off, too // it might make more to 'remove' it from the layout // at least if it's absolutely positioned return(Child.Draw(offset, constraint, context)); }
public static BoxConstraint Deserialize(global::Improbable.Worker.CInterop.SchemaObject obj) { var instance = new BoxConstraint(); { instance.Center = global::Improbable.Coordinates.Serialization.Deserialize(obj.GetObject(1)); } { instance.EdgeLength = global::Improbable.EdgeLength.Serialization.Deserialize(obj.GetObject(2)); } return(instance); }
public Size Measure(BoxConstraint constraint) { var scroll = GetConstraint(constraint); var min = Child.Measure(scroll); // fits whtaever the child returns into the constraint // so if the child doesn't use the full h/w, neither will this measure // but if it does, it will max at the constraint max. // offset isn't important here since if it's 'used' then this box already fills return(constraint.Tighten(min).GetMinSize()); }
private Size GetUsedSize(BoxConstraint constraint, Size childSize) { // if alignment is 'set' then we use the minimum width or the child width, whichever is greater // (that's what we aligned to) var w = HorizontalAlignment != Alignment.Default ? Math.Max(constraint.MinWidth, childSize.Width) : childSize.Width; var h = VerticalAlignment != Alignment.Default ? Math.Max(constraint.MinHeight, childSize.Height) : childSize.Height; return(constraint.Tighten(w, h).GetMinSize()); }
public Size Measure(BoxConstraint constraint) { if (Border == null) { return(Child.Measure(constraint)); } // measure for the fitted space var shrink = constraint.Shrink(2, 2); var childSize = Child.Measure(shrink); // now add the border back return(new Size(childSize.Width + 2, childSize.Height + 2)); }
private MeasuredLayout GetLayout(BoxConstraint constraint) { var layout = new MeasuredLayout(); layout.Elements = Children.Select(c => new LayoutElement() { Child = (c is FlexibleElement) ? (FlexibleElement)c : new FlexibleElement(c), }).ToList(); MeasureItems(layout.Elements, MainAxis, constraint); LayoutLine(layout, ItemSpacing, MainAxis, constraint); return(layout); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var scroll = GetConstraint(constraint); // measure the child, if the child doesn't fit // then we can apply the offset. // wait.... the offset works... differently... shit we need to pass in a custom 'buffer' // TODO: we should validate the offset makes 'sense' here // ICK //var ctx = new UIContext(context.Console, new ConsoleBuffer(int.MaxValue, int.MaxValue, new Cell())); throw new NotImplementedException(); }
private BoxConstraint GetConstraint(BoxConstraint constraint) { var scroll = constraint; if (HorizontalScroll) { scroll = scroll.Set(Axis.Horizontal, 0, int.MaxValue); } if (VerticalScroll) { scroll = scroll.Set(Axis.Vertical, 0, int.MaxValue); } return(scroll); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { if (Border == null) { return(Child.Draw(offset, constraint, context)); } // measure for the fitted space var shrink = constraint.Shrink(2, 2); var childSize = Child.Draw(new Point(offset.X + 1, offset.Y + 1), shrink, context); var bordered = new Size(childSize.Width + 2, childSize.Height + 2); DrawBorder(new Rectangle(offset, bordered), bordered, context); return(bordered); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var measured = Child.Measure(constraint); var bounds = new Rectangle(offset, measured); if (Style.HasStyles()) { for (var x = 0; x < measured.Width; x++) { for (var y = 0; y < measured.Height; y++) { context.Buffer.Modify(bounds, new Point(x, y), Style.Apply); } } } return(Child.Draw(offset, constraint, context)); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var size = Child.Draw(offset, constraint, context); if (EventHandler != null) { // simply wraps the child bounds in an area event handler context.AddEventHandler(new UIContext.AreaEventHandlerRegistration() { Area = new Rectangle { Location = offset, Size = size, }, Handler = EventHandler, }); } return(size); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var lines = TextArray(constraint.GetMaxSize(), WrapContent, true); var max = lines.DefaultIfEmpty(string.Empty).Max(l => l.Length); var size = constraint.Tighten(max, lines.Length).GetMinSize(); var bounds = new Rectangle(offset, size); for (var y = 0; y < lines.Length; y++) { var l = lines[y]; for (var x = 0; x < l.Length; x++) { context.Buffer.Modify(bounds, new Point(x, y), c => { c.Char = l[x]; return(c); }); } } return(size); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var size = constraint.GetMaxSize(); var bounds = new Rectangle(offset, size); Dictionary <Point, Cell> buffer; if (Cache.Cached.ContainsKey(size)) { buffer = Cache.Cached[size]; } else { buffer = GetCellsFromImage(size, Cache.Image); Cache.Cached.Add(size, buffer); } foreach (var kvp in buffer) { context.Buffer.Modify(bounds, kvp.Key, c => kvp.Value); } return(constraint.GetMaxSize()); }
public Size Measure(BoxConstraint constraint) { return(constraint.Tighten(constraint.MaxWidth, 1).GetMinSize()); }
public Size Draw(Point offset, BoxConstraint constraint, UIContext context) { var w = constraint.IsBoundedWidth ? constraint.MaxWidth : constraint.MinWidth; var size = new Size(w, 1); // TODO yeuks // sanity check if (w < 1) { return(new Size(0, 0)); } if (Input.CursorPosition < Input.StartVisiblePosition) { // cursor is behind start Input.StartVisiblePosition = Input.CursorPosition; } else if (Input.Text.Length + 1 <= w) { // everything fits, just remove 'visible' back to 0 Input.StartVisiblePosition = 0; } else if (Input.CursorPosition - Input.StartVisiblePosition >= w) { // cursor is out of range ahoy! // move start pos to match cursor Input.StartVisiblePosition = Input.CursorPosition - w + 1; } else if (Input.Text.Length - Input.StartVisiblePosition + 1 < w) { // start pos is further right that it needs to be Input.StartVisiblePosition = Input.Text.Length - w + 1; } var bounds = new Rectangle(offset, size); if (Input.IsFocused) { // draw the cursor pos style if it has focus var z = new Point(Input.CursorPosition - Input.StartVisiblePosition, 0); if (CursorStyle != null) { context.Buffer.Modify(bounds, z, CursorStyle.Apply); } else { z.Offset(bounds.X, bounds.Y); context.SetCursor(z, true); } } // cut the text as approp var output = Input.Text.Substring(Input.StartVisiblePosition); var l = w > output.Length ? output.Length : w; for (var x = 0; x < l; x++) { context.Buffer.Modify(bounds, new Point(x, 0), c => { c.Char = output[x]; return(c); }); } return(constraint.Tighten(size).GetMinSize()); }
public Size Measure(BoxConstraint constraint) { return(constraint.GetMaxSize()); }