Skip to content
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

increment , decrement with mouse drag #2

Closed
wirmachenbunt opened this issue Feb 14, 2019 · 12 comments · Fixed by #50 or #53
Closed

increment , decrement with mouse drag #2

wirmachenbunt opened this issue Feb 14, 2019 · 12 comments · Fixed by #50 or #53

Comments

@wirmachenbunt
Copy link

it would be nice if this library would support numeric controls with mouse drag increment/decrement. similar to how value boxes work in after effects or blend.

so rather than using the mouse wheel, right click into the value box and drag up or down to decrement/ increment.

maybe this is doable ?

could not find any custom control which support that, most just do mouse wheel

keep up the good work

@Dirkster99
Copy link
Owner

Sounds like an interesting idea but I am not sure I get the details right.

I am not sure what you mean by 'how value boxes work in after effects or blend' - I don't know 'after effects' and rarelly use blend. Can you give a specific example or Image screenshot, video to better understand how you would like to increment or decrement via mouse drag?

@wirmachenbunt
Copy link
Author

wirmachenbunt commented Feb 14, 2019

_14 02 2019-15 02 15

in the gif you see me right click and drag up and down to increment/decrement
its a very useful interaction for designing things, since you can combine this with key commands to increment/decrement in smaller or larger steps. that's how after effects values work, or expression blend...pretty much most of the design tools have similar value boxes. none of them use the mouse wheel.

edit: works similar to a endless slider, although you don't see a slider

@wirmachenbunt
Copy link
Author

ezgif com-optimize
AE example

@Dirkster99
Copy link
Owner

I found this CodeProject article about it. It does not seem to be complicated.

I would implement this behavior and add the ability to make the RepeatButton invisible so the control will look like in your screenshot. I would not change the mouse cursor as in the referenced article. What do you think about the article - is that what you want?

@wirmachenbunt
Copy link
Author

yes, i remember the article. but it was from 2007 and in VB. therefore i thought there is maybe a better best practise in 2018/2019 and kept searching for something like that.

hiding the repeatButton would be nice and changing the cursor is not nessecary.

@Dirkster99
Copy link
Owner

CSharp_BlendStyleTextbox.zip

I have translated the VB project to C# to use it as a base of develobment. Just to summarize requirements, we want to:

  • hide/show repeat buttons
  • right click into textbox portion of control and increment/decrement on mouse up/down

right?

@Dirkster99
Copy link
Owner

Dirkster99 commented Feb 17, 2019

I have a first version that works similar to the increment/decrement in blend commited in a seperate Mouse_Inc branch.

See additional handling methods below line 310 in AbstractBaseUpDown.xaml.cs.

This seems to be a little bit more involved than I originally thought.
There are 2 issues I cannot seem to get passed:

  1. Click into text portion of control is no longer possible since the AbstractBaseUpDpwn._PART_TextBox_PreviewMouseDown() method handles the mouse down event in all cases - What I need here is a method that can determine whether a mouse click is taking place (let the click through) or whether a drag event is taking place (handle the event with the _objMouseIncrementor = new MouseIncrementor(e.GetPosition(this), MouseDirections.None); statement.

  2. Mouse Increment and Decrement is limited to the mouse being over the control. I think I can get passed this with CaptureMouse() but I have to review or find a sample on how to do that. I known that AvalonDock makes use of this to drag and drop things around - but thats a complex sample for sure...

Would you know how either of these could be resolved?

@wirmachenbunt
Copy link
Author

i made a valuebox with mouse control in winforms. it handles the mouse delta movement outside of the box. not sure if this is helpful for wpf.

IOBoxValue.zip

concerning the first issue, would it be possible to distinguish between left and right mouse drag, left click is for edit text portion, right click drag is for increment/decrement...

@Dirkster99
Copy link
Owner

Dirkster99 commented Feb 19, 2019

The attached code was not so usefull - I guess WPF is not that similar to WinForms after all. But I was able to solve the two problems mentioned above:

  1. I realized that I can use the MouseUp event to compare the MouseDown X/Y position with the MouseUp X/Y position and set the focus to the textbox if the position was the same...

  2. The mouse capture problem was solved by following the code posted here:
    https://wpf.2000things.com/tag/capturemouse/

The control should now behave exactly like a Blend numeric up/down - you can even hit excape when you are editing to go back to the mouse drag mode.

When testing - I have found only one remaining problem - which is that a control on a previously hidden tab (eg Float) does initially not appear to be in mouse over drag mode. It seems like I am missing some kind of initiallization if the control is constructed with Visibility=Hidden because everything works fine on the first page?

Or, alternatively, the problem has nothing to do with numeric control and is more a problem of the Tab control (maybe focus is still on a hidden Tab)?

Would be good to know a solution to this :-) Anyway, I think its quit good as it is. What do you think?
I also added a IsIncDecButtonsVisible dependency property to show/hide radio buttons.

Would you be able to use the demo app to record a small movie as you attached above? I would love to include a demo movie in the GitHub pages :-)

@wirmachenbunt
Copy link
Author

ezgif-4-80898694f890

this looks pretty good. and yes, concerning the tab focus, this is odd. it only switches to the active tab when using one of the debug controls or edit the box manually. but i never used tabs, so no experience here. one could probably catch the tab switch event and force the focus. probably kinda dirty.

anyway, this helps me a lot. the whole lib should be promoted since this is a very common thing, people look for in wpf. well, it seems that way, reading all the threads all over the internet.

@Dirkster99
Copy link
Owner

I solved the problem with the missing drag mode as well :-) did not think I would but I found at last that I need to schedule the dispatcher in order to loose the initial focus when the visibility on the control changes:
See in LoginControl_IsVisibleChanged in this commit

A side effect of this is that the control cannot gain initial/default keyboard focus - maybe I add another dependency property to let the user configure whether keyboard focus should be gained or lost by default - that way - everyone has a choice in the matter :-)

I'll test a bit more and release to NuGet later this week. Thanks for the recording - I'll add it once this is released.

@Dirkster99
Copy link
Owner

Version 2.2 of the library is out now - it supports incrementing/decrementing values with:

  • mouse drag (left/right and up/down)
  • cursor keys (left/right and up/down)
  • mouse wheel (without and with accelerator key)

supporting 2 different configureable step size dependency properties StepSize and LargeStepSize

Thanks again for the suggestion.
Please let me know if you find issues with this.

As far as promoting the project goes - give it a star if you like it - link to it when you see fit - test and report issues - or even contribute a pull request.... thanx

Dirkster99 added a commit that referenced this issue Oct 20, 2022
Fix #1: FormatString not working with custom texts, Fix #2: Control not scaling correctly with HorizontalAlignment set to "Stretch"
Dirkster99 added a commit that referenced this issue Oct 20, 2022
…ontrol not scaling correctly with HorizontalAlignment set to "Stretch""
Dirkster99 added a commit that referenced this issue Oct 20, 2022
Revert "Fix #1: FormatString not working with custom texts, Fix #2: Control not scaling correctly with HorizontalAlignment set to "Stretch""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment