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

    function doPosition(h)
%DOPOSITION Set label and control positions
%
%  DOPOSITION(OBJ) Updates the position of the label and control.

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




Lrel=strcmp(h.LabelSizeMode,'relative');
Crel=strcmp(h.ControlSizeMode,'relative');
Ls=h.LabelSize;
Cs=h.ControlSize;

Lpos=zeros(1,4);
Cpos=Lpos;

pos=h.position;
brdr=h.Border;
if any(brdr)
   pos(1:2)=pos(1:2) + brdr(1:2);
   pos(3:4)=max([1 1],pos(3:4) - brdr(1:2) - brdr(3:4));
end

availW=max(1,pos(3)-h.gap);
maxW=pos(1)+pos(3)-1;

% width calcs
Lpos(1)=pos(1);
if Lrel & Crel
   if (Ls+Cs)>1
      div=(Ls+Cs);
      Ls=Ls./div;
      Cs=Cs./div;
   end
   Lpos(3)=availW*Ls;
   Cpos(1)=min(maxW,Lpos(1)+Lpos(3)+h.Gap);
   Cpos(3)=availW*Cs;
elseif Lrel
   Cs=min(Cs,availW);
   availW=availW-Cs;
   Lpos(3)=availW*Ls;
   Cpos(1)=min(maxW,Lpos(1)+Lpos(3)+h.Gap);
   Cpos(3)=Cs;
elseif Crel
   Ls=min(Ls,availW);
   availW=availW-Ls;
   Lpos(3)=Ls;
   Cpos(1)=min(maxW,Lpos(1)+Lpos(3)+h.Gap);
   Cpos(3)=availW*Cs;
else
   % both absolute
   if (Ls+Cs)>availW
      div=(Ls+Cs);
      Ls=availW*Ls./div;
      Cs=availW*Cs./div;
   end
   Lpos(3)=Ls;
   Cpos(1)=min(maxW,Lpos(1)+Lpos(3)+h.Gap);
   Cpos(3)=Cs;
end

% height calcs
Cpos(2)=pos(2);
Cpos(4)=pos(4);
Lpos(2)=pos(2);
switch h.BaseLineOffSetZero
case 'top'
   Lpos(4)=pos(4)+h.BaselineOffset+10;
case 'middle'
   Lpos(4)=ceil(pos(4)*0.5)+h.BaselineOffset+10;
case 'bottom'
   Lpos(4)=h.BaselineOffset+10;
end

set(h.LabelH,'Position',Lpos);
if h.hascontrol
   Cpos(3:4)=max(Cpos(3:4),[1 1]);
   set(h.Control,'Position',Cpos);
end