Beispiel #1
0
PreferredSize TBEditField::OnCalculatePreferredContentSize(const SizeConstraints &constraints)
{
	int font_height = GetFont()->GetHeight();
	PreferredSize ps;
	if (m_adapt_to_content_size)
	{
		int old_layout_width = m_style_edit.layout_width;
		int old_layout_height = m_style_edit.layout_height;
		if (m_style_edit.packed.wrapping)
		{
			// If we have wrapping enabled, we have to set a virtual width and format the text
			// so we can get the actual content width with a constant result every time.
			// If the layouter does not respect our size constraints in the end, we may
			// get a completly different content height due to different wrapping.
			// To fix that, we need to layout in 2 passes.

			// A hacky fix is to do something we probably shouldn't: use the old layout width
			// as virtual width for the new.
			//int layout_width = old_layout_width > 0 ? MAX(old_layout_width, m_virtual_width) : m_virtual_width;
			int layout_width = m_virtual_width;
			if (constraints.available_w != SizeConstraints::NO_RESTRICTION)
			{
				layout_width = constraints.available_w;
				if (TBSkinElement *bg_skin = GetSkinBgElement())
					layout_width -= bg_skin->padding_left + bg_skin->padding_right;
			}

			m_style_edit.SetLayoutSize(layout_width, old_layout_height, true);
			ps.size_dependency = SIZE_DEP_HEIGHT_DEPEND_ON_WIDTH;
		}
		int width = m_style_edit.GetContentWidth();
		int height = m_style_edit.GetContentHeight();
		if (m_style_edit.packed.wrapping)
			m_style_edit.SetLayoutSize(old_layout_width, old_layout_height, true);
		height = MAX(height, font_height);

		ps.min_w = ps.pref_w /*= ps.max_w*/ = width; // should go with the hack above.
		//ps.min_w = ps.pref_w = ps.max_w = width;
		ps.min_h = ps.pref_h = ps.max_h = height;
	}
	else
	{
		ps.pref_h = ps.min_h = font_height;
		if (m_style_edit.packed.multiline_on)
		{
			ps.pref_w = font_height * 10;
			ps.pref_h = font_height * 5;
		}
		else
			ps.max_h = ps.pref_h;
	}
	return ps;
}
Beispiel #2
0
int TBLayout::CalculateSpacing()
{
	// Get spacing from skin, if not specified
	int spacing = m_spacing;
	if (spacing == SPACING_FROM_SKIN)
	{
		if (TBSkinElement *e = GetSkinBgElement())
			spacing = e->spacing;

		assert(SPACING_FROM_SKIN == SKIN_VALUE_NOT_SPECIFIED);
		if (spacing == SPACING_FROM_SKIN /*|| spacing == SKIN_VALUE_NOT_SPECIFIED*/)
			spacing = g_tb_skin->GetDefaultSpacing();
	}
	return spacing;
}
Beispiel #3
0
PreferredSize TBWindow::OnCalculatePreferredSize(const SizeConstraints &constraints)
{
	PreferredSize ps = OnCalculatePreferredContentSize(constraints);

	// Add window skin padding
	if (TBSkinElement *e = GetSkinBgElement())
	{
		ps.min_w += e->padding_left + e->padding_right;
		ps.pref_w += e->padding_left + e->padding_right;
		ps.min_h += e->padding_top + e->padding_bottom;
		ps.pref_h += e->padding_top + e->padding_bottom;
	}
	// Add window title bar height
	int title_height = GetTitleHeight();
	ps.min_h += title_height;
	ps.pref_h += title_height;
	return ps;
}