www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xreglistctrl/xreglistctrl.m

    function obj = xreglistctrl(varargin)
%XREGLISTCTRL Constructor for xreglistctrl object
%
%  L=XREGLISTCTRL
%  L=XREGLISTCTRL(FIG)
%  L=XREGLISTCTRL('Property1',Value1,...)
%  L=XREGLISTCTRL(FIG,'Property1',Value1,...)
%
%  Min dimensions for cell is 25 by 15 pixels
%  Min dimensions for xreglistctrl is 40 by 40 pixels
%
%  Callback to be executed when any control object changes
%  use SET(L, 'CALLBACK', 'CALLBACK STRING');
%
%  Controls must allow the operations:
%  GET(CTRL, 'VALUE')
%  SET(CTRL, 'VISIBLE', 'ON/OFF')
%  SET(CTRL, 'POSTITION',[])
%  DELETE(CTRL)
%  SET(CTRL, 'CALLBACK', 'STRING')
%  and this string must be executed as the final step
%  in the callback of the ctrl object

%  Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.


% Data stored in ud of slider
ud.position = [10 10 300 300];
ud.sliderwidth = 15;
ud.border = 3;
ud.cellBorder = 2;
ud.controls = {};
ud.cellHeight = 30;
ud.top = 1;
ud.callback = '';
% fixnumcells = optional field. If on, redraw numcells held constant
% normally this field empty and redraw keeps cellheight constant
ud.fixnumcells = [];
ud.userdata = [];

% object fields for frame and slider
obj.slider = [];
obj.frame = [];


% ====== construction ==========
if nargin>0 && mbcgui.util.isComponentParent(varargin{1}) 
    fh = varargin{1};
    varargin(1) = [];
else
    fh = gcf;
end

border = ud.border;
sliderWidth = ud.sliderwidth;
cellHeight = ud.cellHeight;
controls = ud.controls;
pos = ud.position;
numCells = floor((pos(4)-2*border)/cellHeight);

% === draw frame, with slider  ===
framePos = pos;
frame = mbcgui.container.layoutpanel(...
    'Parent', fh, ...
    'Position', framePos, ...
    'BorderType', 'etchedin', ...
    'Visible', 'off', ...
    'Tag', 'xreglistctrl_frame');

% NOTE: slider val=1 is bottom so all slider vals seem upsidedown
slLength = max(length(controls)-numCells+1,1);
slstep = [1 1]/max(1,(slLength-1));
slstep = max(min(slstep,1),0);
slider = uicontrol('Parent',frame,...
    'Style','slider',...
    'Enable','off',...
    'Max',max(slLength,2),...
    'Min',1,...
    'SliderStep',slstep,...
    'Value',slLength);
els = cell(1, numCells+3);
els{end} = slider;
lyt = xreggridbaglayout(frame, ....
    'Dimension', [numCells+2 2], ...
    'Colsizes', [-1 sliderWidth], ...
    'Rowsizes', [0 repmat(-1, 1, numCells) 0], ...
    'mergeblock', {[1 numCells+2], [2 2]}, ...
    'elements', els);
set(frame, 'LayoutComponent', {lyt});

obj.layout = lyt;
obj.slider = slider;
obj.frame = frame;
obj = class(obj,'xreglistctrl');

set(slider, 'Callback', {@i_slidercb, obj});

% This is the object to use when dispatching callbacks.  It allows
% subclasses to capture callbacks while still using callback strings
ud.object = obj;
set(slider,'UserData',ud);

DoVis = true;
if ~isempty(varargin)
    % Check for a visible call
    DoVis = ~any(strcmpi('visible',varargin(1:2:end)));
    obj = set(obj,varargin{:});
end
if DoVis
    set(frame,'Visible','on');
end

function i_slidercb(src, evt, obj)
slider(obj);