public int FindItemIndex(HtmlControlBase control) { for (var index = 0; index != Items_.Count; ++index) { if (Items_[index].Container == control || Items_[index].Container == control) { return(index); } } return(-1); }
private void SetImage(string imagePath) { Classes.Add("image"); Children.Remove(DivImg); DivImg = new HtmlControlBase(Page) { HtmlDefaultTag = "img", }; DivImg.Attributes["src"] = imagePath; Children.Insert(0, DivImg); }
private void SetIcon(string iconName) { Classes.Remove("image"); Children.Remove(DivImg); DivImg = new HtmlControlBase(Page) { HtmlDefaultTag = "i", }; DivImg.Classes.AddRange(new List <string> { iconName, "icon" }); Children.Insert(0, DivImg); }
private Task OnItemClickedFromClient(HtmlControlBase control) { var index = FindItemIndex(control); if (index == -1) { return(Task.CompletedTask); // shouldn't happen, but who knows } var item = Items_[index]; SelectedIndex = index; return(Task.CompletedTask); }
public void SetGroups(List <MenuGroup> groups) { Groups = groups; foreach (var group in groups) { var mainDiv = new Div(Page) { Classes = new List <string> { "item" } }; Children.Add(mainDiv); var header = new Div(Page) { Classes = new List <string> { "header" }, InnerText = group.Header }; mainDiv.Children.Add(header); var menu = new Div(Page) { Classes = new List <string> { "menu" } }; mainDiv.Children.Add(menu); foreach (var item in group.Items) { var link = new HtmlControlBase(Page, "a") { Classes = new List <string> { "item" }, InnerText = item.Text, }; link.OnClicked += (control) => OnLinkClicked(item); menu.Children.Add(link); } } }
private ListViewItem AddSingleItem(T item, int?index = null) { var mainDiv = new HtmlControlBase(Page) { HtmlDefaultTag = ContainerHtmlDefaultTag, Classes = new List <string> { "item" } }; if (index.HasValue) { Children.Insert(index.Value, mainDiv); } else { Children.Add(mainDiv); } mainDiv.OnClicked += OnItemClickedFromClient; var listViewItem = new ListViewItem() { Container = mainDiv, Data = item }; if (index.HasValue) { Items_.Insert(index.Value, listViewItem); } else { Items_.Add(listViewItem); } OnGenerateItem?.Invoke(mainDiv, item); if (index != null && SelectedIndex_ != null && SelectedIndex_ >= index) { ++SelectedIndex_; } return(listViewItem); }
public virtual void InitializeMenuPage(FSWPage page, HtmlControlBase parent) { Container = new TemplateContainer(Page, UrlPath); parent.Children.Add(Container); var fields = GetType().GetFields(System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); foreach (var field in fields) { // will check if both the type is based on 'ControlBase', and if the value is set at all! if (field.GetValue(this) is ControlBase control) { if (control is HtmlControlBase htmlControl) { htmlControl.CustomSelector = "#" + field.Name; } Container.Children.Add(control); } } }
public Menu(HtmlControlBase pageContainer) { Container = pageContainer; }
public MenuListView <HorizontalMenuItem> AddHorizontalMenu(string id, HorizontalMenuOptions options, string width = null) { var listView = new MenuListView <HorizontalMenuItem>(Page) { Divided = true, Inverted = true, Pointing = true, Vertical = true, Width = width ?? DefaultWidth, }; listView.Extensions.Add <Transition>(); if (options.GetText != null) { options.RefreshItem = (item) => { var v = options.GetText(item.Id); if (listView?.IsRemoved != false) { return; } item.Value = v; listView.UpdateItem(item); }; } listView.OnItemSelected += (item) => { PopTo(id, true); options.OnSelected?.Invoke(item.Data); }; HtmlControlBase mainContainer = listView; if (options.ShowSearchBox) { mainContainer = new Div(Page) { Height = "100%", Classes = new List <string> { "ui", "inverted", "segment" } }; var searchBox = new TextBox(Page) { Placeholder = "Search...", InstantFeedback = TimeSpan.FromMilliseconds(50) }; searchBox.OnTextChanged += (sender, previous, newText) => { newText = newText.ToLower(); foreach (var item in listView.Items.DataEnumerator) { if (item.Data.Name.ToLower().Contains(newText)) { item.Container.Visible = VisibleState.Block; } else { item.Container.Visible = VisibleState.None; } } }; mainContainer.Children.Add(new Div(Page) { Classes = new List <string> { "ui", "input" }, Width = width ?? DefaultWidth, Height = "40px", Children = new List <Core.ControlBase> { searchBox } }); mainContainer.Children.Add(listView); } mainContainer.Height = "100%"; mainContainer.Visible = VisibleState.None; mainContainer.Float = FloatDirection.Left; mainContainer.CssProperties.AddRange(new Dictionary <string, string> { ["margin-top"] = "0px", ["margin-right"] = "3px", ["margin-left"] = Stacks.Count == 0 ? "0px" : "3px", ["overflow-y"] = "auto" }); listView.OnGenerateItem += (HtmlControlBase container, HorizontalMenuItem obj) => { container.Children.Clear(); container.Children.Add(new Span(Page, obj.Name)); if (!obj.RequireLoading) { return; } if (obj.Value == null) { container.Children.Add(new Html.LoadingIcon(Page)); Page.Manager.Invoke(() => options.RefreshItem(obj)); } else { container.Children.Add(new Span(Page, obj.Value) { Classes = new List <string> { "ui", "label" } }); } }; Stacks.Push(new HorizontalStackItem() { Control = mainContainer, Id = id, Tag = options }); Children.Add(mainContainer); //mainContainer.Transition(Transition.Animation.SlideRight); mainContainer.Visible = VisibleState.Block; if (options.PopulateListView != null) { Page.Manager.Invoke(() => options.PopulateListView(listView)); } return(listView); }