Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media queries #169

Merged
merged 34 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
141af44
defined media features and refactor of stylesheet
Dakror Jan 21, 2021
64ce79f
media query list class
Dakror Jan 21, 2021
585effb
media query list class
Dakror Jan 21, 2021
42db20e
api definition change
Dakror Jan 22, 2021
5f2ae95
restructure to restore old version of stylesheet and move stylesheet …
Dakror Jan 22, 2021
31da349
parser setup
Dakror Jan 23, 2021
7f154de
tests are passing!
Dakror Jan 24, 2021
295b617
Merge branch 'master' of https://github.com/mikke89/RmlUi into media-…
Dakror Jan 24, 2021
bb8169b
parser and unit test
Dakror Jan 24, 2021
5083d46
fix unit test
Dakror Jan 24, 2021
5a7ab55
new properties and propertydefinition flags
Dakror Jan 25, 2021
9b5765f
parse properties using parser
Dakror Jan 25, 2021
6381a6a
Revert PropertyFlags as they are too complicated
Dakror Jan 26, 2021
5dbfa68
media query parser and more test cases
Dakror Jan 26, 2021
3f191a7
Dirty stylesheet container
Dakror Jan 26, 2021
9d1f559
Fix build errors without pch
Dakror Jan 26, 2021
7e88e96
fix more compile errors
Dakror Jan 26, 2021
dd1a749
rework the dirtying of the stylesheet
Dakror Jan 26, 2021
8134fba
Merge branch 'master' of https://github.com/mikke89/RmlUi into media-…
Dakror Jan 26, 2021
6eaac20
First sweep of easy fixes
Dakror Feb 1, 2021
a104282
Merge branch 'master' of https://github.com/mikke89/RmlUi into media-…
Dakror Feb 1, 2021
d11bed1
include parser keeps coming back... im haunted
Dakror Feb 1, 2021
83372e7
more small fixes
Dakror Feb 1, 2021
47f0bfa
media query id
Dakror Feb 1, 2021
f252bdb
media block struct
Dakror Feb 1, 2021
072a61d
stylesheet types
Dakror Feb 1, 2021
44d6454
x unit
Dakror Feb 1, 2021
12f31fc
clang fixes
Dakror Feb 1, 2021
98bcc50
fix specificity offset missing
Dakror Feb 2, 2021
91a6db4
fix unit test
Dakror Feb 2, 2021
c0da560
x unit
Dakror Feb 2, 2021
08f77c6
stylesheet private constructor
Dakror Feb 6, 2021
08fc6ad
fix pch
Dakror Feb 6, 2021
57883eb
few more fixes
Dakror Feb 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rework the dirtying of the stylesheet
  • Loading branch information
Dakror committed Jan 26, 2021
commit dd1a749821461ca053577f8ec1f256270d8b6cc1
3 changes: 0 additions & 3 deletions Include/RmlUi/Core/ElementDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ class RMLUICORE_API ElementDocument : public Element
// The original path this document came from
String source_url;

// The document's style sheet.
StyleSheet* style_sheet;

// The document's style sheet container.
SharedPtr<StyleSheetContainer> style_sheet_container;

Expand Down
9 changes: 3 additions & 6 deletions Include/RmlUi/Core/StyleSheetContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ class RMLUICORE_API StyleSheetContainer : public NonCopyMoveable
/// Loads a style from a CSS definition.
bool LoadStyleSheetContainer(Stream* stream, int begin_line_number = 1);

/// Combines the underlying media blocks into a final merged stylesheet according to the given media features
/// Returns the currently compiled style sheet that has been merged from incorporating all matching media blocks
/// or creates it ad-hoc if the given properties differ from the currently stored values.
/// @param[in] dimensions The current context viewport dimensions
/// @param[in] density_ratio The current context ratio of 'dp' units to 'px' units
/// @return True if a new style sheet has been compiled
bool UpdateMediaFeatures(Vector2i dimensions, float density_ratio);

/// Returns the currently compiled style sheet that has been merged from incorporating all matching media blocks.
StyleSheet* GetCompiledStyleSheet() const;
StyleSheet* GetCompiledStyleSheet(Vector2i dimensions, float density_ratio);

/// Combines this style sheet container with another one, producing a new sheet container.
SharedPtr<StyleSheetContainer> CombineStyleSheetContainer(const StyleSheetContainer& container) const;
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "../../Include/RmlUi/Core/SystemInterface.h"
#include "../../Include/RmlUi/Core/StreamMemory.h"
#include "DataModel.h"
#include "ElementStyle.h"
Dakror marked this conversation as resolved.
Show resolved Hide resolved
#include "EventDispatcher.h"
#include "PluginRegistry.h"
#include "StreamFile.h"
Expand Down Expand Up @@ -125,6 +126,9 @@ void Context::SetDimensions(const Vector2i _dimensions)
ElementDocument* document = root->GetChild(i)->GetOwnerDocument();
if (document != nullptr)
{
// Invalidate definition to force stylesheet recompilation
document->GetStyle()->DirtyDefinition();
Dakror marked this conversation as resolved.
Show resolved Hide resolved

document->DirtyVwAndVhProperties();
document->DirtyLayout();
document->DirtyPosition();
Expand Down Expand Up @@ -153,6 +157,9 @@ void Context::SetDensityIndependentPixelRatio(float _density_independent_pixel_r
ElementDocument* document = root->GetChild(i)->GetOwnerDocument();
if (document != nullptr)
{
// Invalidate definition to force stylesheet recompilation
document->GetStyle()->DirtyDefinition();

document->DirtyDpProperties();
}
}
Expand Down
16 changes: 3 additions & 13 deletions Source/Core/ElementDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace Rml {

ElementDocument::ElementDocument(const String& tag) : Element(tag)
{
style_sheet = nullptr;
context = nullptr;

modal = false;
Expand Down Expand Up @@ -140,10 +139,7 @@ void ElementDocument::ProcessHeader(const DocumentHeader* document_header)

// If a style sheet is available, set it on the document and release it.
if (new_style_sheet)
{
SetStyleSheetContainer(std::move(new_style_sheet));
style_sheet = style_sheet_container->GetCompiledStyleSheet();
}

// Load scripts.
for (const DocumentHeader::Resource& script : header.scripts)
Expand Down Expand Up @@ -200,17 +196,14 @@ void ElementDocument::SetStyleSheetContainer(SharedPtr<StyleSheetContainer> _sty

style_sheet_container = std::move(_style_sheet_container);

if (style_sheet_container && context)
style_sheet_container->UpdateMediaFeatures(context->GetDimensions(), context->GetDensityIndependentPixelRatio());

GetStyle()->DirtyDefinition();
}

// Returns the document's style sheet.
const StyleSheet* ElementDocument::GetStyleSheet() const
{
if(style_sheet_container)
return style_sheet_container->GetCompiledStyleSheet();
if(context && style_sheet_container)
return style_sheet_container->GetCompiledStyleSheet(context->GetDimensions(), context->GetDensityIndependentPixelRatio());
return nullptr;
}

Expand Down Expand Up @@ -405,10 +398,7 @@ void ElementDocument::LoadExternalScript(const String& RMLUI_UNUSED_PARAMETER(so

// Updates the document, including its layout
void ElementDocument::UpdateDocument()
{
if (context && style_sheet_container && style_sheet_container->UpdateMediaFeatures(context->GetDimensions(), context->GetDensityIndependentPixelRatio()))
GetStyle()->DirtyDefinition();

{
const float dp_ratio = (context ? context->GetDensityIndependentPixelRatio() : 1.0f);
const Vector2f vp_dimensions = (context ? Vector2f(context->GetDimensions()) : Vector2f(1.0f));
Update(dp_ratio, vp_dimensions);
Expand Down
12 changes: 3 additions & 9 deletions Source/Core/StyleSheetContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ bool StyleSheetContainer::LoadStyleSheetContainer(Stream* stream, int begin_line
return rule_count >= 0;
}

bool StyleSheetContainer::UpdateMediaFeatures(Vector2i dimensions, float density_ratio)
StyleSheet* StyleSheetContainer::GetCompiledStyleSheet(Vector2i dimensions, float density_ratio)
{
if(compiled_style_sheet && dimensions == current_dimensions && density_ratio == current_density_ratio)
return false;
return compiled_style_sheet.get();

UniquePtr<StyleSheet> new_sheet = MakeUnique<StyleSheet>();

Expand Down Expand Up @@ -136,13 +136,7 @@ bool StyleSheetContainer::UpdateMediaFeatures(Vector2i dimensions, float density

compiled_style_sheet = std::move(new_sheet);
Dakror marked this conversation as resolved.
Show resolved Hide resolved
current_dimensions = dimensions;
current_density_ratio = current_density_ratio;

return true;
}

StyleSheet* StyleSheetContainer::GetCompiledStyleSheet() const
{
current_density_ratio = density_ratio;
return compiled_style_sheet.get();
}

Expand Down
3 changes: 2 additions & 1 deletion Tests/Source/UnitTests/MediaQueries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ TEST_CASE("mediaqueries.dynamic")
CHECK(elems[0]->GetBox() == Box(Vector2f(32.0f, 32.0f)));

context->SetDimensions(Vector2i(480, 320));
document->UpdateDocument();

context->Update();

CHECK(elems[0]->GetBox() == Box(Vector2f(64.0f, 64.0f)));

Expand Down