void UpdateLayout()
{
RunButton.Frame = new CGRect(toolbarPadding, 0, runButtonWidth, ToolbarWidgetHeight);
var statusbarWidth = Math.Max(Math.Min(Frame.Width * 0.3, maxStatusBarWidth), minStatusBarWidth);
var searchbarWidth = maxSearchBarWidth;
if (statusbarWidth < searchbarWidth)
{
searchbarWidth = minSearchBarWidth;
}
// We only need to work out the width on the left side of the window because the statusbar is centred
// Gap + RunButton.Width + Gap + ButtonBar.Width + Gap + Half of StatusBar.Width
var spaceLeft = (Frame.Width / 2) - (toolbarPadding + runButtonWidth + toolbarPadding + ButtonBarContainer.Frame.Width + toolbarPadding + (statusbarWidth / 2));
StatusBar.Frame = new CGRect((Frame.Width - statusbarWidth) / 2, 0, statusbarWidth, ToolbarWidgetHeight);
SearchBar.Frame = new CGRect(Frame.Width - searchbarWidth - 10, 0, searchbarWidth, ToolbarWidgetHeight);
var selectorSize = SelectorView.SizeThatFits(new CGSize(spaceLeft, ToolbarWidgetHeight));
SelectorView.Frame = new CGRect(toolbarPadding + runButtonWidth + toolbarPadding, 0, selectorSize.Width, ToolbarWidgetHeight);
ButtonBarContainer.SetFrameOrigin(new CGPoint(SelectorView.Frame.GetMaxX() + toolbarPadding, 0));
// Finally check if the StatusBar overlaps the ButtonBarContainer (and its padding) and adjust is accordingly
if (StatusBar.Frame.IntersectsWith(ButtonBarContainer.Frame.Inset(-toolbarPadding, 0)))
{
StatusBar.SetFrameOrigin(new CGPoint(ButtonBarContainer.Frame.GetMaxX() + toolbarPadding, StatusBar.Frame.Y));
}
}