-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
Implement EditBoxSlider #238
Conversation
I'm not going to use the widget myself, so I can't give much valuable aestetic feedback. I don't think the slider needs to be bigger though.
This should probably be configurable (with a setTextAlignment function that calls the setAlignment on the edit box). I have no preference for a default value.
For now I would just ignore that a lot of code gets duplicated.
Those constructors are only added when the implicitly-generated constructors aren't sufficient. Ideally they shouldn't be needed anywhere (except for a few places like the Widget and Container base classes). A widget like EditBox for example has no explicit copy constructor because it only contains objects that can be copied (e.g. strings, sprites, rects, integers, ...). SpinControl on the other hand contains an I was going to say that we need some kind of CopiedSharedPtr class, but it turns out that I've already created it. You should check if you can replace |
I've looked into this right now, but I don't think it is feasible. The scrollbar widget lacks functionality that is needed for the slider. For example, one is not able to provide a minimum value, as it is always 0. Furthermore, the value is an unsigned int, so we wouldn't be able to use negative numbers with the
Ah, that's fantastic! I'll implement this then 😄. And thanks very much for the feedback! I'll implement the missing functionality now 👍 |
You're right, I didn't think that one through.
I've had another look at the code, and you actually can't get rid of the constructors. The situation turns out to be very different to widgets with scrollbars. The child widgets exist in two places: inside the m_container and inside the EditBoxSlider as m_editBox and m_slider. Both of these places need to refer to the same widgets. The default copy constructor would cause the ones in the container to be duplicated (which is good), but would leave m_editBox and m_slider in the new EditBoxSlider pointing to the widgets from the original EditBoxSlider. Changing the widgets to use CopiedSharedPtr changes what happens, but still doesn't do what is needed. In that case the default copy constructor would duplicate both the ones in the container and also duplicate the m_editBox and m_slider elements. So you end up with 3 edit boxes: one in the original EditBoxSlider, one in the m_container of the new EditBoxSlider and one in the m_editBox member of the new EditBoxSlider. So a custom copy constructor MUST be written that lets m_editBox and m_slider point to the widget that was duplicated in the container (which is e.g. done in SpinControl with |
All tasks are completed now 🙂. I'll look over the code tomorrow morning again, I wouldn't wonder if some errors were able to slip trough my tiredness 😅. |
I think it's fine to leave it like it is now. If the slider wouldn't move while typing then I would probably suggest resetting to the last value. Since the slider thumb is already moving anyway, it's ok for it to get stuck at the edges when you type something that is out of bounds.
No problem. Many widgets are actually lacking event and/or drawing tests because they are so much work to implement. |
63f98f6
to
7d52b34
Compare
Alright, I'm happy. The PR is now ready to be merged 😄 Although I have one last concern, in
|
There is one inconsistent behavior that I noticed when testing the widget. Suppose the range is 0-10 and the value is 4. Typing a 0 after the 4 will cause the text to change to "10". However, typing another 0 at that point will allow the text to become "100". Personally I don't like that the text changes while typing (I would have preferred the text to be "40" while the internal value is 10), but if the text were to remain "10" while typing additional characters then at least it would be more consistent. So maybe you can have a look if this is something that could be easily improved. If it's hard to do then it can be kept like it is though, it's only a minor detail.
From what I can tell the entire m_textProperties (and m_buttonProperties) property can be removed. I can't find any place where it is used. I believe it's code that remained from before properties where prefixed with Shouldn't the sliderRenderer properties in gui-builder/include/EditBoxSliderProperties.hpp have a "Slider." prefix? (based on what I'm seeing in the SpinControlProperties.hpp file) |
I just improved this behaviour now, by having it be more aligned with how it works with SpinControl. So if you go from 4 to 40, the value stays at 4, but it doesn't go to 10 as it would before. This seemed like the easiest solution to me 🙂. The rest of your feedback is also implemented now! Unfortunately, it seems the change to use the |
839da19
to
116cdb8
Compare
Alright, it's fixed now 🙂. I am still not quite sure, but I assume that the segfault occurred because of a recursive function call. In the code before the fix, on a text change |
The behavior when typing invalid values is a lot better now 👍 |
Addresses #163.
This is a WIP implementation of a widget that allows the user to modify a numerical value through a slider.
I am unsure on some design choices, programming-wise and aesthetic-wise, which is why I put this PR up as a WIP.
Firstly, the design of the widget itself. I am using an
EditBox
and aSlider
in a class deriving fromSubwidgetContainer
. I think the result looks okay, but there is definitely room for improvement. The Slider itself is a little small, and I am unsure if the numerical value should be in the middle of theEditBox
or to the left. It would be nice to hear another opinion on the design first, before I finish it.Secondly, the majority of code I was able to just copy and reimplement from
SpinControl
as it is structured in a very similar way, also being derived fromSubwidgetContainer
. I only had to undertake small changes to account for theSlider
widget being used, and not theSpinButton
. This unfortunately creates a lot of the same structures and functions, which I feel could be put into a new parent class. On the other hand though, this might unnecessarily increase complexity and not even be too necessary, so it'd be great to have an opinion on this as well.Lastly, I am a bit confused on why
SpinControl
uses move and copy constructors whilst other widgets don't. I have implemented the constructors inEditBoxSlider
as well, as I figured they might be necessary here as well (and the save/load test makes use of them, if I am not mistaken). But out of pure interest, why are the other widgets not using these constructors?Tasks still in need of being completed, aside from the asked design questions: