feat(ScrollBar): click-drag support #54

Merged
abart27 merged 1 commit from relative-scrollbar into main 2026-03-01 22:33:20 +00:00
abart27 commented 2026-03-01 22:33:14 +00:00 (Migrated from github.com)
No description provided.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2026-03-01 22:36:41 +00:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull request overview

Adds click-drag behavior to the ScrollBar control by tracking a per-drag offset so the thumb doesn’t “jump” when dragging begins.

Changes:

  • Introduces setup() for scrollbar control state initialization (data.drag_offset).
  • Updates scrollbar drag logic to compute value based on mouse position minus a stored thumb drag offset.
  • Minor formatting change in the returned meta table.
Comments suppressed due to low confidence (2)

src/ugui/controls/scrollbar.lua:27

  • ratio is only type-checked, but the new drag math assumes it’s within a sane range. If ratio <= 0 or ratio > 1, thumb_size becomes invalid and the remap/division logic can misbehave. Consider validating (or clamping) ratio to something like (0, 1] in validate, and handle the ratio == 1 no-scroll case explicitly.
        local thumb_size = is_horizontal
            and control.rectangle.width * control.ratio
            or control.rectangle.height * control.ratio

src/ugui/controls/scrollbar.lua:55

  • Spacing in the returned meta table is inconsistent with the common style used by other controls (e.g., src/ugui/controls/trackbar.lua:34 and src/ugui/controls/joystick.lua:51 use { signal_change = ... }). For consistency/readability, consider restoring the spaces inside the braces here.
            meta = {signal_change = data.signal_change},

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

## Pull request overview Adds click-drag behavior to the `ScrollBar` control by tracking a per-drag offset so the thumb doesn’t “jump” when dragging begins. **Changes:** - Introduces `setup()` for scrollbar control state initialization (`data.drag_offset`). - Updates scrollbar drag logic to compute value based on mouse position minus a stored thumb drag offset. - Minor formatting change in the returned `meta` table. <details> <summary>Comments suppressed due to low confidence (2)</summary> **src/ugui/controls/scrollbar.lua:27** * `ratio` is only type-checked, but the new drag math assumes it’s within a sane range. If `ratio <= 0` or `ratio > 1`, `thumb_size` becomes invalid and the remap/division logic can misbehave. Consider validating (or clamping) `ratio` to something like `(0, 1]` in `validate`, and handle the `ratio == 1` no-scroll case explicitly. ``` local thumb_size = is_horizontal and control.rectangle.width * control.ratio or control.rectangle.height * control.ratio ``` **src/ugui/controls/scrollbar.lua:55** * Spacing in the returned `meta` table is inconsistent with the common style used by other controls (e.g., `src/ugui/controls/trackbar.lua:34` and `src/ugui/controls/joystick.lua:51` use `{ signal_change = ... }`). For consistency/readability, consider restoring the spaces inside the braces here. ``` meta = {signal_change = data.signal_change}, ``` </details> --- 💡 <a href="/mupen64/ugui/new/main?filename=.github/instructions/*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2026-03-01 22:36:41 +00:00

track_length can become 0 (e.g., ratio == 1) or negative (ratio > 1), which makes current_pos / track_length produce nan/inf and then propagate through clamp. Please guard against track_length <= 0 (e.g., keep data.value unchanged and/or force it to 0) before dividing, so dragging can’t generate nan values.

            if track_length > 0 then
                data.value = ugui.internal.clamp(current_pos / track_length, 0, 1)
            end
`track_length` can become 0 (e.g., `ratio == 1`) or negative (`ratio > 1`), which makes `current_pos / track_length` produce `nan`/`inf` and then propagate through `clamp`. Please guard against `track_length <= 0` (e.g., keep `data.value` unchanged and/or force it to 0) before dividing, so dragging can’t generate `nan` values. ```suggestion if track_length > 0 then data.value = ugui.internal.clamp(current_pos / track_length, 0, 1) end ```
Sign in to join this conversation.
No description provided.