Ejemplo n.º 1
0
void wxRibbonBar::RefreshTabBar()
{
    wxRect tab_rect(0, 0, GetClientSize().GetWidth(), m_tab_height);
    Refresh(false, &tab_rect);
}
Ejemplo n.º 2
0
void TabContainer::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_DRAW: {

			RID canvas = get_canvas_item();
			Size2 size = get_size();

			// Draw only the tab area if the header is hidden.
			Ref<StyleBox> panel = get_stylebox("panel");
			if (!tabs_visible) {
				panel->draw(canvas, Rect2(0, 0, size.width, size.height));
				return;
			}

			Vector<Control *> tabs = _get_tabs();
			Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
			Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
			Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
			Ref<Texture> increment = get_icon("increment");
			Ref<Texture> decrement = get_icon("decrement");
			Ref<Texture> menu = get_icon("menu");
			Ref<Texture> menu_hl = get_icon("menu_hl");
			Ref<Font> font = get_font("font");
			Color font_color_fg = get_color("font_color_fg");
			Color font_color_bg = get_color("font_color_bg");
			Color font_color_disabled = get_color("font_color_disabled");
			int side_margin = get_constant("side_margin");
			int icon_text_distance = get_constant("hseparation");

			// Find out start and width of the header area.
			int header_x = side_margin;
			int header_width = size.width - side_margin * 2;
			int header_height = _get_top_margin();
			if (popup)
				header_width -= menu->get_width();

			// Check if all tabs would fit into the header area.
			int all_tabs_width = 0;
			for (int i = 0; i < tabs.size(); i++) {
				int tab_width = _get_tab_width(i);
				all_tabs_width += tab_width;

				if (all_tabs_width > header_width) {
					// Not all tabs are visible at the same time - reserve space for navigation buttons.
					buttons_visible_cache = true;
					header_width -= decrement->get_width() + increment->get_width();
					break;
				} else {
					buttons_visible_cache = false;
				}
			}
			// With buttons, a right side margin does not need to be respected.
			if (popup || buttons_visible_cache) {
				header_width += side_margin;
			}

			// Go through the visible tabs to find the width they occupy.
			all_tabs_width = 0;
			Vector<int> tab_widths;
			for (int i = first_tab_cache; i < tabs.size(); i++) {
				int tab_width = _get_tab_width(i);
				if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0)
					break;
				all_tabs_width += tab_width;
				tab_widths.push_back(tab_width);
			}

			// Find the offset at which to draw tabs, according to the alignment.
			switch (align) {
				case ALIGN_LEFT:
					tabs_ofs_cache = header_x;
					break;
				case ALIGN_CENTER:
					tabs_ofs_cache = header_x + (header_width / 2) - (all_tabs_width / 2);
					break;
				case ALIGN_RIGHT:
					tabs_ofs_cache = header_x + header_width - all_tabs_width;
					break;
			}

			// Draw all visible tabs.
			int x = 0;
			for (int i = 0; i < tab_widths.size(); i++) {
				Ref<StyleBox> tab_style;
				Color font_color;
				if (get_tab_disabled(i + first_tab_cache)) {
					tab_style = tab_disabled;
					font_color = font_color_disabled;
				} else if (i + first_tab_cache == current) {
					tab_style = tab_fg;
					font_color = font_color_fg;
				} else {
					tab_style = tab_bg;
					font_color = font_color_bg;
				}

				// Draw the tab background.
				int tab_width = tab_widths[i];
				Rect2 tab_rect(tabs_ofs_cache + x, 0, tab_width, header_height);
				tab_style->draw(canvas, tab_rect);

				// Draw the tab contents.
				Control *control = tabs[i + first_tab_cache]->cast_to<Control>();
				String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name());

				int x_content = tab_rect.position.x + tab_style->get_margin(MARGIN_LEFT);
				int top_margin = tab_style->get_margin(MARGIN_TOP);
				int y_center = top_margin + (tab_rect.size.y - tab_style->get_minimum_size().y) / 2;

				// Draw the tab icon.
				if (control->has_meta("_tab_icon")) {
					Ref<Texture> icon = control->get_meta("_tab_icon");
					if (icon.is_valid()) {
						int y = y_center - (icon->get_height() / 2);
						icon->draw(canvas, Point2i(x_content, y));
						if (text != "")
							x_content += icon->get_width() + icon_text_distance;
					}
				}

				// Draw the tab text.
				Point2i text_pos(x_content, y_center - (font->get_height() / 2) + font->get_ascent());
				font->draw(canvas, text_pos, text, font_color);

				x += tab_width;
				last_tab_cache = i + first_tab_cache;
			}

			// Draw the popup menu.
			x = get_size().width;
			if (popup) {
				x -= menu->get_width();
				if (mouse_x_cache > x)
					menu_hl->draw(get_canvas_item(), Size2(x, 0));
				else
					menu->draw(get_canvas_item(), Size2(x, 0));
			}

			// Draw the navigation buttons.
			if (buttons_visible_cache) {
				int y_center = header_height / 2;

				x -= increment->get_width();
				increment->draw(canvas,
						Point2(x, y_center - (increment->get_height() / 2)),
						Color(1, 1, 1, last_tab_cache < tabs.size() - 1 ? 1.0 : 0.5));

				x -= decrement->get_width();
				decrement->draw(canvas,
						Point2(x, y_center - (decrement->get_height() / 2)),
						Color(1, 1, 1, first_tab_cache > 0 ? 1.0 : 0.5));
			}

			// Draw the tab area.
			panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
		} break;
		case NOTIFICATION_THEME_CHANGED: {
			if (get_tab_count() > 0) {
				call_deferred("set_current_tab", get_current_tab()); //wait until all changed theme
			}
		} break;
	}
}