AlphaTab.Rendering.Glyphs.AccidentalGroupGlyph.DoLayout C# (CSharp) Method

DoLayout() public method

public DoLayout ( ) : void
return void
        public override void DoLayout()
        {
            if (Glyphs == null)
            {
                Width = 0;
                return;
            }
            //
            // Determine Columns for accidentals
            //
            Glyphs.Sort((a, b) => a.Y.CompareTo(b.Y));

            // defines the reserved y position of the columns
            var columns = new FastList<float>();
            columns.Add(NonReserved);

            var accidentalSize = 21 * Scale;
            for (int i = 0, j = Glyphs.Count; i < j; i++)
            {
                var g = Glyphs[i];
                g.Renderer = Renderer;
                g.DoLayout();

                // find column where glyph fits into

                // as long the glyph does not fit into the current column
                var gColumn = 0;
                while (columns[gColumn] > g.Y)
                {
                    // move to next column
                    gColumn++;

                    // and create the new column if needed
                    if (gColumn == columns.Count)
                    {
                        columns.Add(NonReserved);
                    }
                }

                // temporary save column as X
                g.X = gColumn;
                columns[gColumn] = g.Y + accidentalSize;
            }

            //
            // Place accidentals in columns
            //
            var columnWidth = 8 * Scale;
            var padding = 2*Scale;
            if (Glyphs.Count == 0)
            {
                Width = 0;
            }
            else
            {
                Width = padding + (columnWidth * columns.Count);
            }

            for (int i = 0, j = Glyphs.Count; i < j; i++)
            {
                var g = Glyphs[i];
                g.X = padding + (Width - ((g.X + 1) * columnWidth));
            }
        }

Usage Example

        public override void DoLayout()
        {
            var x = 0f;

            if (_showParenthesis)
            {
                _preNoteParenthesis.X        = x;
                _preNoteParenthesis.Renderer = Renderer;
                _preNoteParenthesis.DoLayout();
                x += _preNoteParenthesis.Width + ElementPadding * Scale;
            }

            if (!_accidentals.IsEmpty)
            {
                _accidentals.X        = x;
                _accidentals.Renderer = Renderer;
                _accidentals.DoLayout();
                x += _accidentals.Width + ElementPadding * Scale;
            }

            NoteStartX = x;

            base.DoLayout();

            NoteHeadOffset = NoteStartX + (Width - NoteStartX) / 2;

            if (_showParenthesis)
            {
                _postNoteParenthesis.X        = Width + ElementPadding * Scale;
                _postNoteParenthesis.Renderer = Renderer;
                _postNoteParenthesis.DoLayout();
                Width += _postNoteParenthesis.Width + ElementPadding * Scale;
            }
        }