Skip to content

Color Picker Rewrite - Alpha Slider & Presets, Color Pickers Everywhere!#148

Open
Superkat32 wants to merge 9 commits into
ModFest:26.1from
Superkat32:color-picker-rewrite
Open

Color Picker Rewrite - Alpha Slider & Presets, Color Pickers Everywhere!#148
Superkat32 wants to merge 9 commits into
ModFest:26.1from
Superkat32:color-picker-rewrite

Conversation

@Superkat32

@Superkat32 Superkat32 commented Jul 18, 2026

Copy link
Copy Markdown

Rewrites the ColorPickerWidget from scratch, focusing on reduced repeated code, ease of use(implementation), and maintainability (I hope).


User Facing Changes:
Color Picker Widgets are now available on the following edit screens: Text Block & Properties, Sprite Block, Outline Block, Popup Block, and Note Item.

The Color Picker now has an alpha slider and alpha value presets if the color entry supports an alpha value. Each alpha value preset has some text indicating its hexadecimal value.

Each Color Picker Area (sat/value gradient, hue bar, presets) will be outlined when hovered or dragged. With that, the cursor will only display the pointer if something can be clicked, instead of when over the entire color picker.

The Color Picker is ever so slightly taller now (I think like 8 pixels, only affects preview area & sat/value area).

The Color Picker's hue bar now spans its entire length, instead of being cut off by a few pixels.

The Text Block's edit screen now contains its background color entry, and its "More..." button to open the Properties screen has been replaced with a gear icon.

The Text Block's "Color" and "Background Color" text translation keys have been changed to "Color (ARGB)" and "Background Color (ARGB)" to better indicate the hex code format.

2026-07-17_19 49 36 2026-07-17_20 43 52

General Internal Changes
A new HexColorEditBox widget has been added specifically for color entries. It automatically handles converting between String HEX codes & color integers, and automatically sets any target(e.g. block entity)'s color using the ColorSetter functional interface. It also comes with built in Color Picker support if you give it the Screen's ColorPickerWidget.

The ColorPickerIncludedScreen interface has had multiple methods given default code, including handling rendering, clicking, and key pressing for the ColorPickerWidget, only needing its getColorPickerWidget() method to be implemented. This combined with the HexColorEditBox makes it much easier to include color pickers into new screens.

Added methods for converting to and from HSV and RGB to ColorUtil, and removed all instances of java.awt.Color. The conversion methods were taken from java.awt.Color, and are used in favor of awt's Color class because of some shenanigans with awt's Color class sometimes causing issues for Macs. Ask Falkreon for more info, or see this comment.

Added GuiGraphicsUtil for horizontal gradients, hue gradient, and precise (float position instead of int) texture drawing for GUI extraction. Helps keep the ColorPickerWidget class slightly cleaner :)


Color Picker Internal Changes
The Color Picker has been split up into multiple PickerAreas, which contain positions, boundaries, and ColorSetters for what to do when clicked. Overall, this helps reduce repeated code for checking if the hue bar or sat/value area or anything else was clicked and needing to set their values.

The Color Picker's width and height are practically hard-coded now, instead of attempting some amount of dynamic scaling. With that, presets are now required instead of being toggleable. Both of these makes everything so much simpler and kept me from going insane. I did include comments about how I landed on most of the numbers, though.

The Color Picker now automatically hides itself and handles reverting/undoing color on cancel, instead of leaving those to the widget using Screen.

Removed ColorPresetWidget and the confirm/cancel button's usage of ButtonWidgets in favor of PickerPreset and PickerButton areas (it was so annoying trying to combine widgets and custom stuff lol).

All internal references of a color's brightness have been renamed from "light" to "value." I found out there's a difference, and I believe "value" is more accurate to what we have.

In theory, the Color Picker's render extraction should be slightly more efficient, as it now calculates the positions of everything upon targeting a widget, instead of every render extraction.

A majority of the methods and logic have been simplified I think (more assumptions are made about what logic to default to, like picker position upon target and what to do when a preset is clicked). I think there's like one or two more things here but I can't remember, I spent like 45 minutes writing this lol


Any changes can be made as needed. Thanks!

@Awakened-Redstone
Awakened-Redstone self-requested a review July 18, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant