Skip to content

Commit

Permalink
Merge pull request #128 from ImJimmi/stylesheet-improvements
Browse files Browse the repository at this point in the history
Stylesheet improvements
  • Loading branch information
ImJimmi authored Dec 2, 2023
2 parents 24df764 + cd8a669 commit ef36c06
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
16 changes: 16 additions & 0 deletions jive_components/canvases/jive_BackgroundCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,27 @@ namespace jive
juce::Point<float> end{ 1.0f, 1.0f };
};

template <typename Arithmetic>
[[nodiscard]] static auto limited(BorderRadii<Arithmetic> radii, Arithmetic min, Arithmetic max)
{
static_assert(std::is_arithmetic<Arithmetic>());

radii.topLeft = juce::jlimit(min, max, radii.topLeft);
radii.topRight = juce::jlimit(min, max, radii.topRight);
radii.bottomLeft = juce::jlimit(min, max, radii.bottomLeft);
radii.bottomRight = juce::jlimit(min, max, radii.bottomRight);

return radii;
}

static std::array<CubicBezier, 4> getCorners(BorderRadii<float> radii,
juce::Rectangle<float> bounds)
{
static constexpr auto relativeControlPointOffsetForNearPerfectEllipse = 0.552f;

const auto maxRadius = juce::jmin(bounds.getWidth(), bounds.getHeight()) / 2.0f;
radii = limited(radii, 0.0f, maxRadius);

CubicBezier topLeft;
topLeft.start = bounds.getTopLeft().translated(0.0f, radii.topLeft);
topLeft.control1 = topLeft.start.translated(0.0f, -radii.topLeft * relativeControlPointOffsetForNearPerfectEllipse);
Expand Down
13 changes: 0 additions & 13 deletions jive_style_sheets/style-sheets/jive_StyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,6 @@ namespace jive
return value;
}

for (auto stateToSearch = state.getParent();
stateToSearch.isValid();
stateToSearch = stateToSearch.getParent())
{
if (auto value = ::jive::findStyleProperty<StyleSearchStrategy::childrenOnly>(stateToSearch,
*selectors,
propertyName);
value != juce::var{})
{
return value;
}
}

return {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace jive_demo
{ "foreground", "#1C3144" },
{ "border", "#D00000" },
{ "font-size", 12 },
{ "border-radius", 5 },
{ "border-radius", 999 },
},
},
{ "padding", 15 },
Expand Down

0 comments on commit ef36c06

Please sign in to comment.