Skip to content

Commit

Permalink
- updated CSS parser to include flexbox & other positioning stuff
Browse files Browse the repository at this point in the history
- added many other CSS keywords
  • Loading branch information
christoph-hart committed Mar 15, 2024
1 parent 2a55279 commit 9d58b35
Show file tree
Hide file tree
Showing 20 changed files with 3,374 additions and 885 deletions.
3 changes: 1 addition & 2 deletions melatonin_blur/melatonin/internal/cached_shadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ namespace melatonin::internal
}
else
{
needsRecomposite |= renderedSingleChannelShadows[index].updateColor(sh.color.withAlpha(1.0f));
needsRecomposite |= renderedSingleChannelShadows[index].updateOpacity(sh.color.getFloatAlpha());
needsRecomposite |= renderedSingleChannelShadows[index].updateColor(sh.color);
needsRecomposite |= renderedSingleChannelShadows[index].updateOffset(sh.offset, scale);

needsRecalculate |= renderedSingleChannelShadows[index].updateSpread(sh.spread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace melatonin::internal
// expand the actual path itself
// note: this is 1x, it'll be upscaled as needed by fillPath
auto bounds = originAgnosticPath.getBounds().expanded (parameters.inner ? (float) -parameters.spread : (float) parameters.spread);
shadowPath.scaleToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), true);
shadowPath.scaleToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), false);
}

// inner shadows are rendered by inverting the path, drop shadowing and clipping to the original path
Expand Down
3 changes: 3 additions & 0 deletions tools/multipagecreator/Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ class jit_playgroundApplication : public JUCEApplication
centreWithSize (getWidth(), getHeight());
#endif
setVisible (true);

UnitTestRunner r;
r.runTestsInCategory("ui");
}

void closeButtonPressed() override
Expand Down
2 changes: 2 additions & 0 deletions tools/multipagecreator/Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ MainComponent::MainComponent():
menuBar(this),
tooltips(this)
{


TopLevelWindowWithKeyMappings::loadKeyPressMap();

mcl::TextEditor::initKeyPresses(this);
Expand Down
195 changes: 191 additions & 4 deletions tools/multipagecreator/Source/simple_css/Animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Animator::ScopedComponentSetter::ScopedComponentSetter(Component* c)
{
auto root = dynamic_cast<ComponentWithCSS*>(c);

if(root == nullptr)
if(root == nullptr && c != nullptr)
root = c->findParentComponentOfClass<ComponentWithCSS>();

if(root != nullptr)
Expand All @@ -63,9 +63,9 @@ Animator::Item::Item(Animator& parent, StyleSheet::Ptr css_, Transition tr_):
jassert(target != nullptr);
}

bool Animator::Item::timerCallback()
bool Animator::Item::timerCallback(double delta)
{
auto d = 1.0 * 0.015;
auto d = delta * 0.001;

if(transitionData.duration > 0.0)
d /= transitionData.duration;
Expand All @@ -86,13 +86,200 @@ bool Animator::Item::timerCallback()
return true;
}

Animator::Animator()
{
startTimer(15);
}

void Animator::timerCallback()
{
auto thisTime = Time::getMillisecondCounterHiRes();

auto delta = thisTime - lastCallbackTime;

for(int i = 0; i < items.size(); i++)
{
if(!items[i]->timerCallback())
if(!items[i]->timerCallback(delta))
items.remove(i--);
}

lastCallbackTime = thisTime;
}

std::pair<bool, int> StateWatcher::Item::changed(int stateFlag)
{
if(stateFlag != currentState)
{
auto prevState = currentState;
currentState = stateFlag;

return { true, prevState };
}

return { false, currentState };
}

void StateWatcher::Item::renderShadow(Graphics& g, const TextData& textData,
const std::vector<melatonin::ShadowParameters>& parameters, bool wantsInset)
{
if(wantsInset)
{
for(int i = 0; i < parameters.size(); i++)
innerShadowText.setShadow(parameters[i], i);

innerShadowText.render(g, std::get<0>(textData), std::get<2>(textData), std::get<1>(textData));
}
else
{
for(int i = 0; i < parameters.size(); i++)
dropShadowText.setShadow(parameters[i], i);

dropShadowText.render(g, std::get<0>(textData), std::get<2>(textData), std::get<1>(textData));
}
}

void StateWatcher::Item::renderShadow(Graphics& g, const Path& p,
const std::vector<melatonin::ShadowParameters>& parameters, bool wantsInset)
{
if(wantsInset)
{
for(int i = 0; i < parameters.size(); i++)
innerShadow.setShadow(parameters[i], i);

innerShadow.render(g, p);
}
else
{
for(int i = 0; i < parameters.size(); i++)
dropShadow.setShadow(parameters[i], i);

dropShadow.render(g, p);
}
}

void StateWatcher::checkChanges(Component* c, StyleSheet::Ptr ss, int currentState)
{
auto stateChanged = changed(c, currentState);

for(int i = 0; i < updatedComponents.size(); i++)
{
auto& uc = updatedComponents.getReference(i);

if(uc.target == nullptr)
{
updatedComponents.remove(i--);
continue;
}

if(uc.target != c)
continue;

if(!uc.initialised || stateChanged.first)
{
uc.update(ss, currentState);
}

}

if(stateChanged.first)
{
ss->forEachProperty(PseudoElementType::All, [&](PseudoElementType t, Property& p)
{
auto findPropertyValue = [&](int stateToFind)
{
return p.getProperty(stateToFind);


for(auto& pv: p.values)
{
if(pv.first == stateToFind)
return pv.second;
}

return PropertyValue();
};

auto f1 = findPropertyValue(stateChanged.second);
auto f2 = findPropertyValue(currentState);

if( f1 || f2)
{
auto pt = ss->getTransitionOrDefault(t, f1.transition);
auto ct = ss->getTransitionOrDefault(t, f2.transition);

if(pt || ct)
{
auto thisTransition = ct ? ct : pt;

PropertyKey thisStartValue(p.name, PseudoState(stateChanged.second).withElement(t));
PropertyKey thisEndValue(p.name, PseudoState(currentState).withElement(t));

bool found = false;

for(auto i: animator.items)
{
if(i->css == ss &&
i->target == animator.currentlyRenderedComponent &&
i->startValue.name == p.name &&
i->startValue.state.matchesElement(t))
{
if(currentState == i->startValue.state.stateFlag)
{
i->reverse = !i->reverse;
found = true;
break;
}
else
{
i->currentProgress = 0.0;
i->startValue.state = i->endValue.state;
i->endValue.state.stateFlag = currentState;
i->transitionData = thisTransition;
found = true;
break;
}
}
}

if(found)
return false;

auto ad = new Animator::Item(animator, ss, thisTransition);

ad->startValue = thisStartValue;
ad->endValue = thisEndValue;

animator.items.add(ad);
}
}

return false;
});

}
}

std::pair<bool, int> StateWatcher::changed(Component* c, int stateFlag)
{
for(auto& i: items)
{
if(i.c == c)
return i.changed(stateFlag);
}

items.add({ c, stateFlag });
return { false, stateFlag };
}

void StateWatcher::registerComponentToUpdate(Component* c)
{
updatedComponents.addIfNotAlreadyThere({ c });
}

void StateWatcher::UpdatedComponent::update(StyleSheet::Ptr ss, int currentState)
{
ss->setupComponent(target.getComponent(), currentState);
initialised = true;
}
}
}
Expand Down
Loading

0 comments on commit 9d58b35

Please sign in to comment.