def stack_layout(container, components, align):
    """ Helper method that does the actual work of layout.
    """
    size = list(container.bounds)
    if container.fit_components != '':
        container.get_preferred_size()
        if 'h' in container.fit_components:
            size[0] = container._cached_preferred_size[0] - container.hpadding
        if 'v' in container.fit_components:
            size[1] = container._cached_preferred_size[1] - container.vpadding
    ndx = container.stack_index
    other_ndx = 1 - ndx
    other_dim = container.other_dimension
    total_fixed_size = 0
    resizable_components = []
    size_prefs = {}
    total_resizable_size = 0
    for component in components:
        if not container._should_layout(component):
            continue
        if container.stack_dimension not in component.resizable:
            total_fixed_size += component.outer_bounds[ndx]
        else:
            preferred_size = component.get_preferred_size()
            size_prefs[component] = preferred_size
            total_resizable_size += preferred_size[ndx]
            resizable_components.append(component)
    new_bounds_dict = {}
    if resizable_components:
        space = container.spacing * (len(container.components) - 1)
        avail_size = size[ndx] - total_fixed_size - space
        if total_resizable_size > 0:
            scale = avail_size / float(total_resizable_size)
            for component in resizable_components:
                tmp = list(component.outer_bounds)
                tmp[ndx] = int(size_prefs[component][ndx] * scale)
                new_bounds_dict[component] = tmp
        else:
            each_size = int(avail_size / len(resizable_components))
            for component in resizable_components:
                tmp = list(component.outer_bounds)
                tmp[ndx] = each_size
                new_bounds_dict[component] = tmp
    cur_pos = 0
    for component in components:
        if not container._should_layout(component):
            continue
        position = list(component.outer_position)
        position[ndx] = cur_pos
        bounds = new_bounds_dict.get(component, list(component.outer_bounds))
        cur_pos += bounds[ndx] + container.spacing
        if bounds[other_ndx] > size[other_ndx
            ] or other_dim in component.resizable:
            position[other_ndx] = 0
            bounds[other_ndx] = size[other_ndx]
        else:
            position[other_ndx] = 0
            if align == 'min':
                pass
            elif align == 'max':
                position[other_ndx] = size[other_ndx] - bounds[other_ndx]
            elif align == 'center':
                position[other_ndx] = (size[other_ndx] - bounds[other_ndx]
                    ) / 2.0
        component.outer_position = position
        component.outer_bounds = bounds
        component.do_layout()
    return
