示例#1
0
文件: menu.cpp 项目: dodikk/iWesnoth
void menu::wrap_words()
{
	int total_width = max_width_ - (style_->get_cell_padding() + (2 * style_->get_thickness()));
	if(has_scrollbar()) {
		total_width -= scrollbar_width();
	}
	if(total_width <= 0) {
		return;
	}
	std::vector<int> const &widths = column_widths();
	for(std::vector<item>::iterator i = items_.begin(); i != items_.end(); ++i) {
		int space_remaining = total_width;
		for(size_t col = 0; col < i->fields.size() && col < widths.size(); ++col) {
			std::string &to_wrap = i->fields[col];
			if (!to_wrap.empty()) {
				if(widths[col] > space_remaining && to_wrap[0] != IMAGE_PREFIX) {
					to_wrap = font::word_wrap_text(to_wrap, style_->get_font_size(), space_remaining);
					break;
				}
				space_remaining -= widths[col] + 5;
			}
		}
	}
	itemRects_.clear();
	column_widths_.clear();
	max_items_ = -1; // Force recalculation of the max items.
	item_height_ = -1; // Force recalculation of the item height.
	update_size();
}
示例#2
0
文件: menu.cpp 项目: dodikk/iWesnoth
void menu::update_size()
{
	unsigned int h = heading_height();
	for(size_t i = get_position(),
	    i_end = std::min(items_.size(), i + max_items_onscreen());
	    i < i_end; ++i)
		h += get_item_rect(i).h;
	h = std::max(h, height());
	if (max_height_ > 0 && h > static_cast<unsigned>(max_height_)) {
		h = max_height_;
	}

	use_ellipsis_ = false;
	std::vector<int> const &widths = column_widths();
	unsigned w = std::accumulate(widths.begin(), widths.end(), 0);
	if (items_.size() > max_items_onscreen())
		w += scrollbar_width();
	w = std::max(w, width());
	if (max_width_ > 0 && w > static_cast<unsigned>(max_width_)) {
		use_ellipsis_ = true;
		w = max_width_;
	}

	//update_scrollbar_grip_height();
	//set_measurements(w, h);
	size_t max_height = (max_height_ == -1 ? (video().gety()*88)/100 : max_height_) - heading_height();
	h = heading_height();
	for(int i = 0; i < items_.size(); i++)
		h += get_item_height(i);	

	if (max_height > h)
		max_height = h;
	set_measurements(w, max_height);
	update_scrollbar_grip_height();
}
示例#3
0
文件: menu.cpp 项目: ArtBears/wesnoth
void menu::update_size()
{
	int h = heading_height();
	for(size_t i = get_position(),
	    i_end = std::min(items_.size(), i + max_items_onscreen());
	    i < i_end; ++i)
		h += get_item_rect(i).h;
	h = std::max(h, height());
	if (max_height_ > 0 && h > (max_height_)) {
		h = max_height_;
	}

	use_ellipsis_ = false;
	std::vector<int> const &widths = column_widths();
	int w = std::accumulate(widths.begin(), widths.end(), 0);
	if (items_.size() > max_items_onscreen())
		w += scrollbar_width();
	w = std::max(w, width());
	if (max_width_ > 0 && w > (max_width_)) {
		use_ellipsis_ = true;
		w = max_width_;
	}

	update_scrollbar_grip_height();
	set_measurements(w, h);
}