KeyMap: Redo modifier keys layout

... by using a group layout inside of a grid layout we can get this
to layout how we want it without having to calculate the label
widths manually.
This commit is contained in:
John Scipione
2014-03-21 17:26:28 -04:00
parent 8512f7b056
commit fd3fa9178b
+17 -48
View File
@@ -289,66 +289,35 @@ ModifierKeysWindow::ModifierKeysWindow()
new BMessage(kMsgApplyModifiers)); new BMessage(kMsgApplyModifiers));
fOkButton->MakeDefault(true); fOkButton->MakeDefault(true);
// Build the layout BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_SMALL_SPACING)
SetLayout(new BGroupLayout(B_VERTICAL)); .AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
.Add(keyRole, 0, 0)
.Add(keyLabel, 1, 0)
// find the minimum width to fit the labels .Add(shiftMenuField->CreateLabelLayoutItem(), 0, 1)
float shiftLabelWidth .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 1)
= shiftMenuField->StringWidth(shiftMenuField->Label());
float controlLabelWidth
= controlMenuField->StringWidth(controlMenuField->Label());
float optionLabelWidth
= optionMenuField->StringWidth(optionMenuField->Label());
float commandLabelWidth
= commandMenuField->StringWidth(commandMenuField->Label());
float forcedMinWidth = shiftLabelWidth;
if (controlLabelWidth > forcedMinWidth)
forcedMinWidth = controlLabelWidth;
if (optionLabelWidth > forcedMinWidth)
forcedMinWidth = optionLabelWidth;
if (commandLabelWidth > forcedMinWidth)
forcedMinWidth = commandLabelWidth;
forcedMinWidth += be_plain_font->StringWidth("XXX");
keyRole->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
BLayoutItem* shiftLabel = shiftMenuField->CreateLabelLayoutItem();
shiftLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
BLayoutItem* controlLabel = controlMenuField->CreateLabelLayoutItem();
controlLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
BLayoutItem* optionLabel = optionMenuField->CreateLabelLayoutItem();
optionLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
BLayoutItem* commandLabel = commandMenuField->CreateLabelLayoutItem();
commandLabel->SetExplicitMinSize(BSize(forcedMinWidth, B_SIZE_UNSET));
AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_SMALL_SPACING)
.AddGroup(B_HORIZONTAL)
.Add(keyRole)
.Add(keyLabel)
.End()
.AddGroup(B_HORIZONTAL)
.Add(shiftLabel)
.Add(shiftMenuField->CreateMenuBarLayoutItem()) .Add(shiftMenuField->CreateMenuBarLayoutItem())
.Add(fShiftConflictView) .Add(fShiftConflictView)
.End() .End()
.AddGroup(B_HORIZONTAL)
.Add(controlLabel) .Add(controlMenuField->CreateLabelLayoutItem(), 0, 2)
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 2)
.Add(controlMenuField->CreateMenuBarLayoutItem()) .Add(controlMenuField->CreateMenuBarLayoutItem())
.Add(fControlConflictView) .Add(fControlConflictView)
.End() .End()
.AddGroup(B_HORIZONTAL)
.Add(optionLabel) .Add(optionMenuField->CreateLabelLayoutItem(), 0, 3)
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 3)
.Add(optionMenuField->CreateMenuBarLayoutItem()) .Add(optionMenuField->CreateMenuBarLayoutItem())
.Add(fOptionConflictView) .Add(fOptionConflictView)
.End() .End()
.AddGroup(B_HORIZONTAL)
.Add(commandLabel) .Add(commandMenuField->CreateLabelLayoutItem(), 0, 4)
.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 4)
.Add(commandMenuField->CreateMenuBarLayoutItem()) .Add(commandMenuField->CreateMenuBarLayoutItem())
.Add(fCommandConflictView) .Add(fCommandConflictView)
.End() .End()
.End()
.AddGlue() .AddGlue()
.AddGroup(B_HORIZONTAL) .AddGroup(B_HORIZONTAL)
.Add(fCancelButton) .Add(fCancelButton)
@@ -357,7 +326,7 @@ ModifierKeysWindow::ModifierKeysWindow()
.Add(fOkButton) .Add(fOkButton)
.End() .End()
.SetInsets(B_USE_DEFAULT_SPACING) .SetInsets(B_USE_DEFAULT_SPACING)
); .End();
_MarkMenuItems(); _MarkMenuItems();
_ValidateDuplicateKeys(); _ValidateDuplicateKeys();