79 const float font = ImGui::GetFontSize();
81 ImGui::GetCursorScreenPos().x + ImGui::GetContentRegionAvail().x;
82 const auto next_control = [inline_controls, right](
float width) {
83 if (inline_controls &&
84 ImGui::GetItemRectMax().x + ImGui::GetStyle().ItemSpacing.x + width <=
88 ImGui::SetNextItemWidth(inline_controls ? width : -1);
90 const auto* selected = Selected(state, scope);
91 const std::string selected_group = selected ? selected->group :
"";
93 selected ? GroupLabel(selected->group) : tr(
"Loaded colors");
95 ImGui::TextUnformatted(tr(
"Preview palette"));
96 ImGui::BeginDisabled(!CanPreview(state));
97 ImGui::SetNextItemWidth(inline_controls ? 11 * font : -1);
98 const bool open = ImGui::BeginCombo(
"##PreviewPalette", label);
101 if (ImGui::Selectable(tr(
"Loaded colors"), !selected))
102 Choose(state, std::nullopt, scope);
104 for (
const auto& group : kGroups) {
105 const auto* palettes =
109 if (!palettes || palettes->empty())
111 if (ImGui::Selectable(tr(group.label), selected_group == group.name)) {
115 "selectable", absl::StrFormat(
"Preview group %s", group.name));
119 ImGui::EndDisabled();
121 selected = Selected(state, scope);
122 if (!selected || !CanPreview(state))
124 auto choice = *selected;
126 if (!resolved.ok()) {
127 ImGui::TextWrapped(
"%s",
128 tr(
"Preview unavailable; choose another palette."));
131 if (resolved->palette_count > 1) {
132 int index = choice.palette;
133 next_control(6 * font);
134 if (ImGui::InputInt(
"##PreviewPaletteIndex", &index)) {
135 choice.palette = std::clamp(index, 0, resolved->palette_count - 1);
137 Choose(state, choice, scope);
141 const auto min = ImGui::GetItemRectMin();
142 const auto max = ImGui::GetItemRectMax();
144 metadata.
label =
"Preview palette index";
145 metadata.
visible = ImGui::IsItemVisible();
146 metadata.
bounds = {min.x, min.y, max.x, max.y,
true};
148 "input:preview_palette_index",
"input",
149 ImGui::GetID(
"##PreviewPaletteIndex"),
"", metadata);
151 "Palette index in the selected group; changes only this preview");
153 if (resolved->row_count > 1) {
154 const auto row_label = absl::StrFormat(
"%s %d/%d", tr(
"Row"),
155 choice.row + 1, resolved->row_count);
157 ImGui::CalcTextSize(row_label.c_str()).x +
158 2 * (ImGui::GetFrameHeight() + ImGui::GetStyle().ItemSpacing.x));
160 ImGui::BeginDisabled(choice.row == 0);
161 const bool previous = ImGui::ArrowButton(
"##RowDown", ImGuiDir_Left);
163 ImGui::EndDisabled();
165 ImGui::TextUnformatted(row_label.c_str());
167 ImGui::BeginDisabled(choice.row + 1 >= resolved->row_count);
168 const bool next = ImGui::ArrowButton(
"##RowUp", ImGuiDir_Right);
170 ImGui::EndDisabled();
171 if (previous || next) {
172 choice.row += next ? 1 : -1;
173 Choose(state, choice, scope);
235 ImGui::TextWrapped(
"%s", tr(
"Showing this sheet's loaded colors. Choose a "
236 "group to preview another palette."));
239 const auto resolved =
243 auto choice = *selected;
244 const auto& palette =
249 ImGui::TextDisabled(tr(
"Preview only; source colors are unchanged"));
250 for (
size_t i = 0; i < palette.size(); ++i) {
251 if (i % layout.colors_per_row != 0)
253 ImGui::PushID(
static_cast<int>(i));
254 if (ImGui::ColorButton(
"##PaletteColor",
256 ImGuiColorEditFlags_NoTooltip, ImVec2(18, 18))) {
257 choice.row =
static_cast<int>(i) / layout.colors_per_row;
260 if (ImGui::IsItemHovered()) {
262 tr(
"Row %d, slot %d: $%04X. Click to preview this row."),
263 static_cast<int>(i) / layout.colors_per_row + 1,
264 static_cast<int>(i) % layout.colors_per_row, palette[i].snes());