public SearchableSectionWidget(string sectionTitle, GuiWidget sectionContent, ThemeConfig theme, int headingPointSize = -1, bool expandingContent = true, bool expanded = true, string serializationKey = null, bool defaultExpansion = false, bool setContentVAnchor = true, string emptyText = null) : base(sectionTitle, sectionContent, theme, theme.CreateSearchButton(), headingPointSize, expandingContent, expanded, serializationKey, defaultExpansion, setContentVAnchor) { var headerRow = this.Children.First(); searchPanel = new TextEditWithInlineCancel(theme, emptyText) { Visible = false, BackgroundColor = theme.TabBarBackground, MinimumSize = new Vector2(0, headerRow.Height) }; searchPanel.TextEditWidget.Margin = new BorderDouble(3, 0); searchPanel.TextEditWidget.ActualTextEditWidget.EnterPressed += (s, e) => { var filter = searchPanel.TextEditWidget.Text.Trim(); this.SearchInvoked?.Invoke(this, new StringEventArgs(filter)); searchPanel.Visible = false; headerRow.Visible = true; searchPanel.TextEditWidget.Text = ""; }; searchPanel.ResetButton.Click += (s, e) => { searchPanel.Visible = false; headerRow.Visible = true; searchPanel.TextEditWidget.Text = ""; }; var searchButton = this.rightAlignedContent as GuiWidget; searchButton.Click += (s, e) => { searchPanel.Visible = true; headerRow.Visible = false; }; this.AddChild(searchPanel, 1); }
public InlineStringEdit(string stringValue, ThemeConfig theme, string automationName, bool boldFont = false, bool editable = true, string emptyText = null) : base(theme.TabbarPadding) { this.Padding = theme.ToolbarPadding; this.HAnchor = HAnchor.Stretch; this.VAnchor = VAnchor.Fit; titleText = new TextWidget(stringValue, textColor: theme.TextColor, pointSize: theme.DefaultFontSize, bold: boldFont) { VAnchor = VAnchor.Center, AutoExpandBoundsToText = true, EllipsisIfClipped = true, Margin = new BorderDouble(left: 5) }; this.AddChild(titleText); this.ActionArea.VAnchor = VAnchor.Stretch; this.ActionArea.MinimumSize = new Vector2(0, titleText.Height); saveButton = new IconButton(StaticData.Instance.LoadIcon("fa-save_16.png", 16, 16).SetToColor(theme.TextColor), theme) { ToolTipText = "Save".Localize(), Visible = false, Name = automationName + " Save", }; textEditWithInlineCancel = new TextEditWithInlineCancel(theme, emptyText) { Visible = false, Margin = new BorderDouble(left: 4) }; textEditWithInlineCancel.TextEditWidget.ActualTextEditWidget.EnterPressed += (s, e) => { this.Text = textEditWithInlineCancel.Text; this.SetVisibility(showEditPanel: false); this.ValueChanged?.Invoke(this, null); }; textEditWithInlineCancel.TextEditWidget.Name = automationName + " Field"; textEditWithInlineCancel.ResetButton.Name = "Close Title Edit"; textEditWithInlineCancel.ResetButton.ToolTipText = "Close".Localize(); textEditWithInlineCancel.ResetButton.Click += (s, e) => { this.SetVisibility(showEditPanel: false); }; this.AddChild(textEditWithInlineCancel); rightPanel = new FlowLayoutWidget(); var icon = editable ? StaticData.Instance.LoadIcon("icon_edit.png", 16, 16).SetToColor(theme.TextColor) : new ImageBuffer(16, 16); editButton = new IconButton(icon, theme) { ToolTipText = "Edit".Localize(), Name = automationName + " Edit", Selectable = editable }; editButton.Click += (s, e) => { if (this.EditOverride != null) { this.EditOverride.Invoke(this, null); } else { textEditWithInlineCancel.Text = this.Text; this.SetVisibility(showEditPanel: true); } }; rightPanel.AddChild(editButton); saveButton.Click += (s, e) => { if (!string.IsNullOrEmpty(textEditWithInlineCancel.Text)) { this.Text = textEditWithInlineCancel.Text; } this.SetVisibility(showEditPanel: false); }; rightPanel.AddChild(saveButton); this.SetRightAnchorItem(rightPanel); this.ActionArea.Margin = this.ActionArea.Margin.Clone(right: rightPanel.Width + 5); }
public SearchPanel(ChromeTabs tabControl, GuiWidget searchButton, ThemeConfig theme) : base(theme, GrabBarSide.Left) { this.HAnchor = HAnchor.Absolute; this.VAnchor = VAnchor.Absolute; this.Width = 500; this.Height = 200; this.BackgroundColor = theme.SectionBackgroundColor; this.tabControl = tabControl; this.searchButton = searchButton; searchButton.BackgroundColor = theme.SectionBackgroundColor; GuiWidget searchResults = null; var scrollable = new ScrollableWidget(true) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Stretch }; searchBox = new TextEditWithInlineCancel(theme) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, Margin = new BorderDouble(5, 8, 5, 5) }; searchBox.TextEditWidget.ActualTextEditWidget.EnterPressed += async(s2, e2) => { searchResults.CloseChildren(); searchResults.AddChild( new TextWidget("Searching".Localize() + "...", pointSize: theme.DefaultFontSize, textColor: theme.TextColor) { Margin = 10 }); this.Invalidate(); var searchHits = await Task.Run(() => { return(HelpIndex.Search(searchBox.TextEditWidget.Text)); }); searchResults.CloseChildren(); foreach (var searchResult in searchHits) { var resultsRow = new HelpSearchResultRow(searchResult, theme); resultsRow.Click += this.ResultsRow_Click; searchResults.AddChild(resultsRow); } if (searchResults.Children.Count == 0) { searchResults.AddChild(new SettingsRow("No results found".Localize(), null, theme, StaticData.Instance.LoadIcon("StatusInfoTip_16x.png", 16, 16).SetPreMultiply())); } // Add top border to first child if (searchResults.Children.FirstOrDefault() is GuiWidget firstChild) { searchResults.BorderColor = firstChild.BorderColor; searchResults.Border = new BorderDouble(top: 1); // firstChild.Border = firstChild.Border.Clone(top: 1); - doesn't work for some reason, pushing border to parent above } scrollable.TopLeftOffset = Vector2.Zero; }; searchBox.ResetButton.Click += (s2, e2) => { searchBox.BackgroundColor = Color.Transparent; searchBox.TextEditWidget.Text = ""; searchResults.CloseChildren(); }; this.AddChild(searchBox); scrollable.ScrollArea.HAnchor = HAnchor.Stretch; scrollable.ScrollArea.VAnchor = VAnchor.Fit; this.AddChild(scrollable); searchResults = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit }; scrollable.AddChild(searchResults); }