-
Notifications
You must be signed in to change notification settings - Fork 24
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
Brush presets #7101
Brush presets #7101
Conversation
@philippotto Some thoughts and questions.
|
… the don't refer to another target element than specified
@dieknolle3333 I think you found a deeper problem in the current event handling. Namely, that the brush can be moved even when the mouse is an another UI (e.g, your popover which is placed above the viewport). I investigated this a bit and think that the
I think, this edge case is okay to ignore for now. You could try to change the |
frontend/javascripts/oxalis/controller/combinations/move_handlers.ts
Outdated
Show resolved
Hide resolved
@philippotto |
const [isBrushSizePopoverOpen, setIsBrushSizePopoverOpen] = useState(false); | ||
const maximumButtonBrushSize = useSelector((state: OxalisState) => getMaximumBrushSize(state)); | ||
const mediumButtonBrushSize = calculateMediumBrushSize(maximumButtonBrushSize); | ||
const minimumButtonBrushSize = Math.max(userSettings.brushSize.minimum, 10); // TODO unsure whether that makes sense across the board |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A brush smaller than 10vx is hardly visible for the dataset I used to test (test-agglomerate-file without zooming in), so I thought this makes sense but wasn't sure.
I'd vote to not add any clamping, because it can be confusing to the user. Especially, when zooming very far in, this would be very unintuitive in my opinion. If the brush size is so small, that one cannot see it, so be it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but would this make sense for the default sizes or should the small preset simply be the smallest size possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understood your question correctly, but I'd change the small brush size preset from 1 to 10 vx, since that is more common in my opinion.
875a1de
to
45e0f77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Looks already very good 👍 I have left some feedback, but nothing major :)
@@ -586,6 +754,10 @@ function ChangeBrushSizeButton() { | |||
); | |||
} | |||
|
|||
function calculateMediumBrushSize(maximumBrushSize: number) { | |||
return Math.ceil((maximumBrushSize - userSettings.brushSize.minimum) / 10) * 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice touch with the rounding to multiples of 5 👍
return [smallBrushSize, mediumBrushSize, largeBrushSize]; | ||
}; | ||
|
||
let maximumBrushSize = useSelector((state: OxalisState) => getMaximumBrushSize(state)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move that above line 560 since it's used in line 561. The current way works technically, because line 562 is executed later than line 567, but I find it cleaner to switch the order.
let smallBrushSize: number, mediumBrushSize: number, largeBrushSize: number; | ||
if (presetBrushSizes.length === 0) { | ||
[smallBrushSize, mediumBrushSize, largeBrushSize] = getDefaultBrushSizes(); | ||
handleUpdatePresetBrushSizes(getDefaultBrushSizes()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a side-effect (since it causes an action dispatch) which should ideally not happen in the normal rendering code. For example, an endless rendering loop could happen if this statement wasn't guarded with a proper if-logic. Currently, it probably works just fine, but it's still cleaner to wrap it with useEffect
. The code would look somewhat like this:
useEffect(() => {
if (presetBrushSizes.length === 0) {
handleUpdatePresetBrushSizes(getDefaultBrushSizes());
}
}, [presetBrushSizes]);
// basically the old code without the handleUpdatePresetBrushSizes:
let smallBrushSize: number, mediumBrushSize: number, largeBrushSize: number;
if (presetBrushSizes.length === 0) {
[smallBrushSize, mediumBrushSize, largeBrushSize] = getDefaultBrushSizes();
} ...
@@ -68,6 +68,7 @@ const defaultState: OxalisState = { | |||
centerNewNode: true, | |||
overrideNodeRadius: true, | |||
particleSize: 5, | |||
presetBrushSizesAsc: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, I'd go with an object because the semantics are way clearer then :) Also, I don't think, that it will result in significantly more code, so there's not really a downside, I'd hope. I'd go with: presetBrushSizes
and {small, medium, large}
then (the keys in the object don't need brushSize
again as the context makes this clear).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, but the keyboard handling code needs to be moved somewhere else :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, let's merge it :)
I just thought, maybe I should quickly add the new shortcuts to the keyboard shortcut docu? If you agree I'll do that :) @philippotto |
Sure, good catch! |
@philippotto can you have a quick look at what I wrote? |
Looks good :) |
Steps to test:
Issues:
-- creates buttons with preset brush sizes
-- renders brush in the center of the active viewport
(Please delete unneeded items, merge only when none are left open)