Is there a way to get the size data of all added circle and square PenTool? #93
Unanswered
PineSongCN
asked this question in
Q&A
Replies: 1 comment 1 reply
-
One method might be to:
For example, import {
Editor, PenTool, Color4, makeOutlinedCircleBuilder, EditorEventType,
} from 'js-draw';
import 'js-draw/styles';
const editor = new Editor(document.body);
editor.addToolbar();
// Create an output element
const penToolSizeList = document.createElement('div');
document.body.appendChild(penToolSizeList);
// [Add PenTools here...]
// Returns a list of all PenTools that create strokes with
// makeOutlinedCircleBuilder.
const allCircleTools = () => {
const toolController = editor.toolController;
const penTools = toolController.getMatchingTools(PenTool);
// Only keep pens that create outlined circles:
return penTools.filter(tool => {
return tool.getStrokeFactory() === makeOutlinedCircleBuilder;
});
};
const updateSizeList = () => {
const sizes = [];
for (const tool of allCircleTools()) {
sizes.push(tool.getThickness());
}
penToolSizeList.textContent = `Sizes: ${sizes.join(',')}`;
};
// Update the output display whenever a tool's style is changed
editor.notifier.on(EditorEventType.ToolUpdated, updateSizeList);
// ...and just after loading the editor
updateSizeList(); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to get the size data of all added circle and square PenTool?Thank you.
Beta Was this translation helpful? Give feedback.
All reactions