Skip to content

[GUI] Color slider update and fixes#1997

Open
MrStevns wants to merge 18 commits into
pencil2d:masterfrom
MrStevns:color-slider-update-and-fixes
Open

[GUI] Color slider update and fixes#1997
MrStevns wants to merge 18 commits into
pencil2d:masterfrom
MrStevns:color-slider-update-and-fixes

Conversation

@MrStevns
Copy link
Copy Markdown
Member

@MrStevns MrStevns commented Mar 15, 2026

Slider appearance updates and other fixes.

Before After
before after

Changes

  • Slider has been made bigger to make it easier to adjust.
  • The corners are now properly clipped, leaving no white or black cutouts.
  • Slider now takes devicePixelRatio into account, making it look less pixelated on HiDPI monitors.
  • Picker is now drawn within the slider boundary rather than being drawn on top
  • Picker outline logic has been simplified. We use two outlines to be able to see it on all colors.
  • The cursor position now corresponds to the middle of the picker, rather than shifting closer to the nearest edge as it moves.
  • The color preview now has a checkerboard backdrop again.

Lately i've been rather intrigued by Data Oriented Design, so i'm also introducing some some slider painter utility namespaces. I think that this approach actually works better and is cleaner rather than creating painter classes, when the logic should be shared across components. What do you think?

Note: There is a known issue on macOS.. for some reason the spinboxes gets cut on the top and bottom as if something is squeezing it, however all the layout is set to be "preferred" so it shouldn't be possible. I haven't been able to fix this yet.

- Slider is now bigger
- Picker stays within the slider boundary
- Slider now scales according to HDPI
- Picker is now multi colored, rather than switching color
- The middle of the picker now corresponds to the cursor position, rather than shifting closer to the nearest edge.
What I thought was caused by the device pixel ratio, ended up being me forgetting to compensate for the borderWidth.
Fix quantization issue where the hue slider skipped one value at the end.
Because we already specify the color type, we don't need to specify the min and max from outside, so that has been removed as well
@sonarqubecloud
Copy link
Copy Markdown

chchwy added a commit to chchwy/pencil2d that referenced this pull request Apr 25, 2026
…ressions

- Finding 1 (gradient endpoints): Confirmed PRE-EXISTING, not a PR regression
- Finding 2 (division-by-zero): CRITICAL NEW BUG introduced by refactor
  pickerMaxDistance() lacks guard against zero/negative values
- Other findings: Minor style/cleanup issues
- Build system: Verified correct in qmake and CMake

Blocker: Division-by-zero in colorPicked() must be fixed before merge.
@chchwy chchwy requested review from chchwy and Copilot April 28, 2026 12:50
@chchwy chchwy self-assigned this Apr 28, 2026
@chchwy chchwy added this to the 0.8.0 milestone Apr 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Pencil2D’s color inspector UI rendering by modernizing the ColorSlider painting (bigger, clipped corners, HiDPI-aware, picker drawn inside bounds) and restoring a checkerboard-backed color preview via a dedicated widget, with shared slider drawing/geometry utilities added to core_lib.

Changes:

  • Add reusable slider geometry + style drawing utilities in core_lib/src/util.
  • Rework ColorSlider rendering/caching and picker math (incl. HiDPI pixmap handling).
  • Replace the old palette-based preview with a new ColorPreviewWidget and update the color inspector layout.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
core_lib/src/util/slidergeometry.h New slider geometry helper API.
core_lib/src/util/slidergeometry.cpp Geometry helper implementations.
core_lib/src/util/drawsliderstyle.h New slider style struct + drawing API.
core_lib/src/util/drawsliderstyle.cpp Slider style drawing implementation.
core_lib/core_lib.pro Registers new util sources/headers for qmake build.
app/ui/colorinspector.ui Layout tweaks; swaps preview widget and rearranges controls.
app/src/colorslider.h Uses new util helpers; adjusts slider API and cached state.
app/src/colorslider.cpp New rendering/caching/picker logic + HiDPI pixmap changes.
app/src/colorpreviewwidget.h New widget header for checkerboard-backed preview.
app/src/colorpreviewwidget.cpp Preview widget painting implementation.
app/src/colorinspector.cpp Wires new preview widget; updates slider init + HSV conversion logic.
app/app.pro Registers new preview widget for qmake build.
Comments suppressed due to low confidence (1)

app/src/colorslider.cpp:55

  • QPaintEvent::rect() can be a sub-rectangle during partial updates; creating the backing pixmap from event->rect().size() can produce a pixmap smaller than the widget, and then drawPixmap(0, 0, ...) will leave the rest undrawn. Build the cache from the full widget size (e.g. this->size()/rect().size()) and use the paint event rect only for clipping if needed.
void ColorSlider::paintEvent(QPaintEvent* event)
{
    drawColorBox(mColor, event->rect().size());

    QPainter painter(this);
    painter.drawPixmap(0, 0, mBoxPixmapSource);
    painter.end();

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

Comment thread app/src/colorslider.cpp
Comment thread app/src/colorpreviewwidget.h
Comment thread core_lib/core_lib.pro
Comment thread core_lib/src/util/drawsliderstyle.h Outdated
Comment thread core_lib/src/util/drawsliderstyle.cpp Outdated
Comment thread app/src/colorslider.cpp
Comment thread app/src/colorslider.cpp Outdated
Comment thread app/app.pro
Comment thread core_lib/src/util/slidergeometry.h Outdated
Comment thread core_lib/src/util/drawsliderstyle.cpp Outdated
@MrStevns MrStevns force-pushed the color-slider-update-and-fixes branch from 3358772 to 898035a Compare April 28, 2026 18:12
@MrStevns
Copy link
Copy Markdown
Member Author

All review comments have now been addressed

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

3 participants