コード例 #1
0
Point Box::PreferredSize()
{
	if (m_children.size() == 0) return Point();

	Point::Component vc, fc;
	GetComponentsForOrient(m_orient == BOX_HORIZONTAL, vc, fc);

	m_preferredSize = Point(0);
	m_minAllocation = 0;
	m_numVariable = 0;

	for (std::list<Child>::iterator i = m_children.begin(); i != m_children.end(); ++i) {
		const Point contribSize = (*i).contribSize = CalcLayoutContribution((*i).widget);

		// they've asked for as much as possible
		if (contribSize[vc] == SIZE_EXPAND) {
			// we'll need to be as big as possible too
			m_preferredSize[vc] = SIZE_EXPAND;

			// count them for later
			m_numVariable++;
		}

		// they asked for a known amount
		else {

			// if we still know our size then we can increase it sanely
			if (m_preferredSize[vc] != SIZE_EXPAND)
				// need a bit more
			    m_preferredSize[vc] += contribSize[vc];

			// track minimum known size so we can avoid recounting in Layout()
			m_minAllocation += contribSize[vc];
		}

		// fixed axis should just be as large as our largest
		m_preferredSize[fc] = std::max(m_preferredSize[fc], contribSize[fc]);
	}

	// if there was no variable ones, and thus we're asking for a specific
	// amount of space, add sufficient padding
	if (m_numVariable == 0)
		m_preferredSize[vc] += m_spacing*m_children.size();

	return m_preferredSize;
}
コード例 #2
0
ファイル: Expand.cpp プロジェクト: HeadHunterEG/pioneer
Point Expand::PreferredSize()
{
	const Point innerPreferredSize(GetInnerWidget() ? CalcLayoutContribution(GetInnerWidget()) : Point());

	switch (m_direction) {
		case BOTH:
			SetSizeControlFlags(EXPAND_WIDTH | EXPAND_HEIGHT);
			break;
		case HORIZONTAL:
			SetSizeControlFlags(EXPAND_WIDTH);
			break;
		case VERTICAL:
			SetSizeControlFlags(EXPAND_HEIGHT);
			break;
	}

	return innerPreferredSize;
}
コード例 #3
0
ファイル: Grid.cpp プロジェクト: HeadHunterEG/pioneer
Point Grid::PreferredSize()
{
	Point preferredSize;

	for (unsigned int rowNum = 0; rowNum < m_numRows; rowNum++) {
		Point rowSize;

		for (unsigned int colNum = 0; colNum < m_numCols; colNum++) {
			const unsigned int n = rowNum*m_numCols+colNum;
			Widget *w = m_widgets[n];
			if (!w) continue;

			const Point childPreferredSize = CalcLayoutContribution(w);
			rowSize.x = SizeAdd(childPreferredSize.x, rowSize.x);
			rowSize.y = std::max(childPreferredSize.y, rowSize.y);
		}

		preferredSize.x = std::max(preferredSize.x, rowSize.x);
		preferredSize.y = SizeAdd(preferredSize.y, rowSize.y);
	}

	return preferredSize;
}