Skip to content
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

add custom value for show() function for p5.Elements #7388 #7389

Open
1 of 17 tasks
rbottura opened this issue Nov 22, 2024 · 7 comments
Open
1 of 17 tasks

add custom value for show() function for p5.Elements #7388 #7389

rbottura opened this issue Nov 22, 2024 · 7 comments

Comments

@rbottura
Copy link

Increasing access

we could deal with flex-type elements, and be able to toggle there visibility with a simple show('flex'). Or with a combined use with hide(), store the initial display value in p5.Element memory and re-use it when calling show() on same element.

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

Feature enhancement details

p5.Element.prototype.show = function (value = 'block') {
  // List of valid CSS display values
  const validDisplayValues = [
    'block', 'inline', 'inline-block', 'flex', 'inline-flex', 'grid',
    'inline-grid', 'table', 'table-row', 'table-cell', 'contents', 'list-item', 
    'none', 'initial', 'inherit', 'unset', 'run-in', 'ruby', 'ruby-base', 
    'ruby-text', 'ruby-base-container', 'ruby-text-container'
  ];

  if (validDisplayValues.includes(value)) {
    this.elt.style.display = value;
  } else {
    console.error(`Invalid value for displaying element: "${value}"`);
  }

  return this;
};
@wayneharish10
Copy link

Hi! Can I work on this enhancement request. I consider myself a newbie to open source and to p5.js for that matter. And I'd do good with a little bit of help.

@rbottura
Copy link
Author

Sure, I'd like also to become a contributor to the library, I have a few blocks of code i'd like to see in the lib and as addons. Maybe we wait for a steward for a review, go free with this one I see you already forked the lib, may be a merge request on main with this implementation would go faster, idk

@wayneharish10
Copy link

wayneharish10 commented Nov 25, 2024

Thank you! I think we might need approval from at least 1 steward before we start the work, as this is feature enhancement. Let's see.

@davepagurek
Copy link
Contributor

I think something like this makes sense, @limzykenneth how do you feel about the proposed API here?

@limzykenneth
Copy link
Member

I'm thinking whether block is a good default or would initial be better, or maybe one of the other reverting ones, would need to consider edge cases if so though. For the implementation itself, there's no need to check within the code valid CSS value for display, it can be checked by FES if necessary.

@rbottura
Copy link
Author

I forked the library to make tests with the 'style' function to go through the _validateParameters() process. That being said I'm having some troubles figuring the impletation of such built-in tools since I'm quite new with the architecture, but I'll get there !
As now, the code looks like this :

p5.Element.prototype.show = function (value) {
  // check if value is a valid value for display prop
  p5._validateParameters('show', arguments);
  //affect const diplayValue either passed-in value, previous value (different from none) or default;
  const displayValue = value || this._prevDisplay || 'revert';
  //apply value to object with p5 style function
  this.style('display', displayValue);
  return this;
};

p5.Element.prototype.hide = function () {
  // Store the current display style if not already set
  this._prevDisplay = this.style('display');
  // use p5 style to hide p5 elt
  this.style('display', 'none');
  return this;
};

This way I think it's more clear that we want to consider that the element we want to .show() had a (visible) display value different from block. If you some1 has advices on how to use _validateParameters on style or show functions would be really helpful !

@limzykenneth
Copy link
Member

_validateParameters works based on the documentation and it may not work correctly for something attached to p5.Element at this stage, you can leave it out for now. In 2.0 we have a new system which we can integrate then.

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

4 participants