[nostalgia/core/studio] Remove unnecessary netsting level in PaletteEditor
This commit is contained in:
parent
ddcb53a535
commit
9ceb1df49e
@ -42,107 +42,105 @@ const ox::String &PaletteEditorImGui::itemDisplayName() const noexcept {
|
|||||||
void PaletteEditorImGui::draw(turbine::Context*) noexcept {
|
void PaletteEditorImGui::draw(turbine::Context*) noexcept {
|
||||||
static constexpr auto flags = ImGuiTableFlags_RowBg;
|
static constexpr auto flags = ImGuiTableFlags_RowBg;
|
||||||
const auto paneSize = ImGui::GetContentRegionAvail();
|
const auto paneSize = ImGui::GetContentRegionAvail();
|
||||||
ImGui::BeginChild("PaletteEditor");
|
ImGui::BeginChild("Colors", ImVec2(paneSize.x - 208, paneSize.y), true);
|
||||||
{
|
{
|
||||||
ImGui::BeginChild("Colors", ImVec2(paneSize.x - 200, paneSize.y), false);
|
const auto colorsSz = ImGui::GetContentRegionAvail();
|
||||||
|
static constexpr auto toolbarHeight = 40;
|
||||||
{
|
{
|
||||||
const auto colorsSz = ImGui::GetContentRegionAvail();
|
const auto sz = ImVec2(70, 24);
|
||||||
static constexpr auto toolbarHeight = 40;
|
if (ImGui::Button("Add", sz)) {
|
||||||
ImGui::BeginChild("Toolbar", ImVec2(colorsSz.x, toolbarHeight), true);
|
const auto colorSz = static_cast<int>(m_pal.colors.size());
|
||||||
|
constexpr Color16 c = 0;
|
||||||
|
undoStack()->push(ox::make<AddColorCommand>(&m_pal, c, colorSz));
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size());
|
||||||
{
|
{
|
||||||
const auto sz = ImVec2(70, 24);
|
if (ImGui::Button("Remove", sz)) {
|
||||||
if (ImGui::Button("Add", sz)) {
|
undoStack()->push(
|
||||||
const auto colorSz = static_cast<int>(m_pal.colors.size());
|
ox::make<RemoveColorCommand>(
|
||||||
constexpr Color16 c = 0;
|
&m_pal,
|
||||||
undoStack()->push(ox::make<AddColorCommand>(&m_pal, c, colorSz));
|
m_pal.colors[static_cast<std::size_t>(m_selectedRow)],
|
||||||
|
static_cast<int>(m_selectedRow)));
|
||||||
|
m_selectedRow = ox::min(m_pal.colors.size() - 1, m_selectedRow);
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size());
|
ImGui::BeginDisabled(m_selectedRow <= 0);
|
||||||
{
|
{
|
||||||
if (ImGui::Button("Remove", sz)) {
|
if (ImGui::Button("Move Up", sz)) {
|
||||||
undoStack()->push(ox::make<RemoveColorCommand>(&m_pal, m_pal.colors[static_cast<std::size_t>(m_selectedRow)], static_cast<int>(m_selectedRow)));
|
undoStack()->push(ox::make<MoveColorCommand>(&m_pal, m_selectedRow, -1));
|
||||||
m_selectedRow = ox::min(m_pal.colors.size() - 1, m_selectedRow);
|
--m_selectedRow;
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
}
|
||||||
ImGui::BeginDisabled(m_selectedRow <= 0);
|
ImGui::EndDisabled();
|
||||||
{
|
ImGui::SameLine();
|
||||||
if (ImGui::Button("Move Up", sz)) {
|
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size() - 1);
|
||||||
undoStack()->push(ox::make<MoveColorCommand>(&m_pal, m_selectedRow, -1));
|
{
|
||||||
--m_selectedRow;
|
if (ImGui::Button("Move Down", sz)) {
|
||||||
}
|
undoStack()->push(ox::make<MoveColorCommand>(&m_pal, m_selectedRow, 1));
|
||||||
|
++m_selectedRow;
|
||||||
}
|
}
|
||||||
ImGui::EndDisabled();
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::BeginDisabled(m_selectedRow >= m_pal.colors.size() - 1);
|
|
||||||
{
|
|
||||||
if (ImGui::Button("Move Down", sz)) {
|
|
||||||
undoStack()->push(ox::make<MoveColorCommand>(&m_pal, m_selectedRow, 1));
|
|
||||||
++m_selectedRow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ImGui::EndDisabled();
|
|
||||||
}
|
}
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndDisabled();
|
||||||
ImGui::BeginTable("Colors", 5, flags, ImVec2(colorsSz.x, colorsSz.y - (toolbarHeight + 5)));
|
|
||||||
{
|
|
||||||
ImGui::TableSetupColumn("Idx", ImGuiTableColumnFlags_WidthFixed, 25);
|
|
||||||
ImGui::TableSetupColumn("Red", ImGuiTableColumnFlags_WidthFixed, 50);
|
|
||||||
ImGui::TableSetupColumn("Green", ImGuiTableColumnFlags_WidthFixed, 50);
|
|
||||||
ImGui::TableSetupColumn("Blue", ImGuiTableColumnFlags_WidthFixed, 50);
|
|
||||||
ImGui::TableSetupColumn("Color Preview", ImGuiTableColumnFlags_NoHide);
|
|
||||||
ImGui::TableHeadersRow();
|
|
||||||
for (auto i = 0u; const auto c : m_pal.colors) {
|
|
||||||
ImGui::PushID(static_cast<int>(i));
|
|
||||||
ImGui::TableNextRow();
|
|
||||||
// Color No.
|
|
||||||
ImGui::TableNextColumn();
|
|
||||||
ImGui::Text("%d", i);
|
|
||||||
// Red
|
|
||||||
ImGui::TableNextColumn();
|
|
||||||
ImGui::Text("%d", red16(c));
|
|
||||||
// Green
|
|
||||||
ImGui::TableNextColumn();
|
|
||||||
ImGui::Text("%d", green16(c));
|
|
||||||
// Blue
|
|
||||||
ImGui::TableNextColumn();
|
|
||||||
ImGui::Text("%d", blue16(c));
|
|
||||||
// ColorPreview
|
|
||||||
ImGui::TableNextColumn();
|
|
||||||
const auto ic = ImGui::GetColorU32(ImVec4(redf(c), greenf(c), bluef(c), 1));
|
|
||||||
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ic);
|
|
||||||
if (ImGui::Selectable("##ColorRow", i == m_selectedRow, ImGuiSelectableFlags_SpanAllColumns)) {
|
|
||||||
m_selectedRow = i;
|
|
||||||
}
|
|
||||||
ImGui::PopID();
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ImGui::EndTable();
|
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::BeginTable("Colors", 5, flags, ImVec2(colorsSz.x, colorsSz.y - (toolbarHeight + 5)));
|
||||||
if (m_selectedRow < m_pal.colors.size()) {
|
{
|
||||||
ImGui::SameLine();
|
ImGui::TableSetupColumn("Idx", ImGuiTableColumnFlags_WidthFixed, 25);
|
||||||
ImGui::BeginChild("ColorEditor", ImVec2(200, paneSize.y), true);
|
ImGui::TableSetupColumn("Red", ImGuiTableColumnFlags_WidthFixed, 50);
|
||||||
{
|
ImGui::TableSetupColumn("Green", ImGuiTableColumnFlags_WidthFixed, 50);
|
||||||
const auto c = m_pal.colors[m_selectedRow];
|
ImGui::TableSetupColumn("Blue", ImGuiTableColumnFlags_WidthFixed, 50);
|
||||||
int r = red16(c);
|
ImGui::TableSetupColumn("Color Preview", ImGuiTableColumnFlags_NoHide);
|
||||||
int g = green16(c);
|
ImGui::TableHeadersRow();
|
||||||
int b = blue16(c);
|
for (auto i = 0u; const auto c : m_pal.colors) {
|
||||||
int a = alpha16(c);
|
ImGui::PushID(static_cast<int>(i));
|
||||||
ImGui::InputInt("Red", &r, 1, 5);
|
ImGui::TableNextRow();
|
||||||
ImGui::InputInt("Green", &g, 1, 5);
|
// Color No.
|
||||||
ImGui::InputInt("Blue", &b, 1, 5);
|
ImGui::TableNextColumn();
|
||||||
const auto newColor = color16(r, g, b, a);
|
ImGui::Text("%d", i);
|
||||||
if (c != newColor) {
|
// Red
|
||||||
undoStack()->push(ox::make<UpdateColorCommand>(&m_pal, static_cast<int>(m_selectedRow), c, newColor));
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text("%d", red16(c));
|
||||||
|
// Green
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text("%d", green16(c));
|
||||||
|
// Blue
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text("%d", blue16(c));
|
||||||
|
// ColorPreview
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
const auto ic = ImGui::GetColorU32(ImVec4(redf(c), greenf(c), bluef(c), 1));
|
||||||
|
ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ic);
|
||||||
|
if (ImGui::Selectable("##ColorRow", i == m_selectedRow, ImGuiSelectableFlags_SpanAllColumns)) {
|
||||||
|
m_selectedRow = i;
|
||||||
}
|
}
|
||||||
|
ImGui::PopID();
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
|
||||||
}
|
}
|
||||||
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
if (m_selectedRow < m_pal.colors.size()) {
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::BeginChild("ColorEditor", ImVec2(200, paneSize.y), true);
|
||||||
|
{
|
||||||
|
const auto c = m_pal.colors[m_selectedRow];
|
||||||
|
int r = red16(c);
|
||||||
|
int g = green16(c);
|
||||||
|
int b = blue16(c);
|
||||||
|
int a = alpha16(c);
|
||||||
|
ImGui::InputInt("Red", &r, 1, 5);
|
||||||
|
ImGui::InputInt("Green", &g, 1, 5);
|
||||||
|
ImGui::InputInt("Blue", &b, 1, 5);
|
||||||
|
const auto newColor = color16(r, g, b, a);
|
||||||
|
if (c != newColor) {
|
||||||
|
undoStack()->push(ox::make<UpdateColorCommand>(&m_pal, static_cast<int>(m_selectedRow), c, newColor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
ox::Error PaletteEditorImGui::saveItem() noexcept {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user