232 if (!palette_group_result) {
233 ImGui::TextDisabled(
"Invalid palette group");
237 auto palette_group = *palette_group_result;
239 ImGui::TextDisabled(
"Invalid palette index");
245 auto palette_group_name =
247 auto layout = GetPaletteRowLayout(palette_group_name, palette.size());
249 int colors_per_row = layout.colors_per_row;
250 int total_colors =
static_cast<int>(palette.size());
251 int num_rows = GetPaletteRowCount(palette.size(), colors_per_row);
256 for (
int row = 0; row < num_rows; row++) {
257 for (
int col = 0; col < colors_per_row; col++) {
258 int idx = row * colors_per_row + col;
259 if (idx >= total_colors)
265 auto& color = palette[idx];
266 ImVec4 im_color(color.rgb().x / 255.0f, color.rgb().y / 255.0f,
267 color.rgb().z / 255.0f, 1.0f);
270 bool in_sub_palette =
272 std::optional<gui::StyleVarGuard> pal_border_var;
273 std::optional<gui::StyleColorGuard> pal_border_color;
274 if (in_sub_palette) {
275 pal_border_var.emplace(ImGuiStyleVar_FrameBorderSize, 2.0f);
279 std::string
id = absl::StrFormat(
"##PalColor%d", idx);
280 if (ImGui::ColorButton(
id.c_str(), im_color,
281 ImGuiColorEditFlags_NoTooltip, ImVec2(18, 18))) {
287 pal_border_color.reset();
288 pal_border_var.reset();
290 if (ImGui::IsItemHovered()) {
291 ImGui::BeginTooltip();
292 ImGui::Text(
"Index: %d (Row %d, Col %d)", idx, row, col);
293 ImGui::Text(
"SNES: $%04X", color.snes());
294 ImGui::Text(
"RGB: %d, %d, %d",
static_cast<int>(color.rgb().x),
295 static_cast<int>(color.rgb().y),
296 static_cast<int>(color.rgb().z));
303 ImGui::Text(
"Sub-palette Row:");
304 for (
int i = 0; i < std::min(8, num_rows); i++) {
309 std::optional<gui::StyleColorGuard> sel_guard;
313 if (ImGui::SmallButton(absl::StrFormat(
"%d", i).c_str())) {
373 auto palette_group_name =
375 auto palette_group_result =
377 if (!palette_group_result)
380 auto palette_group = *palette_group_result;
385 if (palette.empty()) {
390 if (sheet.is_active() && sheet.surface()) {
391 size_t palette_offset = 0;
392 int palette_length = 0;
393 if (ComputePaletteSlice(palette_group_name, palette,
395 palette_offset, palette_length)) {
396 sheet.SetPaletteWithTransparent(palette, palette_offset, palette_length);
398 sheet.SetPaletteWithTransparent(
399 palette, 0, std::min(7,
static_cast<int>(palette.size())));
409 auto palette_group_name =
411 auto palette_group_result =
413 if (!palette_group_result)
416 auto palette_group = *palette_group_result;
421 if (palette.empty()) {
424 size_t palette_offset = 0;
425 int palette_length = 0;
426 const bool has_slice = ComputePaletteSlice(
428 palette_offset, palette_length);
432 if (sheet.is_active() && sheet.surface()) {
434 sheet.SetPaletteWithTransparent(palette, palette_offset,
437 sheet.SetPaletteWithTransparent(
438 palette, 0, std::min(7,
static_cast<int>(palette.size())));