Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use enumeration classes for FontWeight and FontAngle and fixes in eventdata classes #76

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions widgets/+wt/+enum/FontAngleState.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classdef FontAngleState
%FONTANGLESTATE Represents font angle selections
% Enumerates a list of choices


%% Enumerations
enumeration
normal
italic
end %enumeration


end %classdef

14 changes: 14 additions & 0 deletions widgets/+wt/+enum/FontWeightState.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
classdef FontWeightState
%FONTWEIGHTSTATE Represents font weight selections
% Enumerates a list of choices


%% Enumerations
enumeration
normal
bold
end %enumeration


end %classdef

14 changes: 9 additions & 5 deletions widgets/+wt/+eventdata/PropertyChangedData.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
% Set the changed property name
obj.Property = propName;

% Is input a MATLAB eventdata?
if isa(newValue,'matlab.ui.eventdata.ValueChangedData')
% Is input a MATLAB or widget eventdata?
if isa(newValue,'wt.eventdata.ValueChangedData') || ...
isa(newValue,'wt.eventdata.PropertyChangedData')
obj.Value = newValue.Value;
obj.PreviousValue = newValue.PreviousValue;
elseif isa(newValue,'matlab.ui.eventdata.ValueChangedData')
obj.Value = newValue.Value;
obj.PreviousValue = newValue.PreviousValue;
elseif isa(newValue,'matlab.ui.eventdata.ValueChangingData')
Expand All @@ -42,9 +46,9 @@
end

% Any remaining varargin are dynamic property-value pairs
for idx=1:numel(varargin)
thisProp = varargin{idx};
thisValue = remArgs.(thisProp);
for idx = 1:floor(numel(varargin) / 2)
thisProp = varargin{(idx - 1) * 2 + 1};
thisValue = varargin{(idx - 1) * 2 + 2};
obj.addprop(thisProp);
obj.(thisProp) = thisValue;
end
Expand Down
8 changes: 6 additions & 2 deletions widgets/+wt/+eventdata/ValueChangedData.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
previousValue = []
end

% Is input a MATLAB eventdata?
if isa(newValue,'matlab.ui.eventdata.ValueChangedData')
% Is input a MATLAB or widget eventdata?
if isa(newValue,'wt.eventdata.ValueChangedData') || ...
isa(newValue,'wt.eventdata.PropertyChangedData')
obj.Value = newValue.Value;
obj.PreviousValue = newValue.PreviousValue;
elseif isa(newValue,'matlab.ui.eventdata.ValueChangedData')
obj.Value = newValue.Value;
obj.PreviousValue = newValue.PreviousValue;
elseif isa(newValue,'matlab.ui.eventdata.ValueChangingData')
Expand Down
4 changes: 2 additions & 2 deletions widgets/+wt/+mixin/FontStyled.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
FontSize (1,1) double {mustBePositive,mustBeFinite} = 12

% Font weight (normal/bold)
FontWeight {mustBeMember(FontWeight,{'normal','bold'})} = 'normal'
FontWeight (1,1) wt.enum.FontWeightState = 'normal'

% Font angle (normal/italic)
FontAngle {mustBeMember(FontAngle,{'normal','italic'})} = 'normal'
FontAngle (1,1) wt.enum.FontAngleState = 'normal'

% Font color
FontColor (1,3) double {wt.validators.mustBeBetweenZeroAndOne} = [0 0 0]
Expand Down
17 changes: 17 additions & 0 deletions widgets/+wt/+utility/convertEnumToValue.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function value = convertEnumToValue(value)
% Convert enumaration value to its double or string associated value

valueClass = class(value);

% Is the value enumerate?
if startsWith(valueClass, 'wt.enum')
% Can value be converted?
if ismethod(value, 'double')
value = double(value);
elseif ismethod(value, 'string')
value = string(value);
elseif ismethod(value, 'char')
value = char(value);
end
end %if
end %function
3 changes: 3 additions & 0 deletions widgets/+wt/+utility/setStylePropsInPriority.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function setStylePropsInPriority(comps, propNames, value)
value
end

% Convert enumerate value
value = wt.utility.convertEnumToValue(value);

% Filter any invalid components
comps(~isvalid(comps)) = [];

Expand Down