1
0
Fork 0
freesewing/markdown/dev/reference/api/config/options/en.md
bobgeorgethe3rd 8f72b08f9f
fix(link) Incorrect Link for Couter Page.
Noticed this when trying to look it up. The counter page exists it is just not registered as count so the link needed changing :)

Changes
- Changed link from "count" to "counter"
2022-04-13 22:39:28 +01:00

4.1 KiB

title
options

The design options stored under the options key in the pattern configuration file give designers flexility to make one pattern with different variations.

The use case for (design) options

One of the things that sets FreeSewing apart is that sewing patterns are not static. Each pattern is generated on the spot to accommodate the input provided by the user. Input that typically includes their measurments.

This made-to-measure approach is sort of our thing at FreeSewing, but why stop there? There's a lot of things that can be left up to the user and taken into consideration when drafting the pattern. Things like how many buttons to use, whether or not to include pockets, shape of the collar, and so on. The only limit really is the creativity of the designer.

The options section in a pattern's configuration file is what makes this possible.

The five option types you should know

There are the five option types that an aspiring pattern designer should be familiar with:

  1. boolean options are for yes/no choices
  2. [counter options][counter] are for integer values
  3. degree options are for degrees
  4. list options are for a list of possible choices
  5. percentage options are for percentages

In parametric design, percentage options are by far the most common. They also have the most features and flexibility.

For the sake of completeness, here are the two other types of options:

  1. constant options are used as feature flags
  2. millimeter options are deprecated (in favor of snapped percentage options)

Features all five option types share

The five options types listed above (and the millimeter option to be complete) share the following features:

Default value

Each option has a default value. If the user does not specify a preference the default value is what will be used to draft the pattern.

How you configure the default value depends on the option type

Optionally hide options by configuring a hide() method

This section applies to frontend integration

When you use FreeSewing patterns via the API -- in a backend NodeJS system or on the command line for example -- all options can be used.

The conditional display of options is intended for frontend integration. It is what's used on FreeSewing.org and our development environment alike, but it is not intended as a way to block access to a given option. It merely hides it.

By default options are shown to the user when:

  • They are not a constant option
  • and
  • They are included in an optionGroup

You can further control the optional display of options by adding a method to the hide key under you option, as such:

myOption: {
  pct: 50,
  min: 0,
  max: 100,
  hide: function(settings) {
    if (settings.measurments.chest > 100) return true
    else return false
  }
}

Your hide method will receive one parameter that holds the run-time confguration of your pattern, which we typically refer to as the settings.

It contains among other things all measurements and options chosen by the user. So you can make a choice whether to show the option or not.

If it's not obvious from the name, your hide() method you should:

  • Return true or a truthy value to hide the option
  • Return false or a falsy value to show the option
A hide() method is always present on your option

If you do not specify a hide() method, it will be populated with the default hide() method -- which always returns false thus always showing the option.

In other words, the hide() option is always there and will always get called to determine whether an option should be shown or not.