diff --git a/Source/Samples/Sections/Widgets/EntrySection.cs b/Source/Samples/Sections/Widgets/EntrySection.cs index 880018861..32a84f207 100644 --- a/Source/Samples/Sections/Widgets/EntrySection.cs +++ b/Source/Samples/Sections/Widgets/EntrySection.cs @@ -12,6 +12,9 @@ namespace Samples AddItem(CreateMaxLimitEntry()); AddItem(CreatePlaceholderEntry()); AddItem(CreateInvisibleCharEntry()); + AddItem(CreateCustomActionsEntry()); + AddItem(CreateProgressEntry()); + AddItem(CreateCompletionEntry()); } public (string, Widget) CreateSimpleEntry() @@ -66,5 +69,100 @@ namespace Samples return ("Invisible text entry:", entry); } + public (string, Widget) CreateCustomActionsEntry() + { + var entry = new Entry(); + entry.PlaceholderText = "Search"; + entry.SetIconFromIconName(EntryIconPosition.Primary, "edit-find-symbolic"); + entry.SetIconFromIconName(EntryIconPosition.Secondary, "edit-clear-symbolic"); + + entry.IconRelease += (o, args) => + { + switch (args.P0) + { + case EntryIconPosition.Primary: + ApplicationOutput.WriteLine(o, "Clicked Search Icon"); + break; + + default: + entry.Text = string.Empty; + ApplicationOutput.WriteLine(o, "Clicked Clear Icon"); + break; + } + }; + + return ("Custom actions entry:", entry); + } + + public (string, Widget) CreateProgressEntry() + { + var entry = new Entry(); + entry.PlaceholderText = "Progress Entry"; + entry.ProgressFraction = 0f; + entry.MaxLength = 20; + + entry.Changed += (sender, e) => entry.ProgressFraction = (float)entry.Text.Length / entry.MaxLength; + + return ("Progress entry:", entry); + } + + public (string, Widget) CreateCompletionEntry() + { + // create completion object and assign it to entry + var completion = new EntryCompletion(); + var entry = new Entry(); + entry.Completion = completion; + + // create values store + var store = new ListStore(typeof(string)); + store.AppendValues("An example to search for"); + store.AppendValues("Better example"); + store.AppendValues("Better and bigger example"); + store.AppendValues("Some other example"); + + // create tree column + var column = new TreeViewColumn(); + column.Reorderable = false; + column.SortIndicator = false; + column.Clickable = true; + column.SortColumnId = 0; + + // create cells + var cell = new CellRendererText(); + column.PackStart(cell, true); + + // set cell functions + column.SetCellDataFunc(cell, (TreeViewColumn tree_column, CellRenderer cellRenderer, ITreeModel tree_model, TreeIter iter) => + { + var m = tree_model.GetValue(iter, 0); + (cellRenderer as CellRendererText).Text = (string)m; + }); + + // model filter + var filter = new TreeModelFilter(store, null); + filter.VisibleFunc = (model, iter) => + { + if (string.IsNullOrEmpty(entry.Text)) + return true; + + var o = model.GetValue(iter, 0); + var searchString = o as string; + if (!string.IsNullOrEmpty(searchString)) + { + if (searchString.StartsWith(entry.Text, System.StringComparison.InvariantCultureIgnoreCase)) + return true; + else + return false; + } + + return true; + }; + + // assign treemodel as the completion + completion.Model = filter; + completion.TextColumn = 0; + + return ("Completion Entry:",entry); + } } }