Skip to content

Add the capability of setting an User Agent stylesheet #879

@ghsoares

Description

@ghsoares

Describe the project you are working on

A GDExtension for Godot engine integrating RmlUi.

Describe the problem or limitation you are having in your project

RmlUi doesn't include a default stylesheet on the documents, leaving the default stylization by manually including stylesheets, this is ok, as default stylization is done by the actual implementation, not the layout engine.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a way to set a user agent stylesheet in the Context, this stylesheet is automatically included into new documents, regardless if the document already have a stylesheet container.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The configured stylesheet when is not null, would be prepended into new document's stylesheet, it must be prepended by creating a new empty StyleSheetContainer, merging the user agent stylesheet first then the document's stylesheet, it this order so that the user agent doesn't override any style property of the document itself.

If this enhancement will not be used often, can it be worked around?

Yes, quite simply by using a Rml::Plugin and implementing OnDocumentLoad, merging the user agent with the document's stylesheet as detailed previously. The method implementation in my project looks something like this:

void RmlPluginUserAgentStyleSheet::OnDocumentLoad(Rml::ElementDocument* document) {
	// Inject user agent stylesheet for default style
	if (default_stylesheet) {
		Rml::SharedPtr<Rml::StyleSheetContainer> new_stylesheet = std::make_shared<Rml::StyleSheetContainer>();
		new_stylesheet->MergeStyleSheetContainer(*default_stylesheet);
		if (document->GetStyleSheetContainer()) {
			new_stylesheet->MergeStyleSheetContainer(*document->GetStyleSheetContainer());
		}
		document->SetStyleSheetContainer(new_stylesheet);
	}
}

Is there a reason why this should be core?

For any document, it must have a default stylesheet for readable presentation of the elements, and needing to include one on every document it's not ideal. It could be worked around with a plugin as detailed previously, but it would be better if it was core.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionMeta talk and feedbackenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions