resolve #21014 by limiting number of ticks#21147
Conversation
modules/highgui/src/window_cocoa.mm
Outdated
| [[slider slider] setMinValue:0]; | ||
| [[slider slider] setNumberOfTickMarks:(max+1)]; | ||
| [[slider slider] setAllowsTickMarkValuesOnly:YES]; | ||
| [[slider slider] setNumberOfTickMarks:(max > 100 ? 101 : max+1)]; |
There was a problem hiding this comment.
Set a limit on the number of TickMarks shown.
modules/highgui/src/window_cocoa.mm
Outdated
| [[slider slider] setNumberOfTickMarks:(max+1)]; | ||
| [[slider slider] setAllowsTickMarkValuesOnly:YES]; | ||
| [[slider slider] setNumberOfTickMarks:(max > 100 ? 101 : max+1)]; | ||
| [[slider slider] setAllowsTickMarkValuesOnly:NO]; |
There was a problem hiding this comment.
Allow selection of values without TickMarks. This is important for situations where there is a large range of values.
|
While it might be nicer to subclass NSSlider and override |
alalek
left a comment
There was a problem hiding this comment.
Need to fix cvSetTrackbarMax() too.
(use max - min instead of max there)
| [[slider slider] setMinValue:0]; | ||
| [[slider slider] setNumberOfTickMarks:(max+1)]; | ||
| [[slider slider] setAllowsTickMarkValuesOnly:YES]; | ||
| [[slider slider] setNumberOfTickMarks:(max > 100 ? 101 : max+1)]; | ||
| [[slider slider] setAllowsTickMarkValuesOnly:NO]; | ||
| if(value) |
There was a problem hiding this comment.
Can we just hide all ticks? (use 0 instead of 101)
[[slider slider] setNumberOfTickMarks:(max > 100 ? 0 : max+1)];
There was a problem hiding this comment.
Yes! I think this is a better solution. You'd mentioned limiting the number of ticks as a preferred solution previously.
No ticks is simpler and solves the problem in a way that's less likely be reverted.
There was a problem hiding this comment.
Actually I mean hiding for case with more than 100 values:
-[[slider slider] setNumberOfTickMarks:(max > 100 ? 101 : max+1)];
+[[slider slider] setNumberOfTickMarks:(max > 100 ? 0 : max+1)];Or
if (max <= 100)
{
[[slider slider] setNumberOfTickMarks:(max+1)];
}
Please take a look on cvSetTrackbarMax() too. We have setNumberOfTickMarks call there too.
[[slider slider] setNumberOfTickMarks:((max - min) > 100 ? 0 : (max - min +1))];
Note: we need to call setNumberOfTickMarks:0 here if we want to hide ticks.
It makes sense to define constant in this file somewhere to avoid using of "magic" number 100 in multiple places (OPENCV_NSSLIDER_MAX_TICKS=100)
There was a problem hiding this comment.
When I search the code, there are no more mentions of setNumberOfTickMarks. Are you looking at a branch other than 4.x?
I will prepare another PR that does this. The behaviour will be a little inconsistent but ok I guess.
| [[slider slider] setMaxValue:max]; | ||
| [[slider slider] setMinValue:0]; | ||
| [[slider slider] setNumberOfTickMarks:(max+1)]; | ||
| [[slider slider] setAllowsTickMarkValuesOnly:YES]; |
There was a problem hiding this comment.
Now no TickMarks will be shown.
|
I believe this will work but I've somehow just run into "ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.". I might need to test it later. |
| @@ -944,8 +944,6 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v | |||
| [[slider name] setStringValue:cvname]; | |||
| [[slider slider] setMaxValue:max]; | |||
| [[slider slider] setMinValue:0]; | |||
There was a problem hiding this comment.
Should this be min?
There was a problem hiding this comment.
I guess this should be a different issue.
There was a problem hiding this comment.
In general yes, it should be min.
In "createSliderWithName", we always have min = 0
There was a problem hiding this comment.
Ah, I see that now.
|
Thinking more about it, what should the behaviour be if someone:
Would then expect the trackbar to change in appearance? I believe it's better to offer a consistent UI in this situation. What do you think @alalek? Also not that on this branch I did not find any other references to Options:
Right now, highgui trackbar with ticks around 10k is unusable on OSX so would love to get something in to restore functionality. |
|
Sometime, on UI creation stage application don't know exact number of required ticks.
I agree with that. It makes sense. As a complete and consistent solution, I would vote for the option 2:
I'm OK with the current PR state which removes ticks at all. |
* remove tickmarks on NSSlider

resolves #21014
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.