1
0
Fork 0
freesewing/markdown/dev/tutorials/pattern-design/part2/adding-options/en.md

120 lines
3 KiB
Markdown
Raw Normal View History

---
title: Adding options
2023-09-30 14:04:18 +02:00
order: 40
---
2023-09-28 09:11:06 +02:00
I have shown what our bib should look like, and added the _head_ measurement
to work with. But there's still a number of choices I have to make:
- How large should the neck opening be?
- How wide should the bib be?
- How long should the bib be?
2023-09-28 09:11:06 +02:00
I could make all of these choices for the user and set them in stone, so to speak.
2023-09-28 09:11:06 +02:00
But since the pattern I am designing is code, it is trivial (and _IMHO_ very satisfying)
to make a pattern flexible and let the user choose.
All I need to do to give control to the user is add _options_ to the part.
## Add the neckRatio option
2023-09-28 09:11:06 +02:00
The first option I will add controls the ratio between the neck opening
and the head circumference. Let's call it `neckRatio`.
2023-09-28 09:11:06 +02:00
For this, I will add the `options` property to our `bib` object:
2023-09-30 14:04:18 +02:00
```src/bib.mjs
2023-09-28 09:11:06 +02:00
function draftBib({ part }) => {
return part
}
export const bib = {
2023-09-30 14:04:18 +02:00
name: 'fromscratch.bib',
2023-08-08 13:20:46 -05:00
draft: draftBib,
2023-09-28 09:11:06 +02:00
measurements: [ 'head' ],
2022-10-11 01:37:09 +02:00
// highlight-start
options: {
2023-09-28 09:11:06 +02:00
neckRatio: {
pct: 80,
min: 70,
max: 90,
menu: 'fit'
},
},
2022-10-11 01:37:09 +02:00
// highlight-end
}
```
Can you guess what it means?
2023-09-28 09:11:06 +02:00
- We've added the `options` property to our `bib` object
- On the `options` property, we have added `neckRatio` which holds the configuration for our option
- It is a `pct` option -- whcih means it's a percentage
- Its default value is 90%
- Its minimum value is 70%
- Its maximum value is 90%
2023-09-28 09:11:06 +02:00
There are different types of options, but percentages are by far the most common ones.
They are all documented [in the part reference docs](/reference/api/part/config/options).
<Note>
2023-09-28 09:11:06 +02:00
##### What is `menu` and why should you care?
The `menu` property on our option is *extra*.
It will be ignored by FreeSewing's core library and if we leave it out, our design will produce the same result.
Instead, this `menu` property is there for the benefit FreeSewing's development
environment which will use this to build a menu structure for the various
options.
2023-09-30 14:04:18 +02:00
This is covered in more detail in [Part 3](/tutorials/pattern-design/part3) of this tutorial.
</Note>
## Add the widthRatio and lengthRatio options
Let's do something similar for the width and length of our bib:
2023-09-30 14:04:18 +02:00
```src/bib.mjs
2023-09-28 09:11:06 +02:00
function draftBib({ part }) => {
return part
}
2023-09-28 09:11:06 +02:00
export const bib = {
2023-09-30 14:04:18 +02:00
name: 'fromScratch.bib',
2023-09-28 09:11:06 +02:00
draft: draftBib,
measurements: [ 'head' ],
options: {
neckRatio: {
pct: 80,
min: 70,
max: 90,
menu: 'fit'
},
// highlight-start
widthRatio: {
pct: 45,
min: 35,
max: 55,
menu: 'style'
},
lengthRatio: {
pct: 75,
min: 55,
max: 85,
menu: 'style'
},
// highlight-end
},
}
```
2023-09-28 09:11:06 +02:00
This pretty much the exact same thing, except that are placing this in the `style` menu.
2023-09-28 09:11:06 +02:00
Later, I will test-drive our pattern to see how it behaves when we adapt the options
between their minimum and maximum values. At that time, I may need to tweak these values.
2023-09-28 09:11:06 +02:00
With that out of the way, I will start drawing the bib.