mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-06 06:09:52 +03:00
Added css style propagation + hover propagation from child
This commit is contained in:
@@ -36,8 +36,8 @@ namespace NuakeUI
|
||||
if (!mRootNode)
|
||||
return;
|
||||
|
||||
mRootNode->UpdateInput(mInputManager);
|
||||
mRootNode->Tick(mInputManager);
|
||||
mRootNode->UpdateInput(mInputManager);
|
||||
|
||||
mInputManager->ScrollX = 0.f;
|
||||
mInputManager->ScrollY = 0.f;
|
||||
@@ -84,29 +84,26 @@ namespace NuakeUI
|
||||
}
|
||||
}
|
||||
|
||||
void Canvas::ComputeStyle(NodePtr node)
|
||||
void Canvas::ComputeStyle(NodePtr node, const std::vector<StyleRule>& inheritedRules)
|
||||
{
|
||||
for (auto& s : node->GetDataModelOperations())
|
||||
std::vector<StyleRule> relationStyles;
|
||||
|
||||
auto allRules = mStyleSheet->Rules;
|
||||
for (auto& i : inheritedRules)
|
||||
{
|
||||
if (s->Type != OperationType::IfClass)
|
||||
continue;
|
||||
|
||||
|
||||
if (auto dataModel = node->GetDataModel(); s->Compare(dataModel))
|
||||
{
|
||||
node->AddClass(s->ClassName);
|
||||
}
|
||||
else
|
||||
{
|
||||
node->RemoveClass(s->ClassName);
|
||||
}
|
||||
allRules.push_back(i);
|
||||
}
|
||||
|
||||
std::vector<StyleRule> relationStyles;
|
||||
for (auto& rule : mStyleSheet->Rules)
|
||||
if (node->Classes.size() == 1 && node->Classes[0] == "dropdown")
|
||||
{
|
||||
Logger::Log("Found dropdown");
|
||||
}
|
||||
|
||||
for (auto& rule : allRules)
|
||||
{
|
||||
bool respectSelector = true;
|
||||
bool containsRelation = false;
|
||||
std::vector<StyleRule> relationalStyleInRule;
|
||||
// TODO: Apply descendant selectors to child nodes.
|
||||
for (StyleSelector& selector : rule.Selector)
|
||||
{
|
||||
@@ -150,39 +147,47 @@ namespace NuakeUI
|
||||
}
|
||||
}
|
||||
|
||||
if (selector.SelectorRelation != Relation::None)
|
||||
if (respectSelector && selector.SelectorRelation != Relation::None)
|
||||
{
|
||||
containsRelation = true;
|
||||
if (selector.SelectorRelation == Relation::Descendant)
|
||||
{
|
||||
containsRelation = true;
|
||||
foundSelector = true;
|
||||
auto ruleSelector = StyleSelector{ selector.Type, selector.Value, Relation::None };
|
||||
|
||||
StyleRule newStyleRule = StyleRule({ ruleSelector });
|
||||
newStyleRule.Properties = rule.Properties;
|
||||
relationStyles.push_back(std::move(newStyleRule));
|
||||
relationalStyleInRule.push_back(std::move(newStyleRule));
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundSelector)
|
||||
else if(!foundSelector)
|
||||
{
|
||||
respectSelector = false;
|
||||
}
|
||||
|
||||
if (respectSelector)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (respectSelector && !containsRelation)
|
||||
{
|
||||
node->ApplyStyleProperties(rule.Properties);
|
||||
}
|
||||
|
||||
if (relationalStyleInRule.size() > 0 && respectSelector)
|
||||
{
|
||||
for (auto& s : relationalStyleInRule)
|
||||
{
|
||||
relationStyles.push_back(s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (auto& c : node->GetChildrens())
|
||||
{
|
||||
if (relationStyles.size() > 0)
|
||||
{
|
||||
//c->ApplyStyleProperties(relationStyles.);
|
||||
}
|
||||
|
||||
ComputeStyle(c);
|
||||
ComputeStyle(c, relationStyles);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace NuakeUI
|
||||
void Tick();
|
||||
void Draw();
|
||||
void ComputeLayout(Vector2 size);
|
||||
void ComputeStyle(NodePtr node);
|
||||
void ComputeStyle(NodePtr node, const std::vector<StyleRule>& inheritedRules = {});
|
||||
|
||||
NodePtr GetRoot() const;
|
||||
void SetRoot(NodePtr root);
|
||||
|
||||
@@ -316,6 +316,11 @@ namespace NuakeUI
|
||||
|
||||
bool Node::IsMouseHover(float x, float y)
|
||||
{
|
||||
if (ComputedStyle.Visibility != VisibilityType::Show)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
YGNodeRef ygNode = GetYogaNode();
|
||||
|
||||
float parentScroll = 0.f;
|
||||
@@ -340,7 +345,15 @@ namespace NuakeUI
|
||||
|
||||
left += parentLeft;
|
||||
top += parentTop;
|
||||
bool isHover = x > left && x < left + width && y > top && y < top + height;
|
||||
bool isHover = x >= left && x < left + width && y >= top && y < top + height;
|
||||
|
||||
for (auto& c : Childrens)
|
||||
{
|
||||
if (c->IsMouseHover(x, y))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return isHover;
|
||||
}
|
||||
|
||||
|
||||
@@ -227,9 +227,9 @@ void StyleSheetParser::ParseStyleRule(KatanaRule* rule, StyleSheetPtr styleSheet
|
||||
currentStyleSelector.SelectorRelation = Relation::Child;
|
||||
break;
|
||||
|
||||
case KatanaSelectorRelationSubSelector:
|
||||
currentStyleSelector.SelectorRelation = Relation::SubSelection;
|
||||
break;
|
||||
//case KatanaSelectorRelationSubSelector:
|
||||
// currentStyleSelector.SelectorRelation = Relation::SubSelection;
|
||||
// break;
|
||||
|
||||
default:
|
||||
currentStyleSelector.SelectorRelation = Relation::None;
|
||||
|
||||
Reference in New Issue
Block a user