Skip to content

Add a setter and getter for the intensity value of ColorPicker.#1217

Open
Tekkitslime wants to merge 4 commits intoRedot-Engine:masterfrom
Tekkitslime:color_intensity_getset
Open

Add a setter and getter for the intensity value of ColorPicker.#1217
Tekkitslime wants to merge 4 commits intoRedot-Engine:masterfrom
Tekkitslime:color_intensity_getset

Conversation

@Tekkitslime
Copy link

@Tekkitslime Tekkitslime commented Mar 6, 2026

This commit adds a getter and setter for ColorPicker's intensity value. The setter works by setting the intensity through the slider, so that everything updates as expected. This closes Redot-Engine/redot-proposals#117

Summary by CodeRabbit

  • New Features
    • ColorPicker gains an intensity property (default 0.0) to adjust displayed color intensity.
    • Intensity is adjustable via the ColorPicker UI (label, slider, value display) and available in editor/property views and scripts.
    • Input is clamped to the supported range (values outside bounds are limited).

@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

Walkthrough

Adds a new public float property intensity to ColorPicker with getter get_intensity and setter set_intensity, binds the methods, updates the UI controls to expose intensity, and documents the new member in ColorPicker's XML docs.

Changes

Cohort / File(s) Summary
ColorPicker API & UI
scene/gui/color_picker.h, scene/gui/color_picker.cpp
Declare and implement set_intensity(float) and get_intensity(), clamp inputs, bind both in _bind_methods(), register intensity as a FLOAT property, add UI elements and update control refresh logic to show/edit intensity.
Documentation
doc/classes/ColorPicker.xml
Add public member entry for intensity (type="float", getter="get_intensity", setter="set_intensity", default="0.0") in the ColorPicker class documentation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding setter and getter methods for ColorPicker's intensity value, matching the primary objective.
Linked Issues check ✅ Passed The PR implements the core requirement from issue #117: adding getter and setter for ColorPicker's intensity value, enabling programmatic access to the intensity (I) slider exposed in the inspector.
Out of Scope Changes check ✅ Passed All changes are directly related to exposing intensity getter/setter functionality for ColorPicker; no extraneous modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scene/gui/color_picker.cpp`:
- Line 2112: The property registration uses Variant::INT which truncates
fractional values; change the ADD_PROPERTY call for "intensity" to use
Variant::FLOAT so it matches the set_intensity/get_intensity methods and the UI
slider/documentation; update the PropertyInfo in the ADD_PROPERTY(
PropertyInfo(..., "intensity"), "set_intensity", "get_intensity" ) invocation to
Variant::FLOAT to preserve decimals.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b027ec7f-8c56-4ef3-b84c-ebea5235bc2c

📥 Commits

Reviewing files that changed from the base of the PR and between dde68ad and c457c34.

📒 Files selected for processing (3)
  • doc/classes/ColorPicker.xml
  • scene/gui/color_picker.cpp
  • scene/gui/color_picker.h

@Arctis-Fireblight
Copy link
Contributor

Hey Tekk, It looks like it is failing the Unit Tests, I think you will need to update those to account for the new method.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
scene/gui/color_picker.cpp (1)

2114-2114: ⚠️ Potential issue | 🟠 Major

Register intensity as a float property.

set_intensity() and get_intensity() use float, so exposing the property as Variant::INT will truncate fractional values through property/script access.

Suggested fix
-	ADD_PROPERTY(PropertyInfo(Variant::INT, "intensity"), "set_intensity", "get_intensity");
+	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "intensity"), "set_intensity", "get_intensity");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scene/gui/color_picker.cpp` at line 2114, The property is registered as
Variant::INT which truncates fractional values; update the ADD_PROPERTY
registration to use a floating Variant type (Variant::REAL) so the exposed
"intensity" property matches set_intensity/get_intensity (both use float) —
locate the ADD_PROPERTY(PropertyInfo(..., "intensity"), "set_intensity",
"get_intensity") call and change the PropertyInfo's Variant::INT to
Variant::REAL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scene/gui/color_picker.cpp`:
- Around line 2096-2097: The new bindings add script-visible methods
ColorPicker::set_intensity and ColorPicker::get_intensity, so update the
API/unit test baseline that enumerates ColorPicker methods to include these two
entries; locate the test that asserts the class method list or the bindings
snapshot for ColorPicker and add expectations for "set_intensity" and
"get_intensity" (or regenerate the baseline snapshot) so the unit tests reflect
the new API surface.

---

Duplicate comments:
In `@scene/gui/color_picker.cpp`:
- Line 2114: The property is registered as Variant::INT which truncates
fractional values; update the ADD_PROPERTY registration to use a floating
Variant type (Variant::REAL) so the exposed "intensity" property matches
set_intensity/get_intensity (both use float) — locate the
ADD_PROPERTY(PropertyInfo(..., "intensity"), "set_intensity", "get_intensity")
call and change the PropertyInfo's Variant::INT to Variant::REAL.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a17016d6-6c01-4ce2-a97d-647967e2deb5

📥 Commits

Reviewing files that changed from the base of the PR and between c457c34 and 6725804.

📒 Files selected for processing (1)
  • scene/gui/color_picker.cpp

Comment on lines +2096 to +2097
ClassDB::bind_method(D_METHOD("set_intensity", "intensity"), &ColorPicker::set_intensity);
ClassDB::bind_method(D_METHOD("get_intensity"), &ColorPicker::get_intensity);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Please update the API test expectations for the new bindings.

This adds new script-visible methods, and the PR context already notes unit tests are failing. The corresponding API/unit test baseline needs to be updated alongside these bindings.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scene/gui/color_picker.cpp` around lines 2096 - 2097, The new bindings add
script-visible methods ColorPicker::set_intensity and
ColorPicker::get_intensity, so update the API/unit test baseline that enumerates
ColorPicker methods to include these two entries; locate the test that asserts
the class method list or the bindings snapshot for ColorPicker and add
expectations for "set_intensity" and "get_intensity" (or regenerate the baseline
snapshot) so the unit tests reflect the new API surface.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scene/gui/color_picker.cpp`:
- Around line 376-380: set_intensity currently assigns the backing field
directly (intensity) which bypasses the UI control logic and range/coercion done
by the slider/spinbox, so update the setter to route through the existing
control path: either call the shared helper that applies intensity (extract
_normalized_apply_intensity_to_color logic into a new helper and call it from
both set_intensity and _slider_value_changed) or set the slider/spinbox value
programmatically so _slider_value_changed runs; ensure you still call
_update_color afterwards and reference the functions set_intensity,
_normalized_apply_intensity_to_color, _slider_value_changed, and _update_color
when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aac2b3ab-ac18-4509-8bc5-e916ef9bc97e

📥 Commits

Reviewing files that changed from the base of the PR and between 6725804 and 06ea4e3.

📒 Files selected for processing (1)
  • scene/gui/color_picker.cpp

…s min and max bounds, reflect that in the docs.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
doc/classes/ColorPicker.xml (1)

85-87: Document what intensity actually means.

This entry tells users that the property exists, but not how the value maps to the picked color. Since intensity is now script-facing API, it should mirror the semantic explanation already given on edit_intensity, and ideally phrase the clamp note so it does not become a second source of truth if the slider bounds ever change.

📝 Suggested doc update
 		<member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="0.0">
-			The currently selected intensity.
-			Note: [code]set_intensity[/code] clamps the value in the range [code][-10.0, 10.0][/code]
+			The currently selected intensity. This is the same value shown by the intensity slider; it multiplies the color by [code]2 ** intensity[/code] in linear RGB space, and then converts it back to sRGB.
+			[b]Note:[/b] [code]set_intensity()[/code] clamps the value to the intensity slider range (currently [code][-10.0, 10.0][/code]).
 		</member>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@doc/classes/ColorPicker.xml` around lines 85 - 87, The documentation for the
script-facing property intensity is missing semantic meaning and duplicates
clamp bounds; update the <member name="intensity"> docs to explain what
intensity controls (e.g., that it shifts the picked color toward
white/darker/ambient or adjusts brightness/saturation as described by
edit_intensity), mirror the same explanatory text used in edit_intensity, and
replace the hard-coded clamp note with a statement like “value is clamped to the
same range enforced by set_intensity/GUI slider” referencing set_intensity and
the slider rather than repeating numeric bounds so the documentation remains
correct if the slider limits change; ensure get_intensity and set_intensity are
mentioned to indicate how scripts read/write the value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@doc/classes/ColorPicker.xml`:
- Around line 85-87: The documentation for the script-facing property intensity
is missing semantic meaning and duplicates clamp bounds; update the <member
name="intensity"> docs to explain what intensity controls (e.g., that it shifts
the picked color toward white/darker/ambient or adjusts brightness/saturation as
described by edit_intensity), mirror the same explanatory text used in
edit_intensity, and replace the hard-coded clamp note with a statement like
“value is clamped to the same range enforced by set_intensity/GUI slider”
referencing set_intensity and the slider rather than repeating numeric bounds so
the documentation remains correct if the slider limits change; ensure
get_intensity and set_intensity are mentioned to indicate how scripts read/write
the value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 46907370-c805-4128-aa74-2c26904efa6e

📥 Commits

Reviewing files that changed from the base of the PR and between 06ea4e3 and 7225b5f.

📒 Files selected for processing (2)
  • doc/classes/ColorPicker.xml
  • scene/gui/color_picker.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • scene/gui/color_picker.cpp

@Arctis-Fireblight Arctis-Fireblight dismissed their stale review March 14, 2026 22:18

Requested changes were made, review is outdated.

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

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Add getter/setter for intensity on Color

2 participants