Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color Picker Widget #78

Open
VisenDev opened this issue Jul 29, 2024 · 6 comments
Open

Color Picker Widget #78

VisenDev opened this issue Jul 29, 2024 · 6 comments

Comments

@VisenDev
Copy link
Collaborator

Add support for a specialized color picker widget similar to the following.

Screenshot 2024-07-29 at 11 58 15 AM

.
The current implementation of a basic color picker in src/Example.zig looks like this

// Let's wrap the sliderEntry widget so we have 3 that represent a Color
pub fn rgbSliders(src: std.builtin.SourceLocation, color: *dvui.Color, opts: Options) !void {
    var hbox = try dvui.box(src, .horizontal, opts);
    defer hbox.deinit();

    var red: f32 = @floatFromInt(color.r);
    var green: f32 = @floatFromInt(color.g);
    var blue: f32 = @floatFromInt(color.b);

    _ = try dvui.sliderEntry(@src(), "R: {d:0.0}", .{ .value = &red, .min = 0, .max = 255, .interval = 1 }, .{ .gravity_y = 0.5 });
    _ = try dvui.sliderEntry(@src(), "G: {d:0.0}", .{ .value = &green, .min = 0, .max = 255, .interval = 1 }, .{ .gravity_y = 0.5 });
    _ = try dvui.sliderEntry(@src(), "B: {d:0.0}", .{ .value = &blue, .min = 0, .max = 255, .interval = 1 }, .{ .gravity_y = 0.5 });

    color.r = @intFromFloat(red);
    color.g = @intFromFloat(green);
    color.b = @intFromFloat(blue);
}
@david-vanderson
Copy link
Owner

Oh that would be cool. Can you point me to the place (raylib I assume) that implements that color picker?

@VisenDev
Copy link
Collaborator Author

Can you point me to the place (raylib I assume) that implements that color picker?

The color picker functions are implemented around line 3500 in raygui.h

@VisenDev
Copy link
Collaborator Author

VisenDev commented Aug 3, 2024

After a little experimentation, I have discovered that dvui does have the capability to draw gradient rectangles.

Screenshot_20240803_162749

This is an extremely simple way to do that, but I wanted to verify that it was even possible because I was not really familiar with how renderGeometry worked

@VisenDev
Copy link
Collaborator Author

VisenDev commented Aug 3, 2024

As for the hue selector bar, theoretically the simplest way to do that is just to embed a pregenerated image and use it as the background for a slider.

@david-vanderson
Copy link
Owner

Excellent! That code looks great, let me play around with it a little bit to make sure the function signature feels right to call.

I looked at how raygui does the hue bar - they split the bar into 6 parts and draw a gradient rectangle for each. So that seems like a good strategy.

@VisenDev
Copy link
Collaborator Author

VisenDev commented Aug 4, 2024

Excellent! That code looks great, let me play around with it a little bit to make sure the function signature feels right to call.

Yes, the implementation details and signatures should probably change. I was just interested if renderGeometry even supported this before I started experimenting with the pathFillConvex functions and the like

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

No branches or pull requests

2 participants