No BSD License  

Highlights from
Yet Another Layout Manager

  • resize_example 1. This layout manager is based on MATLAB Central File Exchange entry "Resizable
  • RE_Axis custom axis
  • RE_Box elementary layout building block, positions matrix of elements
  • RE_Button checkboxes/radiobuttons/togglebuttons column
  • RE_Layout Class which defines figure and has many factory methods for ui components
  • RE_Panel custom axis
  • RE_Separator separator with or without label
  • RE_Tabpane tab pane implementation using java element
  • View all files
image thumbnail
from Yet Another Layout Manager by amilcar chaudhary
Easily align gui elements and quickly build resizable gui

RE_Layout
%% Class which defines figure and has many factory methods for ui components
classdef RE_Layout < hgsetget
    
    properties
        Pane = [];      % pane panel
        Handle = [];    % figure handle
        Color = [];     % figure color
        ResizeFcn = []; % function called when figure is being resized        
    end

    methods

        % CONSTRUCTOR
        function obj = RE_Layout(varargin)
            obj.Color = get(0, 'DefaultUIControlBackgroundColor');
            def = {'DefaultUIControlFontName', 'tahoma', 'DefaultAxesUnits', 'pixels', 'DefaultUIPanelUnits', 'pixels'};
            obj.Handle = figure(def{:}, 'NumberTitle', 'off', 'MenuBar', 'none', 'DockControls', 'off', 'Color', obj.Color, varargin{:}, 'Visible', 'off');
        end

        % factory methods
        function bx = box(obj, element, varargin)
            if numel(element) == 1
                bx = local_box(obj, element, 'Width', -1, 'Height', -1, varargin{:});
            else
                bx = local_box(obj, element, varargin{:});
            end
        end

        function bx = vbox(obj, element, height, varargin)
            bx = local_box(obj, element(:), 'Width', -1, 'Height', height, varargin{:});
        end

        function bx = hbox(obj, element, width, varargin)
            bx = local_box(obj, element(:)', 'Width', width, 'Height', -1, varargin{:});
        end

        function pn = panel(obj, varargin)
            pn = RE_Panel(varargin{:});
            set(pn.Handle(1), 'Parent', obj.Handle);
        end
        
        function tb = tabpane(obj, varargin)
            tb = RE_Tabpane(varargin{:});
            set(tb.Handle(1), 'Parent', obj.Handle);
        end        

        function sp = separator(obj, varargin)
            sp = RE_Separator(varargin{:});
            set(sp.Handle, 'Parent', obj.Handle);
        end

        function cb = check(obj, varargin)
            cb = RE_Button(varargin{:}, 'Style', 'CheckBox');
            set(cb.Handle, 'Parent', obj.Handle);
        end

        function rb = radio(obj, varargin)
            rb = RE_Button(varargin{:}, 'Style', 'RadioButton');
            set(rb.Handle, 'Parent', obj.Handle);
        end

        function ax = axis(obj, varargin)
            ax = RE_Axis(varargin{:});
            set(ax.Handle, 'Parent', obj.Handle);
        end

        function show(obj, wh)
            local_show(obj, wh);
        end
    end % methods
end % classdef

%% add elements to ResizablePane
function pn = local_box(obj, element, varargin)

% use java container
if iscell(element)
    isj = cellfun(@(x) isjava(x), element);
    if any(isj)
        for ind = find(isj(:)')
            [hcomp, hcont] = javacomponent(element{ind});
            element{ind}   = hcont;
        end
    end
elseif isjava(element)
    [hcomp, element] = javacomponent(element);
end

pn = RE_Box(element);
set(pn, varargin{:});
set(pn.Handle, 'Parent', obj.Handle);
obj.Pane = pn;
end

%% make figure and layout visible
function local_show(obj, wh)
obj.ResizeFcn = get(obj.Handle, 'ResizeFcn');

ssz = get(0, 'ScreenSize');
pos = [(ssz(3:4)-wh)/2, wh];
fun = @(varargin) local_position(obj);

local_position(obj, pos);
set(obj.Handle, 'Visible', 'on', 'ResizeFcn', fun);
drawnow();
end

%% set figure to the given position and pack layout
function local_position(obj, pos)

if nargin > 1
    set(obj.Handle, 'Position', pos);
else
    pos = get(obj.Handle, 'Position');
end

pos(1:2) = 0;
set(obj.Pane, 'Position', pos);

if isempty(obj.ResizeFcn), return; end

evt = struct('position', pos);
obj.ResizeFcn(obj.Handle, evt);
end

Contact us at files@mathworks.com