当前位置: 首页>>代码示例>>C++>>正文


C++ StringWidth函数代码示例

本文整理汇总了C++中StringWidth函数的典型用法代码示例。如果您正苦于以下问题:C++ StringWidth函数的具体用法?C++ StringWidth怎么用?C++ StringWidth使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了StringWidth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetMenuSize

void GetMenuSize(XlibMenu * menu)
{
    int i = 0;
    int winheight = 0;
    int fontheight = 0;
    int menuwidth = 0;
    FcitxSkin *sc = &menu->owner->skin;
    int dpi = sc->skinFont.respectDPI? menu->owner->dpi: 0;
    FCITX_UNUSED(dpi);

    winheight = sc->skinMenu.marginTop + sc->skinMenu.marginBottom;//菜单头和尾都空8个pixel
    fontheight = FontHeight(menu->owner->menuFont, sc->skinFont.menuFontSize, dpi);
    for (i = 0; i < utarray_len(&menu->menushell->shell); i++) {
        if (GetMenuItem(menu->menushell, i)->type == MENUTYPE_SIMPLE || GetMenuItem(menu->menushell, i)->type == MENUTYPE_SUBMENU)
            winheight += 6 + fontheight;
        else if (GetMenuItem(menu->menushell, i)->type == MENUTYPE_DIVLINE)
            winheight += 5;

        int width = StringWidth(GetMenuItem(menu->menushell, i)->tipstr, menu->owner->menuFont, sc->skinFont.menuFontSize, dpi);
        if (width > menuwidth)
            menuwidth = width;
    }
    menu->height = winheight;
    menu->width = menuwidth + sc->skinMenu.marginLeft + sc->skinMenu.marginRight + 15 + 20;
}
开发者ID:adaptee,项目名称:fcitx,代码行数:25,代码来源:MenuWindow.c

示例2: BView

BFileControl::BFileControl(BRect rect, const char* name, const char* label,
	const char *pathOfFile,uint32 flavors)
	:
	BView(rect, name, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0)
{
	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	// determine font height
	font_height fontHeight;
	GetFontHeight(&fontHeight);
	float itemHeight = (int32)(fontHeight.ascent + fontHeight.descent
		+ fontHeight.leading) + 13;
	BString selectString = B_TRANSLATE("Select" B_UTF8_ELLIPSIS);
	float labelWidth = StringWidth(selectString) + 20;
	rect = Bounds();
	rect.right -= labelWidth;
	rect.top = 4;
	rect.bottom = itemHeight + 2;
	fText = new BTextControl(rect,"file_path", label, pathOfFile, NULL);
	if (label)
		fText->SetDivider(fText->StringWidth(label) + 6);
	AddChild(fText);

	fButton = new BButton(BRect(0, 0, 1, 1), "select_file", selectString,
		new BMessage(kMsgSelectButton));
	fButton->ResizeToPreferred();
	fButton->MoveBy(rect.right + 6,
		(rect.Height() - fButton->Frame().Height()) / 2);
	AddChild(fButton);

	fPanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL, flavors, false);

	ResizeToPreferred();
}
开发者ID:veer77,项目名称:Haiku-services-branch,代码行数:34,代码来源:FileConfigView.cpp

示例3: GetTabName

void YabTabView::DrawLabel(int32 current, BRect frame)
{
    BString label = GetTabName(current);
	if (label == NULL)
		return;

	float frameWidth = frame.Width();
	float width = StringWidth(label.String());
	font_height fh;

	if (width > frameWidth) {
		BFont font;
		GetFont(&font);
		font.TruncateString(&label, B_TRUNCATE_END, frameWidth);
		width = frameWidth;
		font.GetHeight(&fh);
	} else {
		GetFontHeight(&fh);
	}

	SetDrawingMode(B_OP_OVER);
	SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
	DrawString(label.String(),
		BPoint((frame.left + frame.right - width) / 2.0,
 			(frame.top + frame.bottom - fh.ascent - fh.descent) / 2.0
 			+ fh.ascent));
}
开发者ID:HaikuArchives,项目名称:Yab,代码行数:27,代码来源:YabTabView.cpp

示例4: BView

EventPrefsView::EventPrefsView(BRect frame)
	: BView(frame, "Event prefs", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS)
{
	AdoptSystemColors();
	BRect bounds(Bounds());
	bounds.left += 3;
	bounds.right -= B_V_SCROLL_BAR_WIDTH + 3;
	bounds.top += 3;
	bounds.bottom -= 5;
	int32 i(0);

	float label_width(0.0);

	for (i = 0; EventControlLabels[i]; ++i)
		if (StringWidth(EventControlLabels[i]) > label_width)
			label_width = StringWidth(EventControlLabels[i]);

	BView* bgView(new BView(bounds, "", B_FOLLOW_ALL_SIDES, B_WILL_DRAW));
	bgView->AdoptSystemColors();
	fEvents = new VTextControl* [MAX_EVENTS];

	for (i = 0; i < MAX_EVENTS; ++i) {
		fEvents[i] = new VTextControl(
			BRect(5, be_plain_font->Size() + ((1.5 * i) * 1.5 * be_plain_font->Size()),
				  5 + bounds.right - be_plain_font->StringWidth("gP"),
				  be_plain_font->Size() + (1.5 * (i + 1) * 1.5 * be_plain_font->Size())),
			"commands", EventControlLabels[i], vision_app->GetEvent(i).String(), NULL,
			B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);

		fEvents[i]->SetDivider(label_width + 5);

		BMessage* msg(new BMessage(M_EVENT_MODIFIED));

		msg->AddInt32("which", i);
		fEvents[i]->SetModificationMessage(msg);
		bgView->AddChild(fEvents[i]);
	}
	fScroller = new BScrollView("command fScroller", bgView, B_FOLLOW_ALL_SIDES, 0, false, true);
	BScrollBar* bar(fScroller->ScrollBar(B_VERTICAL));

	fMaxheight = bgView->Bounds().Height();
	fProportionheight = fEvents[MAX_EVENTS - 1]->Frame().bottom + 10.0;
	bar->SetRange(0.0, (fProportionheight - fScroller->Bounds().Height()));
	bar->SetProportion(fScroller->Bounds().Height() / fProportionheight);

	AddChild(fScroller);
}
开发者ID:HaikuArchives,项目名称:Vision,代码行数:47,代码来源:PrefEvent.cpp

示例5: inherited

/*******************************************************
 * ARP-FONT-CONTROL
 *******************************************************/
ArpFontControl::ArpFontControl(	BRect frame,
								const char* name,
								const BString16* label,
								uint32 message,
								float divider)
		: inherited(frame, name, 0, new BMessage(message),
					B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW),
		  mFontCtrl(0), mSizeCtrl(0), mMsgWhat(message)
{
	if (label) {
		if (divider <= 0) divider = StringWidth(label);
		BRect			f(0, 0, divider, frame.Height());
		BStringView*	sv = new BStringView(f, "sv", label);
		if (sv) AddChild(sv);
	}

	float				sizeW = StringWidth("000") + 5;
	float				sizeL = frame.Width() - sizeW;
	BRect				f(divider + 1, 0, sizeL - 1, frame.Height());
	mFontCtrl = new BMenuField(f, "fonts", 0, new BMenu("font"), true,
								B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	if (!mFontCtrl) return;

	mFontCtrl->SetDivider(0);
	BMenu*		m = mFontCtrl->Menu();
	if (m) {
		m->SetLabelFromMarked(true);
		_ArpFontControlFamilies		families(m);
		families.ForEach();
	}
	AddChild(mFontCtrl);

	float		iH = float(Prefs().GetInt32(ARP_INTCTRL_Y));
	float		iT = 0, iB = frame.Height();
	if (iH < frame.Height()) {
		iT = (frame.Height() - iH) / 2;
		iB = iT + iH;
	}
	f.Set(sizeL, iT, sizeL + sizeW, iB);
	mSizeCtrl = new ArpIntControl(	f, "size", 0, new BMessage(SIZE_IMSG),
									B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	if (mSizeCtrl) {
		mSizeCtrl->SetLimits(1, 512);
		AddChild(mSizeCtrl);
	}

}
开发者ID:HaikuArchives,项目名称:Sequitur,代码行数:50,代码来源:ArpFontControl.cpp

示例6: IsDefault

BSize
BButton::_ValidatePreferredSize()
{
	if (fPreferredSize.width < 0) {
		BControlLook::background_type backgroundType
			= fBehavior == B_POP_UP_BEHAVIOR
				? BControlLook::B_BUTTON_WITH_POP_UP_BACKGROUND
				: BControlLook::B_BUTTON_BACKGROUND;
		float left, top, right, bottom;
		be_control_look->GetInsets(BControlLook::B_BUTTON_FRAME, backgroundType,
			IsDefault() ? BControlLook::B_DEFAULT_BUTTON : 0,
			left, top, right, bottom);

		// width
		float width = left + right + 2 * kLabelMargin - 1;

		const char* label = Label();
		if (label != NULL) {
			width = std::max(width, 20.0f);
			width += (float)ceil(StringWidth(label));
		}

		const BBitmap* icon = IconBitmap(B_INACTIVE_ICON_BITMAP);
		if (icon != NULL)
			width += icon->Bounds().Width() + 1;

		if (label != NULL && icon != NULL)
			width += be_control_look->DefaultLabelSpacing();

		// height
		float minHorizontalMargins = top + bottom + 2 * kLabelMargin;
		float height = -1;

		if (label != NULL) {
			font_height fontHeight;
			GetFontHeight(&fontHeight);
			float textHeight = fontHeight.ascent + fontHeight.descent;
			height = ceilf(textHeight * 1.8);
			float margins = height - ceilf(textHeight);
			if (margins < minHorizontalMargins)
				height += minHorizontalMargins - margins;
		}

		if (icon != NULL) {
			height = std::max(height,
				icon->Bounds().Height() + minHorizontalMargins);
		}

		// force some minimum width/height values
		width = std::max(width, label != NULL ? 75.0f : 5.0f);
		height = std::max(height, 5.0f);

		fPreferredSize.Set(width, height);

		ResetLayoutInvalidation();
	}

	return fPreferredSize;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:59,代码来源:Button.cpp

示例7: ceilf

// PreferredLabelWidth
float
PropertyItemView::PreferredLabelWidth() const
{
	float width = 0.0;
	if (const Property* property = GetProperty())
		width = ceilf(StringWidth(name_for_id(property->Identifier())) + 10.0);
	return width;
}
开发者ID:mariuz,项目名称:haiku,代码行数:9,代码来源:PropertyItemView.cpp

示例8: BView

IPCPView::IPCPView(IPCPAddon *addon, BRect frame)
	: BView(frame, kLabelIPCP, B_FOLLOW_NONE, 0),
	fAddon(addon)
{
	BRect rect = Bounds();
	rect.InsetBy(10, 10);
	rect.bottom = rect.top + 20;
	BRect optionalRect(rect);
	rect.right -= 75;
	fIPAddress = new BTextControl(rect, "ip", kLabelIPAddress, NULL, NULL);
	optionalRect.left = rect.right + 5;
	optionalRect.bottom = optionalRect.top + 15;
	AddChild(new BStringView(optionalRect, "optional_1", kLabelOptional));
	rect.top = rect.bottom + 5;
	rect.bottom = rect.top + 20;
	fPrimaryDNS = new BTextControl(rect, "primaryDNS", kLabelPrimaryDNS, NULL, NULL);
	optionalRect.top = rect.top;
	optionalRect.bottom = optionalRect.top + 15;
	AddChild(new BStringView(optionalRect, "optional_2", kLabelOptional));
	rect.top = rect.bottom + 5;
	rect.bottom = rect.top + 20;
	fSecondaryDNS = new BTextControl(rect, "secondaryDNS", kLabelSecondaryDNS, NULL,
		NULL);
	optionalRect.top = rect.top;
	optionalRect.bottom = optionalRect.top + 15;
	AddChild(new BStringView(optionalRect, "optional_3", kLabelOptional));
	rect.top = rect.bottom + 50;
	rect.bottom = rect.top + 10;
	AddChild(new BStringView(rect, "expert", kLabelExtendedOptions));
	rect.top = rect.bottom + 5;
	rect.bottom = rect.top + 15;
	fIsEnabled = new BCheckBox(rect, "isEnabled", kLabelEnabled,
		new BMessage(kMsgUpdateControls));
	
	// set divider of text controls
	float controlWidth = max(max(StringWidth(fIPAddress->Label()),
		StringWidth(fPrimaryDNS->Label())), StringWidth(fSecondaryDNS->Label()));
	fIPAddress->SetDivider(controlWidth + 5);
	fPrimaryDNS->SetDivider(controlWidth + 5);
	fSecondaryDNS->SetDivider(controlWidth + 5);
	
	AddChild(fIsEnabled);
	AddChild(fIPAddress);
	AddChild(fPrimaryDNS);
	AddChild(fSecondaryDNS);
}
开发者ID:mariuz,项目名称:haiku,代码行数:46,代码来源:IPCPAddon.cpp

示例9: Looper

void VideoDVDPanel::AllAttached() {
    mi->SetTarget(this, Looper());
    filesystemMF->SetDivider(StringWidth(_T("Volume name"))+30); // "TVOLUMENAME"
    filesystemMF->MoveTo(5,2);
    filesystemMF->ResizeTo(200, 22);
    volumenameTC->MoveTo(5,28);
    volumenameTC->ResizeTo(200, 20);
}
开发者ID:carriercomm,项目名称:Helios,代码行数:8,代码来源:VideoDVDPanel.cpp

示例10: SetDivider

void
TNameControl::AttachedToWindow()
{
	BTextControl::AttachedToWindow();

	SetDivider(StringWidth(fLabel) + 6);
	TextView()->SetMaxBytes(B_FILE_NAME_LENGTH - 1);
}
开发者ID:HaikuArchives,项目名称:BeMailDaemon,代码行数:8,代码来源:Signature.cpp

示例11: GetFontHeight

void AmTimeView::AddViews()
{
	font_height		fheight;
	GetFontHeight( &fheight );
	// Add the measure control
	float	left = 0, top = 0;
	float	width = StringWidth("0000") + 5;
	float	height = fheight.ascent + fheight.descent + fheight.leading + 1;
	BRect	f(left, top, left + width, top + height);
	if( (mMeasureCtrl = new ArpIntControl(f, "measure", 0, 0)) != 0 ) {
		mMeasureCtrl->SetLimits(1, 9999);
		mMeasureCtrl->StartWatching(this, ARPMSG_INT_CONTROL_CHANGED);
		mMeasureCtrl->SetMotion( new ArpIntControlSmallMotion() );
		AddChild(mMeasureCtrl);
	}
	// Add a ":"
	left += width;
	float	dotW = StringWidth(":") + 2;
	BStringView	*sv = new BStringView(	BRect(left, top, left + dotW, top + height - 2),
										"dot", ":");
	if( sv ) AddChild(sv);
	// Add the beat control
	left += dotW;
	width = StringWidth("00") + 5;
	f.Set(left, top, left + width, top + height);
	if( (mBeatCtrl = new ArpIntControl(f, "beat", 0, 0)) != 0 ) {
		mBeatCtrl->StartWatching(this, ARPMSG_INT_CONTROL_CHANGED);
		AddChild(mBeatCtrl);
	}
	// Add a ":"
	left += width;
	sv = new BStringView(	BRect(left, top, left + dotW, top + height - 2),
							"dot", ":");
	if( sv ) AddChild(sv);
	// Add the clock control
	left += dotW;
	width = StringWidth("0000") + 5;
	f.Set(left, top, left + width, top + height);
	if ( (mClockCtrl = new ArpIntControl(f, "clock", 0, 0)) != 0 ) {
		mClockCtrl->SetLimits(0, PPQN - 1);
		mClockCtrl->StartWatching(this, ARPMSG_INT_CONTROL_CHANGED);
		AddChild(mClockCtrl);
	}
	ResizeTo(left + width, top + height);	
}
开发者ID:HaikuArchives,项目名称:Sequitur,代码行数:45,代码来源:AmEventControls.cpp

示例12: SetViewColor

void
Spinner::_InitObject(void)
{
	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	BRect r(Bounds());
	if (r.Height() < B_H_SCROLL_BAR_HEIGHT * 2)
		r.bottom = r.top + 1 + B_H_SCROLL_BAR_HEIGHT * 2;
	ResizeTo(r.Width(),r.Height());
	
	r.right -= B_V_SCROLL_BAR_WIDTH;
	
	font_height fh;
	BFont font;
	font.GetHeight(&fh);
	float textheight = fh.ascent + fh.descent + fh.leading;
	
	r.top = 0;
	r.bottom = textheight;
	
	fTextControl = new BTextControl(r,"textcontrol",Label(),"0",
									new BMessage(M_TEXT_CHANGED), B_FOLLOW_TOP | 
									B_FOLLOW_LEFT_RIGHT,
									B_WILL_DRAW | B_NAVIGABLE);
	AddChild(fTextControl);
	fTextControl->ResizeTo(r.Width(), MAX(textheight, fTextControl->TextView()->LineHeight(0) + 4.0));
	fTextControl->MoveTo(0,
		((B_H_SCROLL_BAR_HEIGHT * 2) - fTextControl->Bounds().Height()) / 2);
		
	fTextControl->SetDivider(StringWidth(Label()) + 5);
	
	BTextView *tview = fTextControl->TextView();
	tview->SetAlignment(B_ALIGN_LEFT);
	tview->SetWordWrap(false);
	
	BString string("QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,/qwertyuiop{}| "
		"asdfghjkl:\"zxcvbnm<>[email protected]#$%^&*()-_=+`~\r");
	
	for (int32 i = 0; i < string.CountChars(); i++) {
		char c = string.ByteAt(i);
		tview->DisallowChar(c);
	}
	
	r = Bounds();
	r.left = r.right - B_V_SCROLL_BAR_WIDTH;
	r.bottom = B_H_SCROLL_BAR_HEIGHT;
	
	fUpButton = new SpinnerArrowButton(r.LeftTop(),"up",ARROW_UP);
	AddChild(fUpButton);
	
	r.OffsetBy(0,r.Height() + 1);
	fDownButton = new SpinnerArrowButton(r.LeftTop(),"down",ARROW_DOWN);
	AddChild(fDownButton);
	
	
	fPrivateData = new SpinnerPrivateData;
	fFilter = new SpinnerMsgFilter;
}
开发者ID:Barrett17,项目名称:Faber,代码行数:57,代码来源:Spinner.cpp

示例13: StringWidth

BSize
PaneSwitch::MinSize()
{
	BSize size;
	float onLabelWidth = StringWidth(fLabelOn);
	float offLabelWidth = StringWidth(fLabelOff);
	float labelWidth = max_c(onLabelWidth, offLabelWidth);
	size.width = sLatchSize;
	if (labelWidth > 0.0)
		size.width += ceilf(sLatchSize / 2.0) + labelWidth;

	font_height fontHeight;
	GetFontHeight(&fontHeight);
	size.height = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent);
	size.height = max_c(size.height, sLatchSize);

	return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:18,代码来源:DialogPane.cpp

示例14: last

void StatusView::AddItem(StatusItem* item, bool erase)
{
	StatusItem* last((StatusItem*)items.LastItem());
	float width(3.0);

	if (last) width = last->frame.right + 8.0;

	if (item->label.Length()) width += StringWidth(item->label.String()) + 3;

	item->frame.top = 2.0;
	item->frame.bottom = Bounds().Height();
	item->frame.left = width;
	item->frame.right = width + StringWidth(item->value.String());

	if (erase) item->value = "";

	items.AddItem(item);
}
开发者ID:carriercomm,项目名称:Vision,代码行数:18,代码来源:StatusView.cpp

示例15: _UpdateFontDimens

void
BChannelSlider::Draw(BRect updateRect)
{
	_UpdateFontDimens();
	_DrawThumbs();

	BRect bounds(Bounds());
	if (Label()) {
		float labelWidth = StringWidth(Label());
		DrawString(Label(), BPoint((bounds.Width() - labelWidth) / 2.0,
			fBaseLine));
	}

	if (MinLimitLabel()) {
		if (fIsVertical) {
			if (MinLimitLabel()) {
				float x = (bounds.Width() - StringWidth(MinLimitLabel()))
					/ 2.0;
				DrawString(MinLimitLabel(), BPoint(x, bounds.bottom
					- kPadding));
			}
		} else {
			if (MinLimitLabel()) {
				DrawString(MinLimitLabel(), BPoint(kPadding, bounds.bottom
					- kPadding));
			}
		}
	}

	if (MaxLimitLabel()) {
		if (fIsVertical) {
			if (MaxLimitLabel()) {
				float x = (bounds.Width() - StringWidth(MaxLimitLabel()))
					/ 2.0;
				DrawString(MaxLimitLabel(), BPoint(x, 2 * fLineFeed));
			}
		} else {
			if (MaxLimitLabel()) {
				DrawString(MaxLimitLabel(), BPoint(bounds.right - kPadding
					- StringWidth(MaxLimitLabel()), bounds.bottom - kPadding));
			}
		}
	}
}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:44,代码来源:ChannelSlider.cpp


注:本文中的StringWidth函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。