Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed May 11, 2019
1 parent d442216 commit b7f84b1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Include/Rocket/Core/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ class ROCKETCORE_API Element : public ScriptInterface

PropertyNameList dirty_properties;
bool all_properties_dirty;
bool computed_values_are_default;
bool computed_values_are_default_initialized;
bool box_dirty;

// The element's font face; used to render text and resolve em / ex properties.
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ transform_state(), transform_state_perspective_dirty(true), transform_state_tran
parent_structure_dirty = false;

all_properties_dirty = true;
computed_values_are_default = true;
computed_values_are_default_initialized = true;
box_dirty = false;

font_face_handle = NULL;
Expand Down Expand Up @@ -224,9 +224,9 @@ void Element::Update()
if (auto context = doc->GetContext())
dp_ratio = context->GetDensityIndependentPixelRatio();
}
style->ComputeValues(element_meta->computed_values, parent_values, document_values, computed_values_are_default, dp_ratio);
style->ComputeValues(element_meta->computed_values, parent_values, document_values, computed_values_are_default_initialized, dp_ratio);

computed_values_are_default = false;
computed_values_are_default_initialized = false;
}

// Right now we are assuming computed values are calculated before OnPropertyChange
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/ElementAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ static Property InterpolateProperties(const Property & p0, const Property& p1, f
else
{
// Otherwise, convert units to pixels.
float f0 = element.GetStyle()->ResolveLengthPercentage(&p0, definition->GetRelativeTarget());
float f1 = element.GetStyle()->ResolveLengthPercentage(&p1, definition->GetRelativeTarget());
float f0 = element.GetStyle()->ResolveNumberLengthPercentage(&p0, definition->GetRelativeTarget());
float f1 = element.GetStyle()->ResolveNumberLengthPercentage(&p1, definition->GetRelativeTarget());
float f = (1.0f - alpha) * f0 + alpha * f1;
return Property{ f, Property::PX };
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/ElementStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ const PropertyMap * ElementStyle::GetLocalProperties() const
return NULL;
}

float ElementStyle::ResolveLengthPercentage(const Property * property, RelativeTarget relative_target)
float ElementStyle::ResolveNumberLengthPercentage(const Property * property, RelativeTarget relative_target)
{
// There is an exception on font-size properties, as 'em' units here refer to parent font size instead
if ((property->unit & Property::LENGTH) && !(property->unit == Property::EM && relative_target == RelativeTarget::ParentFontSize))
Expand Down Expand Up @@ -746,7 +746,7 @@ void ElementStyle::DirtyInheritedProperties(const PropertyNameList& properties)


// Must be called in correct order, from document root to children elements.
void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::ComputedValues* parent_values, const Style::ComputedValues* document_values, bool values_are_defaulted, float dp_ratio)
void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::ComputedValues* parent_values, const Style::ComputedValues* document_values, bool values_are_default_initialized, float dp_ratio)
{
// Generally, this is how it works (for now, we can probably be smarter about this):
// 1. Assign default values (clears any newly dirtied properties)
Expand All @@ -755,7 +755,7 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com


// The next flag is just a small optimization, if the element was just created we don't need to copy all the default values.
if (!values_are_defaulted)
if (!values_are_default_initialized)
{
values = DefaultComputedValues;
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/ElementStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class ElementStyle
/// @param[in] base_value The value that is scaled by the percentage value, if it is a percentage.
/// @return The resolved value in 'px' unit.
float ResolveLengthPercentage(const Property *property, float base_value);
/// Resolves a property with units of length or percentage to 'px'. Percentages are resolved by scaling by the size of the specified target.
/// 'percentage' and 'number' are multiplied by the size of the specified relative reference.
float ResolveLengthPercentage(const Property* property, RelativeTarget relative_target);
/// Resolves a property with units of number, length or percentage. Lengths are resolved to 'px'.
/// Number and percentages are resolved by scaling by the size of the specified target.
float ResolveNumberLengthPercentage(const Property* property, RelativeTarget relative_target);

/// Iterates over the properties defined on the element.
/// @param[inout] index Index of the property to fetch. This is incremented to the next valid index after the fetch. Indices are not necessarily incremental.
Expand Down Expand Up @@ -141,7 +141,7 @@ class ElementStyle
// Dirties dp properties.
void DirtyDpProperties();

void ComputeValues(Style::ComputedValues& values, const Style::ComputedValues* parent_values, const Style::ComputedValues* document_values, bool values_are_defaulted, float dp_ratio);
void ComputeValues(Style::ComputedValues& values, const Style::ComputedValues* parent_values, const Style::ComputedValues* document_values, bool values_are_default_initialized, float dp_ratio);

private:
// Sets a single property as dirty.
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ If upgrading from the original libRocket branch, some breaking changes should be
- Rocket::Core::String has been replaced by std::string, thus, interfacing with the library now requires you to change your string types. This change was motivated by a small performance gain, additionally, it should make it easier to interface with the library especially for users already using std::string in their codebase.
- Querying the property of an element for size, position and similar may not work as expected right after changes to the document or style. This change is made for performance reasons, see the note below for reasoning and a workaround.
- The Controls::DataGrid "min-rows" property has been replaced by an attribute of the same name.
- Removed RenderInterface::GetPixelsPerInch, instead the pixels per inch value has been fixed to 96 PPI, as per CSS specs. To achieve a scalable user interface, instead use the 'dp' unit.

## Performance

Expand Down

0 comments on commit b7f84b1

Please sign in to comment.