mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibGUI: Set correct value on click with set jump_to_cursor() in Slider
Prior this change, clicking on a slider with set jump_to_cursor() flag didn't exactly match the knob to the mouse position, and therefore the slider values were a bit off in the corners. The calculation used the whole widget size to set new values, which isn't correct as the track slider has margins on both ends. I noticed this while seeking in the Sound Player.
This commit is contained in:
parent
dabbe4ee27
commit
43a800a838
Notes:
sideshowbarker
2024-07-19 17:16:01 +09:00
Author: https://github.com/krkk Commit: https://github.com/SerenityOS/serenity/commit/43a800a8385 Pull-request: https://github.com/SerenityOS/serenity/pull/9759
1 changed files with 2 additions and 2 deletions
|
@ -93,9 +93,9 @@ void Slider::mousedown_event(MouseEvent& event)
|
|||
if (jump_to_cursor()) {
|
||||
float normalized_mouse_offset = 0.0f;
|
||||
if (orientation() == Orientation::Vertical) {
|
||||
normalized_mouse_offset = static_cast<float>(mouse_offset) / static_cast<float>(height());
|
||||
normalized_mouse_offset = static_cast<float>(mouse_offset - track_margin()) / static_cast<float>(inner_rect().height());
|
||||
} else {
|
||||
normalized_mouse_offset = static_cast<float>(mouse_offset) / static_cast<float>(width());
|
||||
normalized_mouse_offset = static_cast<float>(mouse_offset - track_margin()) / static_cast<float>(inner_rect().width());
|
||||
}
|
||||
|
||||
int new_value = static_cast<int>(min() + ((max() - min()) * normalized_mouse_offset));
|
||||
|
|
Loading…
Add table
Reference in a new issue