function thisrender(this, hFig, pos)
%RENDER Render the varsinheader object
%   RENDER(this, hFIG, POS) Render the varsinheader object (this) to the
%   figure hFIG in the position POS.

%   Copyright 1988-2021 The MathWorks, Inc.

if nargin < 3
    pos = [10 10 300 200];
    if nargin < 2
        hFig = gcf;
    end
end

sz  = gui_sizes(this);
cbs = callbacks(this);

hPanel = uipanel('Parent', hFig, ...
    'Visible',  'Off', ...
    'Units',    'Pixels', ...
    'Position', pos, ...
    'Units',    'Normalized', ...
    'Tag',      'exportheader_variableframe', ...
    'Title',    getString(message('signal:sigtools:siggui:Variablenamesinheader')));

hLayout = siglayout.gridbaglayout(hPanel);

set(hLayout, ...
    'HorizontalGap',     5, ...
    'VerticalGap',       5, ...
    'HorizontalWeights', [0 1 0 1], ...
    'VerticalWeights',   [0 1]);

for i = 1:2

    if i == 1
        ti = 20*sz.pixf;
    else
        ti = 5*sz.pixf;
    end

    % Render the controls
    num = num2str(i);

    h.label(i) = uicontrol(hFig, ...
        'Style', 'Text', ...
        'HorizontalAlignment', 'Left', ...
        'String', getString(message('signal:sigtools:siggui:Test')), ...
        'Tag', ['varsinheader_lbl' num]);

    h.varedit(i) = uicontrol(hFig, ...
        'Style', 'Edit', ...
        'HorizontalAlignment', 'Left', ...
        'String', getString(message('signal:sigtools:siggui:Test')), ...
        'UserData', i, ...  % Callback needs to know the index
        'Callback', {cbs.name, this}, ...
        'Tag', ['varsinheader_edit' num]);

    h.length(i) = uicontrol(hFig, ...
        'Style', 'Text', ...
        'Tag', ['varsinheader_lengthlbl' num], ...
        'HorizontalAlignment', 'Left', ...
        'String', getString(message('signal:sigtools:siggui:Test')));

    h.lengthedit(i) = uicontrol(hFig, ...
        'Style', 'Edit', ...
        'Tag', ['varsinheader_length' num], ...
        'UserData', i, ...
        'HorizontalAlignment', 'Left', ...
        'String', getString(message('signal:sigtools:siggui:Test')), ...
        'Callback', {cbs.length, this});

    hLayout.add(h.label(i), i, 1, ...
        'MinimumHeight', sz.uh-sz.lblTweak, ...
        'TopInset',      ti, ...
        'LeftInset',     5*sz.pixf, ...
        'Anchor',        'NorthWest');

    hLayout.add(h.varedit(i), i, 2, ...
        'MinimumHeight', sz.uh, ...
        'MinimumWidth',  0, ...
        'TopInset',      ti, ...
        'Fill',          'Horizontal', ...
        'Anchor',        'NorthWest');

    hLayout.add(h.length(i), i, 3, ...
        'MinimumHeight', sz.uh-sz.lblTweak, ...
        'TopInset',      ti, ...
        'LeftInset',     5*sz.pixf, ...
        'Anchor',        'NorthWest');

    hLayout.add(h.lengthedit(i), i, 4, ...
        'MinimumHeight', sz.uh, ...
        'MinimumWidth',  0, ...
        'TopInset',      ti, ...
        'RightInset',    5*sz.pixf, ...
        'Anchor',        'NorthWest', ...
        'Fill',          'Horizontal');
end

set(this, 'Handles', h, 'Parent', hFig, 'Container', hPanel, 'Layout', hLayout);

% Sync the GUI with the settings
enable_listener(this);
update_editboxes(this);

listen = [ ...
    handle.listener(this, this.findprop('CurrentStructure'), ...
    'PropertyPostSet', @currentstructure_listener); ...
    handle.listener(this, this.findprop('VariableNames'), ...
    'PropertyPostSet', @variablenames_listener); ...
    ];

set(listen, 'CallbackTarget', this);

set(this, 'WhenRenderedListeners', listen);

% [EOF]
