Repository: godotengine/godot (language: cpp)

Issue:
Switching to RAW mode and then to RGB will change slider max value until refreshed
### Godot version

4.0 d26442e / 3.5

### System information

Windows 10 x64

### Issue description

When you change to RAW color mode, you can set a slider to some very big value. When you then switch to RGB, that slider will have a different max value. That value will stay until you change color mode again. I think it should switch back to 0-255 range as soon as you change the value to something within that range.
![Z5sEZ3qfr0](https://user-images.githubusercontent.com/2223172/178157048-3e72e7c8-c87d-4d7f-9b6c-5a6163dee756.gif)
(the GIF is from older build)

### Steps to reproduce

1. Have some ColorPicker
2. Change to RAW color mode
3. Set e.g. R to 100
4. Switch back to RGB
5. Set R to 0
6. You can still set R beyond 255

### Minimal reproduction project

_No response_


Discussion / hints:
Is this still reproducible in 4.0 RC 1?
Yes.

Fix patch:
diff --git a/scene/gui/color_mode.cpp b/scene/gui/color_mode.cpp
index 5f58a16d50fe..ccf2d03caa3a 100644
--- a/scene/gui/color_mode.cpp
+++ b/scene/gui/color_mode.cpp
@@ -43,12 +43,6 @@ String ColorModeRGB::get_slider_label(int idx) const {
 	return labels[idx];
 }
 
-float ColorModeRGB::get_slider_max(int idx) const {
-	ERR_FAIL_INDEX_V_MSG(idx, 4, 0, "Couldn't get slider max value.");
-	Color color = color_picker->get_pick_color();
-	return next_power_of_2(MAX(255, color.components[idx] * 255.0)) - 1;
-}
-
 float ColorModeRGB::get_slider_value(int idx) const {
 	ERR_FAIL_INDEX_V_MSG(idx, 4, 0, "Couldn't get slider value.");
 	return color_picker->get_pick_color().components[idx] * 255;
diff --git a/scene/gui/color_mode.h b/scene/gui/color_mode.h
index c035fe6f65a3..4c73967e15fb 100644
--- a/scene/gui/color_mode.h
+++ b/scene/gui/color_mode.h
@@ -46,6 +46,7 @@ class ColorMode {
 	virtual float get_spinbox_arrow_step() const { return get_slider_step(); }
 	virtual String get_slider_label(int idx) const = 0;
 	virtual float get_slider_max(int idx) const = 0;
+	virtual bool get_allow_greater() const { return false; }
 	virtual float get_slider_value(int idx) const = 0;
 
 	virtual Color get_color() const = 0;
@@ -92,7 +93,8 @@ class ColorModeRGB : public ColorMode {
 
 	virtual float get_slider_step() const override { return 1; }
 	virtual String get_slider_label(int idx) const override;
-	virtual float get_slider_max(int idx) const override;
+	virtual float get_slider_max(int idx) const override { return 255; }
+	virtual bool get_allow_greater() const override { return true; }
 	virtual float get_slider_value(int idx) const override;
 
 	virtual Color get_color() const override;
@@ -114,6 +116,7 @@ class ColorModeRAW : public ColorMode {
 	virtual float get_spinbox_arrow_step() const override { return 0.01; }
 	virtual String get_slider_label(int idx) const override;
 	virtual float get_slider_max(int idx) const override;
+	virtual bool get_allow_greater() const override { return true; }
 	virtual float get_slider_value(int idx) const override;
 
 	virtual Color get_color() const override;
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 27539c906456..9f5d1a6dfbf6 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -675,8 +675,9 @@ void ColorPicker::_update_color(bool p_update_sliders) {
 		for (int i = 0; i < current_slider_count; i++) {
 			sliders[i]->set_max(modes[current_mode]->get_slider_max(i));
 			sliders[i]->set_step(step);
-			values[i]->set_custom_arrow_step(spinbox_arrow_step);
 			sliders[i]->set_value(modes[current_mode]->get_slider_value(i));
+			values[i]->set_custom_arrow_step(spinbox_arrow_step);
+			values[i]->set_allow_greater(modes[current_mode]->get_allow_greater());
 		}
 		alpha_slider->set_max(modes[current_mode]->get_slider_max(current_slider_count));
 		alpha_slider->set_step(step);


Test patch: