64 const float font = ImGui::GetFontSize();
66 ImGui::GetCursorScreenPos().x + ImGui::GetContentRegionAvail().x;
67 const auto next_control = [inline_controls, right](
float width) {
68 if (inline_controls &&
69 ImGui::GetItemRectMax().x + ImGui::GetStyle().ItemSpacing.x + width <=
73 ImGui::SetNextItemWidth(inline_controls ? width : -1);
76 const std::string selected_group = selected ? selected->
group :
"";
78 selected ? GroupLabel(selected->group) : tr(
"Loaded colors");
80 ImGui::TextUnformatted(tr(
"Preview palette"));
81 ImGui::BeginDisabled(!CanPreview(state));
82 ImGui::SetNextItemWidth(inline_controls ? 11 * font : -1);
83 const bool open = ImGui::BeginCombo(
"##PreviewPalette", label);
86 if (ImGui::Selectable(tr(
"Loaded colors"), !selected))
87 Choose(state, std::nullopt);
89 for (
const auto& group : kGroups) {
90 const auto* palettes =
94 if (!palettes || palettes->empty())
96 if (ImGui::Selectable(tr(group.label), selected_group == group.name)) {
100 "selectable", absl::StrFormat(
"Preview group %s", group.name));
104 ImGui::EndDisabled();
107 if (!selected || !CanPreview(state))
109 auto choice = *selected;
111 if (!resolved.ok()) {
112 ImGui::TextWrapped(
"%s",
113 tr(
"Preview unavailable; choose another palette."));
116 if (resolved->palette_count > 1) {
117 int index = choice.palette;
118 next_control(6 * font);
119 if (ImGui::InputInt(
"##PreviewPaletteIndex", &index)) {
120 choice.palette = std::clamp(index, 0, resolved->palette_count - 1);
122 Choose(state, choice);
126 const auto min = ImGui::GetItemRectMin();
127 const auto max = ImGui::GetItemRectMax();
129 metadata.
label =
"Preview palette index";
130 metadata.
visible = ImGui::IsItemVisible();
131 metadata.
bounds = {min.x, min.y, max.x, max.y,
true};
133 "input:preview_palette_index",
"input",
134 ImGui::GetID(
"##PreviewPaletteIndex"),
"", metadata);
136 "Palette index in the selected group; changes only this preview");
138 if (resolved->row_count > 1) {
139 const auto row_label = absl::StrFormat(
"%s %d/%d", tr(
"Row"),
140 choice.row + 1, resolved->row_count);
142 ImGui::CalcTextSize(row_label.c_str()).x +
143 2 * (ImGui::GetFrameHeight() + ImGui::GetStyle().ItemSpacing.x));
145 ImGui::BeginDisabled(choice.row == 0);
146 const bool previous = ImGui::ArrowButton(
"##RowDown", ImGuiDir_Left);
148 ImGui::EndDisabled();
150 ImGui::TextUnformatted(row_label.c_str());
152 ImGui::BeginDisabled(choice.row + 1 >= resolved->row_count);
153 const bool next = ImGui::ArrowButton(
"##RowUp", ImGuiDir_Right);
155 ImGui::EndDisabled();
156 if (previous || next) {
157 choice.row += next ? 1 : -1;
158 Choose(state, choice);
220 ImGui::TextWrapped(
"%s", tr(
"Showing this sheet's loaded colors. Choose a "
221 "group to preview another palette."));
224 const auto resolved =
228 auto choice = *selected;
229 const auto& palette =
234 ImGui::TextDisabled(tr(
"Preview only; source colors are unchanged"));
235 for (
size_t i = 0; i < palette.size(); ++i) {
236 if (i % layout.colors_per_row != 0)
238 ImGui::PushID(
static_cast<int>(i));
239 if (ImGui::ColorButton(
"##PaletteColor",
241 ImGuiColorEditFlags_NoTooltip, ImVec2(18, 18))) {
242 choice.row =
static_cast<int>(i) / layout.colors_per_row;
245 if (ImGui::IsItemHovered()) {
247 tr(
"Row %d, slot %d: $%04X. Click to preview this row."),
248 static_cast<int>(i) / layout.colors_per_row + 1,
249 static_cast<int>(i) % layout.colors_per_row, palette[i].snes());