本文整理汇总了C++中BButton::StringWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ BButton::StringWidth方法的具体用法?C++ BButton::StringWidth怎么用?C++ BButton::StringWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BButton
的用法示例。
在下文中一共展示了BButton::StringWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
TFilePanel::SetButtonLabel(file_panel_button selector, const char* text)
{
switch (selector) {
case B_CANCEL_BUTTON:
{
BButton* button
= dynamic_cast<BButton*>(FindView("cancel button"));
if (button == NULL)
break;
float old_width = button->StringWidth(button->Label());
button->SetLabel(text);
float delta = old_width - button->StringWidth(text);
if (delta) {
button->MoveBy(delta, 0);
button->ResizeBy(-delta, 0);
}
}
break;
case B_DEFAULT_BUTTON:
{
fButtonText = text;
float delta = 0;
BButton* button
= dynamic_cast<BButton*>(FindView("default button"));
if (button != NULL) {
float old_width = button->StringWidth(button->Label());
button->SetLabel(text);
delta = old_width - button->StringWidth(text);
if (delta) {
button->MoveBy(delta, 0);
button->ResizeBy(-delta, 0);
}
}
// now must move cancel button
button = dynamic_cast<BButton*>(FindView("cancel button"));
if (button != NULL)
button->MoveBy(delta, 0);
}
break;
}
}
示例2: BMessage
BButton*
ScreenWindow::_CreateColumnRowButton(bool columns, bool plus)
{
BMessage* message = new BMessage(kMsgWorkspaceLayoutChanged);
message->AddInt32("delta_x", columns ? (plus ? 1 : -1) : 0);
message->AddInt32("delta_y", !columns ? (plus ? 1 : -1) : 0);
BButton* button = new BButton(plus ? "+" : "-", message);
button->SetFontSize(be_plain_font->Size() * 0.9);
BSize size = button->MinSize();
size.width = button->StringWidth("+") + 16;
button->SetExplicitMinSize(size);
button->SetExplicitMaxSize(size);
fWorkspacesButtons[(columns ? 0 : 2) + (plus ? 1 : 0)] = button;
return button;
}
示例3: BMessage
FileTypesWindow::FileTypesWindow(const BMessage& settings)
: BWindow(_Frame(settings), "FileTypes", B_TITLED_WINDOW,
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
fNewTypeWindow(NULL)
{
bool showIcons;
bool showRule;
if (settings.FindBool("show_icons", &showIcons) != B_OK)
showIcons = true;
if (settings.FindBool("show_rule", &showRule) != B_OK)
showRule = false;
// add the menu
BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
AddChild(menuBar);
BMenu* menu = new BMenu("File");
BMenuItem* item;
menu->AddItem(item = new BMenuItem("New resource file" B_UTF8_ELLIPSIS,
NULL, 'N', B_COMMAND_KEY));
item->SetEnabled(false);
BMenu* recentsMenu = BRecentFilesList::NewFileListMenu("Open" B_UTF8_ELLIPSIS,
NULL, NULL, be_app, 10, false, NULL, kSignature);
item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel));
item->SetShortcut('O', B_COMMAND_KEY);
menu->AddItem(item);
menu->AddItem(new BMenuItem("Application types" B_UTF8_ELLIPSIS,
new BMessage(kMsgOpenApplicationTypesWindow)));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("About FileTypes" B_UTF8_ELLIPSIS,
new BMessage(B_ABOUT_REQUESTED)));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
'Q', B_COMMAND_KEY));
menu->SetTargetForItems(be_app);
menuBar->AddItem(menu);
menu = new BMenu("Settings");
item = new BMenuItem("Show icons in list", new BMessage(kMsgToggleIcons));
item->SetMarked(showIcons);
item->SetTarget(this);
menu->AddItem(item);
item = new BMenuItem("Show recognition rule", new BMessage(kMsgToggleRule));
item->SetMarked(showRule);
item->SetTarget(this);
menu->AddItem(item);
menuBar->AddItem(menu);
// MIME Types list
BRect rect = Bounds();
rect.top = menuBar->Bounds().Height() + 1.0f;
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(topView);
BButton* button = new BButton(rect, "add", "Add" B_UTF8_ELLIPSIS,
new BMessage(kMsgAddType), B_FOLLOW_BOTTOM);
button->ResizeToPreferred();
button->MoveTo(8.0f, topView->Bounds().bottom - 8.0f - button->Bounds().Height());
topView->AddChild(button);
rect = button->Frame();
rect.OffsetBy(rect.Width() + 8.0f, 0.0f);
fRemoveTypeButton = new BButton(rect, "remove", "Remove",
new BMessage(kMsgRemoveType), B_FOLLOW_BOTTOM);
fRemoveTypeButton->ResizeToPreferred();
topView->AddChild(fRemoveTypeButton);
rect.bottom = rect.top - 10.0f;
rect.top = 10.0f;
rect.left = 10.0f;
rect.right -= B_V_SCROLL_BAR_WIDTH + 2.0f;
if (rect.right < 180)
rect.right = 180;
fTypeListView = new MimeTypeListView(rect, "typeview", NULL, showIcons, false,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));
BScrollView* scrollView = new BScrollView("scrollview", fTypeListView,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
topView->AddChild(scrollView);
// "Icon" group
font_height plainHeight;
be_plain_font->GetHeight(&plainHeight);
float height = ceilf(plainHeight.ascent + plainHeight.descent
+ plainHeight.leading) + 2.0f;
BFont font(be_bold_font);
float labelWidth = font.StringWidth("Icon");
font_height boldHeight;
font.GetHeight(&boldHeight);
//.........这里部分代码省略.........