From 0366416be602c04b1346e61fcb93f8f72e79819b Mon Sep 17 00:00:00 2001 From: Robyn Jackey <15696076+rjackey@users.noreply.github.com> Date: Fri, 22 Oct 2021 11:40:55 -0400 Subject: [PATCH] add WIP for SearchField --- .../jiYzFyUNbNpZ1WV9z0H6tMJNk6wd.xml | 6 + .../jiYzFyUNbNpZ1WV9z0H6tMJNk6wp.xml | 2 + widgets/+wt/SearchField.m | 119 ++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 resources/project/elO4D6tOV7Lp-Jfo7ptgr2NlB30/jiYzFyUNbNpZ1WV9z0H6tMJNk6wd.xml create mode 100644 resources/project/elO4D6tOV7Lp-Jfo7ptgr2NlB30/jiYzFyUNbNpZ1WV9z0H6tMJNk6wp.xml create mode 100644 widgets/+wt/SearchField.m diff --git a/resources/project/elO4D6tOV7Lp-Jfo7ptgr2NlB30/jiYzFyUNbNpZ1WV9z0H6tMJNk6wd.xml b/resources/project/elO4D6tOV7Lp-Jfo7ptgr2NlB30/jiYzFyUNbNpZ1WV9z0H6tMJNk6wd.xml new file mode 100644 index 00000000..80b5b161 --- /dev/null +++ b/resources/project/elO4D6tOV7Lp-Jfo7ptgr2NlB30/jiYzFyUNbNpZ1WV9z0H6tMJNk6wd.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/resources/project/elO4D6tOV7Lp-Jfo7ptgr2NlB30/jiYzFyUNbNpZ1WV9z0H6tMJNk6wp.xml b/resources/project/elO4D6tOV7Lp-Jfo7ptgr2NlB30/jiYzFyUNbNpZ1WV9z0H6tMJNk6wp.xml new file mode 100644 index 00000000..d0f3faac --- /dev/null +++ b/resources/project/elO4D6tOV7Lp-Jfo7ptgr2NlB30/jiYzFyUNbNpZ1WV9z0H6tMJNk6wp.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/widgets/+wt/SearchField.m b/widgets/+wt/SearchField.m new file mode 100644 index 00000000..c2182955 --- /dev/null +++ b/widgets/+wt/SearchField.m @@ -0,0 +1,119 @@ +classdef SearchField < wt.abstract.BaseWidget + % A search entry field + + % Copyright 2021 The MathWorks Inc. + + + %% Public properties + properties (AbortSet) + + % The current value shown + Value (1,1) string + + end %properties + + + %% Events + events (HasCallbackProperty, NotifyAccess = protected) + + % Triggered on value changed, has companion callback + ValueChanged + + end %events + + + + %% Internal Properties + properties ( Transient, NonCopyable, ... + Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} ) + + % Search control + SearchControl (1,1) matlab.ui.control.HTML + + end %properties + + + + %% Protected methods + methods (Access = protected) + + function setup(obj) + + % Call superclass setup first to establish the grid + obj.setup@wt.abstract.BaseWidget(); + + % Set default size + obj.Position(3:4) = [100 25]; + + % Define the HTML source + html = ['',... + '']; + + % Create a html search input + obj.SearchControl = uihtml(... + 'Parent',obj.Grid,... + 'HTMLSource',html,... + 'DataChangedFcn',@(h,e)obj.onSearchChanged(e) ); + + end %function + + + function update(obj) + + % Update the edit control text + obj.SearchControl.Data = obj.Value; + + end %function + + end %methods + + + + %% Private methods + methods (Access = private) + + function onSearchChanged(obj,evt) + % Triggered on interaction + + % Return early if data hasn't changed + % The html control may send a double callback on edits + if strcmp(evt.Data, evt.PreviousData) + return + end + + % Prepare event data + evtOut = wt.eventdata.PropertyChangedData('Value',evt.Data, obj.Value); + + % Store new result + obj.Value = evt.Data; + + % Trigger event + notify(obj,"ValueChanged",evtOut); + + end %function + + end %methods + + + %% Accessors + methods + + function set.Value(obj,value) + drawnow %needs a moment to render so that display can update + obj.Value = value; + end + + end % methods + + +end % classdef +