// リストのつなぎ換えだけ private void UnlinkChild(DebugUiControl child) { Debug.Assert(child._parent == this, "それは樸の子じゃないよ!"); // 前と後を取得 var next = child._nextBrother; var prev = child._previousBrother; if (next != null) { next._previousBrother = prev; } // nextがないケースではこれが最後。 else { _lastChild = prev; } if (prev != null) { prev._nextBrother = next; } // prevがないケースではこれが最初 else { _firstChild = next; } child._nextBrother = child._previousBrother = null; }
public void Add( DebugUiControl control, float offsetX = 0f, float offsetY = 0) { _root.AddChild(control, offsetX, offsetY); }
public override void AddChild( DebugUiControl child, float offsetX = 0f, float offsetY = 0f) { _contentPanel.AddChild(child, offsetX, offsetY); }
private void DrawDragMark(DebugUiControl dragged) { float s = dragged.dragMarkSize; float x0 = _input.pointerX; float y0 = _input.pointerY; float x1 = x0 - (s * 0.5f); float y1 = y0 - s; float x2 = x0 + (s * 0.5f); float y2 = y0 - s; // 背景 _renderer.color = dragged.dragMarkColor; _renderer.AddTriangle(x0, y0, x1, y1, x2, y2); // 枠 _renderer.color = new Color32(255, 255, 255, 255); _renderer.AddTriangleFrame(x0, y0, x1, y1, x2, y2, s * 0.125f); // テキスト if (dragged.dragMarkLetter != '\0') { _renderer.color = dragged.dragMarkLetterColor; _renderer.AddText( new string(dragged.dragMarkLetter, 1), s * 0.5f, x0 - (s * 0.25f), y1, dragged.dragMarkSize, dragged.dragMarkSize); } }
// offsetはLocalPositionに足されるので注意 public void Add( DebugUiControl child, float offsetX = 0f, float offsetY = 0f, AlignX alignX = AlignX.Left, AlignY alignY = AlignY.Top) { float x = 0f; switch (alignX) { case AlignX.Center: x = (this.width - child.width) * 0.5f; break; case AlignX.Right: x = this.width - child.width; break; } float y = 0f; switch (alignY) { case AlignY.Center: y = (this.height - child.height) * 0.5f; break; case AlignY.Bottom: y = (this.height - child.height); break; } child.SetLocalPosition( child.localLeftX + offsetX + x, child.localTopY + offsetY + y); AddChildAsTail(child); }
public virtual void RemoveChild(DebugUiControl child) { // リストから切断 UnlinkChild(child); // まず内部を破棄 child.Dispose(); child.Destroy(); }
public void AddAuto(DebugUiControl child) { // 一旦無限に広げて配置後、再配置 _contentPanel.SetSize(float.MaxValue, float.MaxValue); _contentPanel.AddAuto(child); _contentPanel.FitSize(); Layout(); }
public void Initialize(DebugPrimitiveRenderer2D renderer) { _renderer = renderer; _root = new DebugUiControl(); _input = new Input(); this.raycastTarget = true; inputEnabled = true; }
public void Add( DebugUiControl control, float offsetX = 0f, float offsetY = 0, DebugUi.AlignX alignX = DebugUi.AlignX.Left, DebugUi.AlignY alignY = DebugUi.AlignY.Top) { _root.Add(control, offsetX, offsetY, alignX, alignY); }
public void Add( DebugUiControl child, float offsetX = 0f, float offsetY = 0f, AlignX alignX = AlignX.Left, AlignY alignY = AlignY.Top) { _contentPanel.Add(child, offsetX, offsetY, alignX, alignY); }
// offsetはLocalPositionに足されるので注意 public virtual void AddChild( DebugUiControl child, float offsetX = 0f, float offsetY = 0f) { child.SetLocalPosition( child.localLeftX + offsetX, child.localTopY + offsetY); LinkChildToTail(child); child._parent = this; }
public void Destroy() { Dispose(); _nextBrother = _previousBrother = null; _enabled = false; // 以下まともな値が取れないようにしてバグを発覚しやすく localLeftX = float.NaN; localTopY = float.NaN; width = float.NaN; height = float.NaN; }
private void Destroy() { RemoveAllChild(); _parent = _nextBrother = _previousBrother = null; _enabled = false; // 以下まともな値が取れないようにしてバグを発覚しやすく localLeftX = float.NaN; localTopY = float.NaN; width = float.NaN; height = float.NaN; }
public void RemoveAllChild() { var child = _firstChild; while (child != null) { var next = child.nextBrother; child.Destroy(); child = next; } _firstChild = _lastChild = null; }
public void InsertAfter(DebugUiControl newNode) { Debug.Assert(newNode._previousBrother == null, "already in tree."); Debug.Assert(newNode._nextBrother == null, "already in tree."); var next = _nextBrother; newNode._previousBrother = this; newNode._nextBrother = next; _nextBrother = newNode; if (next != null) { next._previousBrother = newNode; } }
public void InsertBefore(DebugUiControl newNode) { Debug.Assert(newNode._previousBrother == null, "already in tree."); Debug.Assert(newNode._nextBrother == null, "already in tree."); var prev = _previousBrother; newNode._nextBrother = this; newNode._previousBrother = prev; _previousBrother = newNode; if (prev != null) { prev._nextBrother = newNode; } }
// リストのつなぎ換えだけ public void UnlinkChild(DebugUiControl child) { // 先頭であれば、 if (child == _firstChild) { _firstChild = child.nextBrother; } // 末尾であれば if (child == _lastChild) { _lastChild = child.previousBrother; } child.Unlink(); }
public void Unlink() { var prev = _previousBrother; var next = _nextBrother; _previousBrother = _nextBrother = null; if (prev != null) { prev._nextBrother = next; } if (next != null) { next._previousBrother = prev; } }
// リストのつなぎ換えだけ private void LinkChildToTail(DebugUiControl child) { child._nextBrother = null; // 末尾がnullの場合、先頭もnull。 if (_lastChild == null) { Debug.Assert(_firstChild == null); _firstChild = _lastChild = child; child._previousBrother = null; } // 末尾が非nullの場合、リンクを生成 else { _lastChild._nextBrother = child; child._previousBrother = _lastChild; _lastChild = child; } }
// リストのつなぎ換えだけ public void AddChildAsTail(DebugUiControl child) { Debug.Assert(child.previousBrother == null, "already in tree."); Debug.Assert(child.nextBrother == null, "already in tree."); // 末尾がnullの場合、先頭もnull。 if (_lastChild == null) { Debug.Assert(_firstChild == null); _firstChild = _lastChild = child; } // 末尾が非nullの場合、リンクを生成 else { if (_lastChild == child) // 同じものを二連続足したバグは無限ループして厄介なので検出して殺してやる { throw new System.InvalidOperationException("same object added. it must be BUG."); } _lastChild.InsertAfter(child); _lastChild = child; } Debug.Assert(child.previousBrother != child); Debug.Assert(child.nextBrother != child); }
public void AddChildAuto(DebugUiControl control) { // 今の位置に入れて入るかを判定 float childWidth = control.width; float childHeight = control.height; float childRight = _x + borderWidth + childWidth; float maxRight = width; float maxBottom = height; if (borderEnabled) { maxRight -= borderWidth * 2f; maxBottom -= borderWidth * 2f; } // 右にあふれた。改行する。 if (childRight > maxRight) { BreakLine(); } // 下にあふれる分には使い手の責任とする。 AddChild(control, _x, _y); _x += childWidth + borderWidth; _currentLineHeight = Mathf.Max(_currentLineHeight, childHeight); }
public void ClearLink() { _previousBrother = _nextBrother = null; }
public void Dispose() { _root = null; _input = null; _renderer = null; }
public virtual void AddAuto(DebugUiControl child) { float minX = 0f; float minY = 0f; float maxX = width; float maxY = height; float borderOffset = borderEnabled ? (borderWidth * 2f) : 0f; if (borderEnabled) { minX += borderOffset; minY += borderOffset; maxX -= borderOffset; maxY -= borderOffset; } // 右 float dx = 0f; float dy = 0f; float size = 0f; AlignX alignX = AlignX.Left; AlignY alignY = AlignY.Top; if ((layout == Layout.RightDown) || (layout == Layout.RightUp)) { alignX = AlignX.Left; alignY = (layout == Layout.RightDown) ? AlignY.Top : AlignY.Bottom; float childRight = _x + borderWidth + child.width; if (childRight > maxX) // あふれた。改行する。 { BreakLine(); } dx = child.width + borderWidth; size = child.height; } else if ((layout == Layout.LeftDown) || (layout == Layout.LeftUp)) { alignX = AlignX.Right; alignY = (layout == Layout.LeftDown) ? AlignY.Top : AlignY.Bottom; float childLeft = _x - borderWidth - child.width; if (childLeft < minX) // あふれた。改行する。 { BreakLine(); } dx = -child.width - borderWidth; size = child.height; } else if ((layout == Layout.DownRight) || (layout == Layout.DownLeft)) { alignY = AlignY.Top; alignX = (layout == Layout.DownRight) ? AlignX.Left : AlignX.Right; float childBottom = _y + borderWidth + child.height; if (childBottom > maxY) // あふれた。改行する。 { BreakLine(); } dy = child.height + borderWidth; size = child.width; } else if ((layout == Layout.UpRight) || (layout == Layout.UpLeft)) { alignY = AlignY.Bottom; alignX = (layout == Layout.UpRight) ? AlignX.Left : AlignX.Right; float childTop = _y - borderWidth - child.height; if (childTop < minY) // あふれた。改行する。 { BreakLine(); } dy = -child.height - borderWidth; size = child.width; } Add(child, _x, _y, alignX, alignY); _x += dx; _y += dy; _currentLineSize = Mathf.Max(_currentLineSize, size); }
private void SetAsLastChild(DebugUiControl child) { UnlinkChild(child); LinkChildToTail(child); }
private void SetAsFirstChild(DebugUiControl child) { UnlinkChild(child); LinkChildToHead(child); }
public void Remove(DebugUiControl control) { _root.RemoveChild(control); }
public override void RemoveChild(DebugUiControl child) { _contentPanel.RemoveChild(child); }
public void MoveToTop(DebugUiControl control) { _root.UnlinkChild(control); _root.AddChildAsTail(control); }