Refactor: Allow to explicitly set the range on the slider UI element #107406

Merged
Christoph Lendenfeld merged 5 commits from ChrisLend/blender:slider_overshoot_refactor into main 2023-05-05 17:22:46 +02:00

The current implementation goes like this

  • default to a 0-1 range
  • you can set is_bidirectional to get a -1/1 range
  • if the slider is bidirectional the overshoot goes both ways, otherwise only on the positive side

The issue is that it is not possible to have a 0-1 range but overshoot both ways.
This is useful for example on the "Blend to Default" operator, where 0 means current position and 1 default.
But overshoot also makes sense for this operator since the other way just scales away from default.

So this patch:

  • removes is_bidirectional
  • adds float range[2] to tSlider and a setter for it
  • rewrite some logic to handle arbitrary ranges
  • split the allow_overshoot flag into one flag for either side
The current implementation goes like this * default to a 0-1 range * you can set `is_bidirectional` to get a -1/1 range * if the slider is bidirectional the overshoot goes both ways, otherwise only on the positive side The issue is that it is not possible to have a 0-1 range but overshoot both ways. This is useful for example on the "Blend to Default" operator, where 0 means current position and 1 default. But overshoot also makes sense for this operator since the other way just scales away from default. So this patch: * removes `is_bidirectional` * adds `float range[2]` to `tSlider` and a setter for it * rewrite some logic to handle arbitrary ranges * split the `allow_overshoot` flag into one flag for either side
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2023-04-27 18:00:27 +02:00
Christoph Lendenfeld added 1 commit 2023-04-27 18:00:33 +02:00
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-04-27 18:01:10 +02:00
Author
Member

@dr.sybren I had a memory leak with this patch that I cannot reproduce again. The only possible culprit could be the range array, but if I understand correctly, as long as I don't calloc anything I don't need to free either. Is that right?

@dr.sybren I had a memory leak with this patch that I cannot reproduce again. The only possible culprit could be the range array, but if I understand correctly, as long as I don't calloc anything I don't need to free either. Is that right?

@dr.sybren I had a memory leak with this patch that I cannot reproduce again.

Hmm that's annoying. Have you tried with blender --debug-memory? Or the ASAN leak detector?

The only possible culprit could be the range array, but if I understand correctly, as long as I don't calloc anything I don't need to free either. Is that right?

That's correct, a fixed-size array is just allocated in-place.

I'm not sure how I feel about the range[2] though. Setting now requires two lines:

float range[2] = {-1, 1};
ED_slider_range_set(pbd->slider, range);

How would you feel splitting this up into factor_bound_lower and factor_bound_upper? That way we could just
have ED_slider_range_set(pbd->slider, -1, 1);

I was thinking of ..._min/..._max first, but IMO that would be inappropriate given that there's the possibility to overshoot.

As for the overshoot, I have the feeling that the code is now quite tightly coupled to the UI. That's not necessarily a bad thing, given that it's a UI element. What would you think of replacing allow_overshoot_{left,right} with allow_overshoot_{lower,upper}? That way it's in the 'space' of the value that's being manipulated, and the terminology would be the same as the field names for the upper/lower bounds.

> @dr.sybren I had a memory leak with this patch that I cannot reproduce again. Hmm that's annoying. Have you tried with `blender --debug-memory`? Or the ASAN leak detector? > The only possible culprit could be the range array, but if I understand correctly, as long as I don't calloc anything I don't need to free either. Is that right? That's correct, a fixed-size array is just allocated in-place. I'm not sure how I feel about the `range[2]` though. Setting now requires two lines: ```c float range[2] = {-1, 1}; ED_slider_range_set(pbd->slider, range); ``` How would you feel splitting this up into `factor_bound_lower` and `factor_bound_upper`? That way we could just have `ED_slider_range_set(pbd->slider, -1, 1);` I was thinking of `..._min`/`..._max` first, but IMO that would be inappropriate given that there's the possibility to overshoot. As for the overshoot, I have the feeling that the code is now quite tightly coupled to the UI. That's not necessarily a bad thing, given that it's a UI element. What would you think of replacing `allow_overshoot_{left,right}` with `allow_overshoot_{lower,upper}`? That way it's in the 'space' of the value that's being manipulated, and the terminology would be the same as the field names for the upper/lower bounds.
Sybren A. Stüvel requested changes 2023-05-02 11:05:13 +02:00
Sybren A. Stüvel left a comment
Member

Just marking 'request changes' to put the PR into the right queue.

Just marking 'request changes' to put the PR into the right queue.
Christoph Lendenfeld added 2 commits 2023-05-04 10:28:04 +02:00
Author
Member
  • use terminology of lower/upper bounds
  • remove float[2] as parameter and instead use 2 separate floats
* use terminology of lower/upper bounds * remove float[2] as parameter and instead use 2 separate floats
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-05-04 10:31:39 +02:00
Sybren A. Stüvel approved these changes 2023-05-05 12:45:02 +02:00
Sybren A. Stüvel left a comment
Member

👍

:+1:
@ -99,0 +97,4 @@
/* One bool value for each side of the slider. Allows to allow overshoot only on one side. */
void ED_slider_allow_overshoot_set(struct tSlider *slider, bool left, bool right);
void ED_slider_factor_bounds_set(struct tSlider *slider, float lower_bound, float upper_bound);

I think a comment here would be in order, something like:

/**
 * Set the bounds for the slider, which are applied until the user enables overshooting.
 */
void ED_slider_factor_bounds_set(struct tSlider *slider, float lower_bound, float upper_bound);

Just to make it clear what the relation between 'bounds' and 'overshoot' is.

I think a comment here would be in order, something like: ``` /** * Set the bounds for the slider, which are applied until the user enables overshooting. */ void ED_slider_factor_bounds_set(struct tSlider *slider, float lower_bound, float upper_bound); ``` Just to make it clear what the relation between 'bounds' and 'overshoot' is.
Christoph Lendenfeld added 2 commits 2023-05-05 15:35:31 +02:00
Christoph Lendenfeld merged commit c9b51591da into main 2023-05-05 17:22:46 +02:00
Christoph Lendenfeld deleted branch slider_overshoot_refactor 2023-05-05 17:22:47 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:42 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#107406
No description provided.