Skip to content

Make style sheets cascade #2977

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

Merged
merged 16 commits into from
Jan 6, 2024
Merged

Make style sheets cascade #2977

merged 16 commits into from
Jan 6, 2024

Conversation

amolenaar
Copy link
Member

@amolenaar amolenaar commented Jan 3, 2024

This is a follow-up PR on #2969.

PR Type

What kind of change does this PR introduce?

  • Bug fix
  • Feature
  • Chore (refactoring, formatting, local variables, other cleanup)
  • Documentation content changes

What is the current behavior?

Currently, every item on the diagram is a root item, even if it's contained in another item

Issue Number: #3023

What is the new behavior?

  • Cascade styles down. From diagram -> item -> nested item -> in-item css node.
  • :root has been fixed. Refers to the top-level diagram. (Note that there's also a DiagramItem, which is referred to as diagram!)
  • CSS nodes in a presentation item are also iterated (for :has() and :empty)
  • Styles are cached per diagram. Cache is reset as soon as an item needs updating.
  • Removed all inline styling for C4 model items.
  • Fixed traversal of item to nested CssNodes.
  • Simplified compile_style_sheet() output. The function now makes sure the rules are in ascending order.
  • Added more type annotations.
  • Text now uses color as color if text-color is not defined. text-color is deprecated.

Does this PR introduce a breaking change?

  • Yes
  • No
  • Minor change in CSS computation.

Other information

The gaphor.core.modeling.diagram.StyledItem class now depends on the interface of gaphor.diagram.shapes.CssNode. This is not so clean, but can be fixed by implementing a protocol in the future.

@github-actions github-actions bot added python Pull requests that update Python code packaging Update to packaging aspects documentation labels Jan 3, 2024
@amolenaar amolenaar changed the base branch from main to pseudo-element January 4, 2024 14:06
@amolenaar amolenaar mentioned this pull request Jan 4, 2024
6 tasks
@danyeaw danyeaw added feature A new feature and removed python Pull requests that update Python code packaging Update to packaging aspects documentation labels Jan 4, 2024
Base automatically changed from pseudo-element to main January 4, 2024 20:47
@github-actions github-actions bot added the python Pull requests that update Python code label Jan 5, 2024
@danyeaw danyeaw removed the python Pull requests that update Python code label Jan 5, 2024
@github-actions github-actions bot added the python Pull requests that update Python code label Jan 5, 2024
Copy link
Member

@danyeaw danyeaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a nice improvement, thanks @amolenaar!

I merged main to resolve a merge conflict. However, mypy isn't happy since the node argument to compute_node is getting a PseudoStyleNode, and importing it from the styling module creates a circular import.

@amolenaar
Copy link
Member Author

I'm not done yet :)

Assign one CompiledStyleSheet per diagram, so style caches can be
invalidated when a diagram is updated.
So that we can just iterate and apply in the right order
@amolenaar amolenaar force-pushed the cascading-css branch 2 times, most recently from 69733ac to 2e25cac Compare January 6, 2024 10:39
Now that styles are inherited, assigning a color will also assign it to
the diagram. Since color is an inherited property, it will automatically
be assigned to all items.
In case text-color is not defined.
@amolenaar amolenaar requested a review from danyeaw January 6, 2024 11:02
@amolenaar
Copy link
Member Author

@danyeaw I think it's ready for review

Copy link
Member

@danyeaw danyeaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amolenaar!

@danyeaw danyeaw merged commit 24c39a6 into main Jan 6, 2024
@danyeaw danyeaw deleted the cascading-css branch January 6, 2024 23:28
@danyeaw danyeaw removed python Pull requests that update Python code documentation labels Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants