Skip to content

Commit

Permalink
feat(formatting): formatted correctly the colors editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskw1999 committed Jun 13, 2024
1 parent 765637c commit 01ca7b1
Showing 1 changed file with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eframe::egui::{ Checkbox, Color32, Image, Slider, TextEdit, TextureHandle, Ui, Vec2 };
use eframe::egui::{Checkbox, Color32, Image, Slider, TextEdit, TextureHandle, Ui, Vec2};
use gamercade_core::Color;

#[derive(Clone, Debug, Default)]
Expand All @@ -14,7 +14,7 @@ impl ColorEditor {
ui: &mut Ui,
current_color: &mut Color,
texture_handle: &TextureHandle,
index: usize
index: usize,
) {
if self.prev_color != *current_color {
self.preview = *current_color;
Expand All @@ -30,14 +30,21 @@ impl ColorEditor {

ui.label(format!("Color index: {index}"));

draw_picker(ui, texture_handle, "Current", false, current_color, &mut current_hex);
draw_picker(
ui,
texture_handle,
"Current",
false,
current_color,
&mut current_hex,
);
draw_picker(
ui,
texture_handle,
"Preview",
true,
&mut self.preview,
&mut self.hex_preview
&mut self.hex_preview,
);

ui.horizontal(|ui| {
Expand All @@ -63,7 +70,7 @@ fn draw_picker(
text: &'static str,
editable: bool,
color: &mut Color,
hex_color: &mut String
hex_color: &mut String,
) {
ui.group(|ui| {
ui.label(text);
Expand All @@ -74,28 +81,43 @@ fn draw_picker(
ui.vertical(|ui| {
ui.horizontal(|ui| {
ui.label("R");
if ui.add_enabled(editable, Slider::new(&mut color.r, 0..=255)).changed() {
if ui
.add_enabled(editable, Slider::new(&mut color.r, 0..=255))
.changed()
{
*hex_color = color.to_hex_string();
}
});

ui.horizontal(|ui| {
ui.label("G");
if ui.add_enabled(editable, Slider::new(&mut color.g, 0..=255)).changed() {
if ui
.add_enabled(editable, Slider::new(&mut color.g, 0..=255))
.changed()
{
*hex_color = color.to_hex_string();
}
});

ui.horizontal(|ui| {
ui.label("B");
if ui.add_enabled(editable, Slider::new(&mut color.b, 0..=255)).changed() {
if ui
.add_enabled(editable, Slider::new(&mut color.b, 0..=255))
.changed()
{
*hex_color = color.to_hex_string();
}
});

ui.horizontal(|ui| {
ui.label("Hex");
if ui.add_enabled(editable, TextEdit::singleline(hex_color).desired_width(64.0)).changed() {
if ui
.add_enabled(
editable,
TextEdit::singleline(hex_color).desired_width(64.0),
)
.changed()
{
let _result = color.update_from_hex_string(hex_color);
}
});
Expand Down

0 comments on commit 01ca7b1

Please sign in to comment.