Skip to content

enhancement to style method: receive object containing styles #5121

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

Closed
2 of 17 tasks
Aloneduckling opened this issue Mar 24, 2021 · 4 comments
Closed
2 of 17 tasks

enhancement to style method: receive object containing styles #5121

Aloneduckling opened this issue Mar 24, 2021 · 4 comments

Comments

@Aloneduckling
Copy link
Contributor

Aloneduckling commented Mar 24, 2021

How would this new feature help increase access to p5.js?

Currently style() method can be used like this:
style(property) and style(property, value) and style('property1: value1; property2: value2')

Using style() like this becomes inefficient if we want to have a relatively large number of styles.

Solution:
If we add a functionality that enables style() to accept an object with styles defined in it, it would reduce a lot of work and make it more efficient and easy to use.

let styles, div;
function setup(){
   background(220);
   div = createDiv('text');
   
   //object which contains styles
   styles = {
        color: green;
        background: white;
        boxShadow: 0 3px 5px black;
        width: 50%;
        margin: 0 auto;
   }; 
   div.style(styles);
}

There is also a workaround for this which is using string template literals to define styles.
Example here

In this case, we can update the inline docs by adding an example.

Most appropriate sub-area of p5.js?

  • Accessibility (Web Accessibility)
  • Build tools and processes
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Friendly error system
  • Image
  • IO (Input/Output)
  • Localization
  • Math
  • Unit Testing
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)

Feature enhancement details:

@welcome
Copy link

welcome bot commented Mar 24, 2021

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

@limzykenneth
Copy link
Member

I'm not sure the accessibility requirement for new features has been met here. One thing I would consider is this new way of defining style makes things easier but for whom?

@Aloneduckling
Copy link
Contributor Author

I think you are right, this feature doesn't quite fulfill the established p5.js access criteria. I thought having this feature would help in writing cleaner, understandable (if we are defining a lot of styles) and quality code. This would make the above things easier for all the p5.js users in general.
I also think having this feature would open doors to make p5.js and DOM much more connected like having CSS properties and states (hover, active, etc. which currently using p5.js is not easy to implement), taking p5.js DOM to a whole new level.

@lmccart
Copy link
Member

lmccart commented Apr 2, 2021

These are great ideas @Aloneduckling, but I agree with your assessment about access criteria. I'd propose we table this for now and see if further needs develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants