Merge commit 'cfc27a384b00388fc1ce30ac47c266ddd1f8e6f1'

This commit is contained in:
Gary Talent 2024-01-28 18:05:09 -06:00
commit f038b89ab4
9 changed files with 156 additions and 9 deletions

View File

@ -13,5 +13,5 @@
#define oxModelBegin(modelName) constexpr ox::Error model(auto *io, [[maybe_unused]] ox::CommonPtrWith<modelName> auto *o) noexcept { oxReturnError(io->template setTypeInfo<modelName>()); #define oxModelBegin(modelName) constexpr ox::Error model(auto *io, [[maybe_unused]] ox::CommonPtrWith<modelName> auto *o) noexcept { oxReturnError(io->template setTypeInfo<modelName>());
#define oxModelEnd() return OxError(0); } #define oxModelEnd() return OxError(0); }
#define oxModelField(fieldName) oxReturnError(io->field(#fieldName, &o->fieldName)); #define oxModelField(fieldName) oxReturnError(io->field(#fieldName, &o->fieldName));
#define oxModelFieldRename(serFieldName, objFieldName) oxReturnError(io->field(#serFieldName, &o->objFieldName)); #define oxModelFieldRename(objFieldName, serFieldName) oxReturnError(io->field(#serFieldName, &o->objFieldName));
#define oxModelFriend(modelName) friend constexpr ox::Error model(auto*, ox::CommonPtrWith<modelName> auto*) noexcept #define oxModelFriend(modelName) friend constexpr ox::Error model(auto*, ox::CommonPtrWith<modelName> auto*) noexcept

View File

@ -221,6 +221,12 @@ class Vector: detail::VectorAllocator<T, Allocator, SmallVectorSize> {
constexpr const T &operator[](std::size_t i) const noexcept; constexpr const T &operator[](std::size_t i) const noexcept;
[[nodiscard]]
constexpr Result<T*> at(size_t i) noexcept;
[[nodiscard]]
constexpr Result<T const*> at(size_t i) const noexcept;
[[nodiscard]] [[nodiscard]]
constexpr Result<T*> front() noexcept; constexpr Result<T*> front() noexcept;
@ -416,6 +422,22 @@ constexpr const T &Vector<T, SmallVectorSize, Allocator>::operator[](std::size_t
return m_items[i]; return m_items[i];
} }
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) noexcept {
if (i < size()) {
return &operator[](i);
}
return OxError(1, "Vector: Invalid index");
}
template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<T const*> Vector<T, SmallVectorSize, Allocator>::at(size_t i) const noexcept {
if (i < size()) {
return &operator[](i);
}
return OxError(1, "Vector: Invalid index");
}
template<typename T, std::size_t SmallVectorSize, typename Allocator> template<typename T, std::size_t SmallVectorSize, typename Allocator>
constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept { constexpr Result<T*> Vector<T, SmallVectorSize, Allocator>::front() noexcept {
if (!m_size) { if (!m_size) {

View File

@ -40,7 +40,7 @@ oxModelBegin(TileSheetClipboard::Pixel)
oxModelEnd() oxModelEnd()
oxModelBegin(TileSheetClipboard) oxModelBegin(TileSheetClipboard)
oxModelFieldRename(pixels, m_pixels) oxModelFieldRename(m_pixels, pixels)
oxModelEnd() oxModelEnd()
class CutPasteCommand: public TileSheetCommand { class CutPasteCommand: public TileSheetCommand {

View File

@ -58,10 +58,10 @@ struct TileDoc {
}; };
oxModelBegin(TileDoc) oxModelBegin(TileDoc)
oxModelFieldRename(subsheet_id, subsheetId) oxModelFieldRename(subsheetId, subsheet_id)
oxModelFieldRename(subsheet_path, subsheetPath) oxModelFieldRename(subsheetPath, subsheet_path)
oxModelField(type) oxModelField(type)
oxModelFieldRename(layer_attachments, layerAttachments) oxModelFieldRename(layerAttachments, layer_attachments)
oxModelEnd() oxModelEnd()
struct SceneDoc { struct SceneDoc {

View File

@ -34,10 +34,10 @@ struct StudioConfig {
}; };
oxModelBegin(StudioConfig) oxModelBegin(StudioConfig)
oxModelFieldRename(active_tab_item_name, activeTabItemName) oxModelFieldRename(activeTabItemName, active_tab_item_name)
oxModelFieldRename(project_path, projectPath) oxModelFieldRename(projectPath, project_path)
oxModelFieldRename(open_files, openFiles) oxModelFieldRename(openFiles, open_files)
oxModelFieldRename(show_project_explorer, showProjectExplorer) oxModelFieldRename(showProjectExplorer, show_project_explorer)
oxModelEnd() oxModelEnd()
StudioUI::StudioUI(studio::StudioContext &ctx, ox::StringView projectDataDir) noexcept: StudioUI::StudioUI(studio::StudioContext &ctx, ox::StringView projectDataDir) noexcept:

View File

@ -131,6 +131,17 @@ class Editor: public studio::BaseEditor {
[[nodiscard]] [[nodiscard]]
UndoStack *undoStack() noexcept final; UndoStack *undoStack() noexcept final;
void pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept;
template<typename UC, typename ...Args>
void pushCommand(Args&&... args) noexcept {
try {
m_undoStack.push(ox::make_unique<UC>(ox::forward<Args>(args)...));
} catch (ox::Exception const&ex) {
oxLogError(ex.toError());
}
}
private: private:
ox::Error markUnsavedChanges(UndoCommand const*) noexcept; ox::Error markUnsavedChanges(UndoCommand const*) noexcept;
}; };

View File

@ -7,6 +7,7 @@
#include <imgui.h> #include <imgui.h>
#include <turbine/context.hpp> #include <turbine/context.hpp>
#include <studio/context.hpp>
namespace studio::ig { namespace studio::ig {
@ -52,4 +53,41 @@ bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, Im
*/ */
bool ComboBox(ox::CStringView lbl, ox::SpanView<ox::String> list, size_t &selectedIdx) noexcept; bool ComboBox(ox::CStringView lbl, ox::SpanView<ox::String> list, size_t &selectedIdx) noexcept;
bool FileComboBox(
ox::CStringView lbl,
studio::StudioContext &sctx,
ox::StringView fileExt,
size_t &selectedIdx) noexcept;
/**
*
* @param name
* @param list
* @param selIdx
* @return true if new value selected, false otherwise
*/
bool ListBox(ox::CStringView name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept;
class FilePicker {
private:
bool m_show{};
studio::StudioContext &m_sctx;
ox::String const m_title;
ox::String const m_fileExt;
ImVec2 const m_size;
public:
ox::Signal<ox::Error(ox::StringView)> filePicked;
FilePicker(
studio::StudioContext &sctx,
ox::String title,
ox::String fileExt,
ImVec2 const&size = {}) noexcept;
void draw() noexcept;
void show() noexcept;
};
} }

View File

@ -127,6 +127,10 @@ ox::CStringView Editor::itemDisplayName() const noexcept {
return m_itemName; return m_itemName;
} }
void Editor::pushCommand(ox::UPtr<UndoCommand> &&cmd) noexcept {
m_undoStack.push(std::move(cmd));
}
UndoStack *Editor::undoStack() noexcept { UndoStack *Editor::undoStack() noexcept {
return &m_undoStack; return &m_undoStack;
} }

View File

@ -92,4 +92,76 @@ bool ComboBox(
return out; return out;
} }
bool FileComboBox(
ox::CStringView lbl,
studio::StudioContext &sctx,
ox::StringView fileExt,
size_t &selectedIdx) noexcept {
auto const&list = sctx.project->fileList(fileExt);
bool out{};
auto const first = selectedIdx < list.size() ? list[selectedIdx].c_str() : "";
if (ImGui::BeginCombo(lbl.c_str(), first, 0)) {
for (auto i = 0u; i < list.size(); ++i) {
const auto selected = (selectedIdx == i);
if (ImGui::Selectable(list[i].c_str(), selected) && selectedIdx != i) {
selectedIdx = i;
out = true;
}
}
ImGui::EndCombo();
}
return out;
}
bool ListBox(ox::CStringView name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept {
auto out = false;
if (ImGui::BeginListBox(name.c_str())) {
for (auto i = 0u; auto const&obj : list) {
ig::IDStackItem const idStackItem2(static_cast<int>(i));
if (ImGui::Selectable(obj.c_str(), selIdx == i)) {
if (i != selIdx) {
selIdx = i;
out = true;
}
}
++i;
}
ImGui::EndListBox();
}
return out;
}
FilePicker::FilePicker(
studio::StudioContext &sctx,
ox::String title,
ox::String fileExt,
ImVec2 const&size) noexcept:
m_sctx(sctx),
m_title(std::move(title)),
m_fileExt(std::move(fileExt)),
m_size(size) {
}
void FilePicker::draw() noexcept {
if (!m_show) {
return;
}
auto constexpr popupSz = ImVec2{450.f, 0};
ig::IDStackItem const idStackItem(m_title.c_str());
if (ig::BeginPopup(m_sctx.tctx, m_title.c_str(), m_show, popupSz)) {
auto const&list = m_sctx.project->fileList(m_fileExt);
size_t selIdx{};
ig::ComboBox(m_title.c_str(), list, selIdx);
if (ig::PopupControlsOkCancel(popupSz.x, m_show) == ig::PopupResponse::OK) {
filePicked.emit(list[selIdx]);
}
ImGui::EndPopup();
}
}
void FilePicker::show() noexcept {
m_show = true;
}
} }