Exemplo n.º 1
0
void ElementTabSet::SetActiveTab(int tab_index)
{
	// Update display if the tab has changed
	if (tab_index != active_tab)
	{
		Core::Element* tabs = GetChildByTag("tabs");
		Core::Element* old_tab = tabs->GetChild(active_tab);
		Core::Element* new_tab = tabs->GetChild(tab_index);

		if (old_tab)
			old_tab->SetPseudoClass("selected", false);
		if (new_tab)
			new_tab->SetPseudoClass("selected", true);

		Core::Element* windows = GetChildByTag("panels");
		Core::Element* old_window = windows->GetChild(active_tab);
		Core::Element* new_window = windows->GetChild(tab_index);

		if (old_window)
			old_window->SetProperty("display", "none");
		if (new_window)
			new_window->SetProperty("display", "inline-block");

		active_tab = tab_index;

		Rocket::Core::Dictionary parameters;
		parameters.Set("tab_index", active_tab);
		DispatchEvent("tabchange", parameters);
	}
}
Exemplo n.º 2
0
// Remove one of the tab set's panels and its corresponding tab.
void ElementTabSet::RemoveTab(int tab_index)
{
	if (tab_index < 0)
		return;

	Core::Element* panels = GetChildByTag("panels");
	Core::Element* tabs = GetChildByTag("tabs");

	if (panels->GetNumChildren() > tab_index &&
		tabs->GetNumChildren() > tab_index)
	{
		panels->RemoveChild(panels->GetChild(tab_index));
		tabs->RemoveChild(tabs->GetChild(tab_index));
	}
}
Exemplo n.º 3
0
// Process the incoming event.
void ElementTabSet::ProcessEvent(Core::Event& event)
{
	Core::Element::ProcessEvent(event);

	if (event.GetCurrentElement() == this && event == "click")
	{
		// Find the tab that this click occured on
		Core::Element* tabs = GetChildByTag("tabs");
		Core::Element* tab = event.GetTargetElement();
		while (tab && tab != this && tab->GetParentNode() != tabs)
			tab = tab->GetParentNode();

		// Abort if we couldn't find the tab the click occured on
		if (!tab || tab == this)
			return;

		// Determine the new active tab index
		int new_active_tab = active_tab;
		for (int i = 0; i < tabs->GetNumChildren(); i++)
		{
			if (tabs->GetChild(i) == tab)
			{
				new_active_tab = i;
				break;
			}
		}

		SetActiveTab(new_active_tab);
	}
}
Exemplo n.º 4
0
// Renders any debug elements in the debug context.
void Plugin::Render()
{
	// Render the outlines of the debug context's elements.
	if (render_outlines &&
		debug_context != NULL)
	{
		for (int i = 0; i < debug_context->GetNumDocuments(); ++i)
		{
			Core::ElementDocument* document = debug_context->GetDocument(i);
			if (document->GetId().Find("rkt-debug-") == 0)
				continue;

			std::stack< Core::Element* > element_stack;
			element_stack.push(document);

			while (!element_stack.empty())
			{
				Core::Element* element = element_stack.top();
				element_stack.pop();
				if (element->IsVisible())
				{
					for (int j = 0; j < element->GetNumBoxes(); ++j)
					{
						const Core::Box& box = element->GetBox(j);
						Geometry::RenderOutline(element->GetAbsoluteOffset(Core::Box::BORDER) + box.GetPosition(Core::Box::BORDER), box.GetSize(Core::Box::BORDER), Core::Colourb(255, 0, 0, 128), 1);
					}

					for (int j = 0; j < element->GetNumChildren(); ++j)
						element_stack.push(element->GetChild(j));
				}
			}
		}
	}

	// Render the info element's boxes.
	if (info_element != NULL &&
		info_element->IsVisible())
	{
		info_element->RenderHoverElement();
		info_element->RenderSourceElement();
	}
}
Exemplo n.º 5
0
// Adds the cell contents, and marks the row as loaded.
void ElementDataGridRow::Load(const DataQuery& row_information)
{
	// Check for a data source. If they're both set then we set
	// ourselves up with it.
	if (row_information.IsFieldSet(DataSource::CHILD_SOURCE))
	{
		Rocket::Core::String data_source = row_information.Get< Rocket::Core::String >(DataSource::CHILD_SOURCE, "");
		if (!data_source.Empty())
		{
			SetDataSource(data_source);
		}
		else
		{
			// If we've no data source, then we should remove any children.
			RemoveChildren();
		}
	}

	// Now load our cells.
	for (int i = 0; i < parent_grid->GetNumColumns(); i++)
	{
		Core::Element* cell = GetChild(i);

		if (cell)
		{
			// Fetch the column:
			const ElementDataGrid::Column* column = parent_grid->GetColumn(i);

			// Now we use the column's formatter to process the raw data into the
			// XML string, and parse that into the actual Core::Elements. If there is
			// no formatter, then we just send through the raw text, in CVS form.
			Rocket::Core::StringList raw_data;
			for (size_t i = 0; i < column->fields.size(); i++)
			{
				if (column->fields[i] == DataSource::DEPTH)
				{
					raw_data.push_back(Rocket::Core::String(8, "%d", depth));
				}
				else if (column->fields[i] == DataSource::NUM_CHILDREN)
				{
					raw_data.push_back(Rocket::Core::String(8, "%d", children.size()));
				}
				else
				{
					raw_data.push_back(row_information.Get< Rocket::Core::String >(column->fields[i], ""));
				}
			}

			Rocket::Core::String cell_string;
			if (column->formatter)
			{
				column->formatter->FormatData(cell_string, raw_data);
			}
			else
			{
				for (size_t i = 0; i < raw_data.size(); i++)
				{
					if (i > 0)
					{
						cell_string.Append(",");
					}
					cell_string.Append(raw_data[i]);
				}
			}

			// Remove all the cell's current contents.
			while (cell->GetNumChildren(true) > 0)
			{
				cell->RemoveChild(cell->GetChild(0));
			}

			// Add the new contents to the cell.
			Core::Factory::InstanceElementText(cell, cell_string);
		}
		else
		{
			ROCKET_ERROR;
		}
	}

	dirty_cells = false;
}