Beispiel #1
0
        public SectionWidget(string sectionTitle, GuiWidget sectionContent, ThemeConfig theme, GuiWidget rightAlignedContent = null, int headingPointSize = -1, bool expandingContent = true, bool expanded = true, string serializationKey = null, bool defaultExpansion = false, bool setContentVAnchor = true)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor = HAnchor.Stretch;
            this.VAnchor = VAnchor.Fit;

            theme.ApplyBorder(this, new BorderDouble(top: 1));

            this.setContentVAnchor = setContentVAnchor;

            if (!string.IsNullOrEmpty(sectionTitle))
            {
                // Add heading
                var pointSize = (headingPointSize) == -1 ? theme.DefaultFontSize : headingPointSize;

                // If the control is expandable and a serialization key is supplied, set expanded from persisted value
                if (serializationKey != null && expandingContent)
                {
                    string dbValue = UserSettings.Instance.get(serializationKey);
                    expanded = dbValue == "1" || (dbValue == null && defaultExpansion);
                }

                checkbox = new ExpandCheckboxButton(sectionTitle, theme, pointSize: pointSize, expandable: expandingContent)
                {
                    HAnchor = HAnchor.Stretch,
                    Checked = expanded,
                    Padding = 0
                };
                checkbox.CheckedStateChanged += (s, e) =>
                {
                    if (expandingContent)
                    {
                        ContentPanel.Visible = checkbox.Checked;
                    }
                    // TODO: Remove this Height = 10 and figure out why the layout engine is not sizing these correctly without this.
                    ContentPanel.Height = 10;
                };

                if (serializationKey != null)
                {
                    checkbox.CheckedStateChanged += (s, e) =>
                    {
                        UserSettings.Instance.set(serializationKey, checkbox.Checked ? "1" : "0");
                    };
                }

                if (rightAlignedContent == null)
                {
                    this.AddChild(checkbox);
                }
                else
                {
                    rightAlignedContent.HAnchor |= HAnchor.Right;

                    var headingRow = new GuiWidget()
                    {
                        VAnchor = VAnchor.Fit,
                        HAnchor = HAnchor.Stretch
                    };
                    headingRow.AddChild(checkbox);
                    headingRow.AddChild(rightAlignedContent);
                    this.AddChild(headingRow);
                }

                this.rightAlignedContent = rightAlignedContent;
            }

            sectionContent.Visible = expanded;

            this.SetContentWidget(sectionContent);
        }