コード例 #1
0
ファイル: FlexBoxes.cs プロジェクト: LazyWolf/Flexerator
        public FlexItem SpawnFlexItem(string className)
        {
            FlexItem newFlexItem = new FlexItem(this, this.Depth + 1, className);

            Children.Add(newFlexItem);
            return(newFlexItem);
        }
コード例 #2
0
ファイル: FlexBoxes.cs プロジェクト: LazyWolf/Flexerator
 public FlexItem(FlexItem parent = null, int depth = 0, string className = "wrap")
 {
     Parent    = parent;
     Depth     = depth;
     Direction = "row";
     Children  = new List <FlexItem>();
     ClassName = className;
 }
コード例 #3
0
ファイル: Flexerator.cs プロジェクト: LazyWolf/Flexerator
        private void ParseArrowAnnotationToFlex(string input)
        {
            // Init
            FlexItem currentFlexItem = new FlexItem(className: $"{tbWraPre.Text}-1");
            var      wraps           = new List <FlexItem>()
            {
                currentFlexItem
            };
            var rows    = new List <FlexItem>();
            var cols    = new List <FlexItem>();
            var rowRevs = new List <FlexItem>();
            var colRevs = new List <FlexItem>();

            // Generate Structure
            for (int i = 0; i < input.Length; i++)
            {
                switch (input[i])
                {
                case '[':
                    currentFlexItem = currentFlexItem.SpawnFlexItem(className: "no-type");
                    break;

                case ']':
                    currentFlexItem = currentFlexItem.Parent;
                    break;

                case '\n':
                    if (currentFlexItem.Parent == null)
                    {
                        currentFlexItem = new FlexItem(className: $"{tbWraPre.Text}-{wraps.Count + 1}");
                        wraps.Add(currentFlexItem);
                    }
                    else
                    {
                        currentFlexItem = currentFlexItem.Parent;
                    }
                    break;

                case '>':
                    rows.Add(currentFlexItem);
                    currentFlexItem.ClassName = $"{tbRowPre.Text}-{rows.Count}";
                    currentFlexItem.Direction = "row";
                    break;

                case '<':
                    rowRevs.Add(currentFlexItem);
                    currentFlexItem.ClassName = $"{tbRowPre.Text}-rev-{rowRevs.Count}";
                    currentFlexItem.Direction = "row-reverse";
                    break;

                case 'V':
                case 'v':
                    cols.Add(currentFlexItem);
                    currentFlexItem.ClassName = $"{tbColPre.Text}-{cols.Count}";
                    currentFlexItem.Direction = "column";
                    break;

                case '^':
                    colRevs.Add(currentFlexItem);
                    currentFlexItem.ClassName = $"{tbColPre.Text}-rev-{colRevs.Count}";
                    currentFlexItem.Direction = "column-reverse";
                    break;

                default:
                    break;
                }
            }

            // HTML Output
            rtbOutputHtml.Text = String.Join("\n", wraps.Select(w => w.Report(chLabels.Checked, tbWraPre.Text))).Trim();

            // CSS Output

            // Label Styling
            string labelStyle = chLabels.Checked ? ".container-label {\n  position: absolute;\n  top: 1px;\n  left: 1px;\n  padding: 2px;\n  " +
                                "border: 1px solid #000;\n  border-radius: 3px;\n  color: #59f9ff;\n  text-shadow: 2px 2px #000;\n  " +
                                "background: #446;\n}\n\n" : "";

            // Wrap Styling
            string extraWrapStyle = string.Join(";\n  ", tbWraStyle.Text.Split(';').Select(e => e.Trim()));
            string wrapStyle      = wraps.Count > 0 ? "." + String.Join(", .", wraps.Select(r => r.ClassName)) + " {\n  display: flex;\n  "
                                    + $"{extraWrapStyle.Trim()}\n}}\n\n" : "";

            // Row Styling
            string extraRowStyle = string.Join(";\n  ", tbRowStyle.Text.Split(';').Select(e => e.Trim()));
            string rowStyle      = rows.Count > 0 ? "." + String.Join(", .", rows.Select(r => r.ClassName))
                                   + " {\n  "
                                   + (chLabels.Checked ? "  position: relative;\n  " : "")
                                   + "display: flex;\n  flex-direction: row;\n  flex-wrap: wrap;\n  flex: 1;\n  "
                                   + $"{extraRowStyle.Trim()}\n}}\n\n" : "";
            string rowRevStyle = rowRevs.Count > 0 ? "." + String.Join(", .", rowRevs.Select(rr => rr.ClassName))
                                 + " {\n  "
                                 + (chLabels.Checked ? "  position: relative;\n  " : "")
                                 + "display: flex;\n  flex-direction: row-reverse;\n  flex-wrap: wrap;\n  flex: 1;\n  "
                                 + $"{extraRowStyle.Trim()}\n}}\n\n" : "";

            // Column Styling
            string extraColStyle = string.Join(";\n  ", tbColStyle.Text.Split(';').Select(e => e.Trim()));
            string colStyle      = cols.Count > 0 ? "." + String.Join(", .", cols.Select(c => c.ClassName))
                                   + " {\n  "
                                   + (chLabels.Checked ? "  position: relative;\n  " : "")
                                   + "display: flex;\n  flex-direction: column;\n  flex-wrap: wrap;\n  flex: 1;\n  "
                                   + $"{extraColStyle.Trim()}\n}}\n\n" : "";
            string colRevStyle = colRevs.Count > 0 ? "." + String.Join(", .", colRevs.Select(cr => cr.ClassName))
                                 + " {\n  "
                                 + (chLabels.Checked ? "  position: relative;\n  " : "")
                                 + "display: flex;\n  flex-direction: column-reverse;\n  flex-wrap: wrap;\n  flex: 1;\n  "
                                 + $"{extraColStyle.Trim()}\n}}\n\n" : "";

            rtbOutputCss.Text = $"{labelStyle}{wrapStyle}{rowStyle}{rowRevStyle}{colStyle}{colRevStyle}".Trim();
        }