Squashed 'deps/nostalgia/' changes from ab025e88..4d63a65f
4d63a65f [nostalgia/core/studio] Show Palette page names in TileSheetEditor 686db99d [nostalgia/core/studio] Disable Palette page hotkeys when Rename popup is open 52533c8c [nostalgia/core/studio] Add Palette page names to editor ba4540e4 [ox/std] Add IString::unsafeResize 36057bb0 [nostalgia/core/studio] Fix Clang build 1a2b2b8b [nostalgia/core] Add PaletteV4, with support for page names, make PaletteColor object 6189193a [nostalgia] Add NFDE install 67a10d35 [nostalgia/sample_project] Update type descriptor git-subtree-dir: deps/nostalgia git-subtree-split: 4d63a65fbde480235edd961e5cd19d8b4de1b66d
This commit is contained in:
@@ -18,7 +18,7 @@ struct StudioContext {
|
||||
StudioUI &ui;
|
||||
Project *project = nullptr;
|
||||
turbine::Context &tctx;
|
||||
inline StudioContext(StudioUI &pUi, turbine::Context &pTctx) noexcept:
|
||||
StudioContext(StudioUI &pUi, turbine::Context &pTctx) noexcept:
|
||||
ui(pUi), tctx(pTctx) {}
|
||||
};
|
||||
|
||||
|
@@ -45,10 +45,10 @@ class DragDropSource {
|
||||
private:
|
||||
bool const m_active{};
|
||||
public:
|
||||
inline DragDropSource() noexcept:
|
||||
DragDropSource() noexcept:
|
||||
m_active(ImGui::BeginDragDropSource()) {
|
||||
}
|
||||
inline ~DragDropSource() noexcept {
|
||||
~DragDropSource() noexcept {
|
||||
if (m_active) {
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class DragDropSource {
|
||||
}
|
||||
};
|
||||
|
||||
inline auto dragDropSource(auto const&cb) noexcept {
|
||||
auto dragDropSource(auto const&cb) noexcept {
|
||||
if constexpr(ox::is_same_v<decltype(cb()), ox::Error>) {
|
||||
if (ig::DragDropSource const tgt; tgt) [[unlikely]] {
|
||||
return cb();
|
||||
@@ -75,10 +75,10 @@ class DragDropTarget {
|
||||
private:
|
||||
bool const m_active{};
|
||||
public:
|
||||
inline DragDropTarget() noexcept:
|
||||
DragDropTarget() noexcept:
|
||||
m_active(ImGui::BeginDragDropTarget()) {
|
||||
}
|
||||
inline ~DragDropTarget() noexcept {
|
||||
~DragDropTarget() noexcept {
|
||||
if (m_active) {
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
@@ -128,6 +128,21 @@ void centerNextWindow(turbine::Context &ctx) noexcept;
|
||||
|
||||
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept;
|
||||
|
||||
template<size_t StrCap>
|
||||
bool InputText(
|
||||
ox::CStringView label,
|
||||
ox::IString<StrCap> &text,
|
||||
ImGuiInputTextFlags const flags = 0,
|
||||
ImGuiInputTextCallback const callback = nullptr,
|
||||
void *user_data = nullptr) noexcept {
|
||||
auto const out = ImGui::InputText(
|
||||
label.c_str(), text.data(), StrCap + 1, flags, callback, user_data);
|
||||
if (out) {
|
||||
std::ignore = text.unsafeResize(ox::strlen(text.c_str()));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
enum class PopupResponse {
|
||||
None,
|
||||
OK,
|
||||
@@ -136,6 +151,8 @@ enum class PopupResponse {
|
||||
|
||||
PopupResponse PopupControlsOkCancel(float popupWidth, bool &popupOpen);
|
||||
|
||||
PopupResponse PopupControlsOkCancel(bool &popupOpen);
|
||||
|
||||
[[nodiscard]]
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz = {285, 0});
|
||||
|
||||
|
@@ -73,9 +73,13 @@ PopupResponse PopupControlsOkCancel(float popupWidth, bool &popupOpen) {
|
||||
return out;
|
||||
}
|
||||
|
||||
PopupResponse PopupControlsOkCancel(bool &popupOpen) {
|
||||
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen);
|
||||
}
|
||||
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz) {
|
||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
ig::centerNextWindow(ctx);
|
||||
centerNextWindow(ctx);
|
||||
ImGui::OpenPopup(popupName.c_str());
|
||||
ImGui::SetNextWindowSize(sz);
|
||||
return ImGui::BeginPopupModal(popupName.c_str(), &show, modalFlags);
|
||||
@@ -122,23 +126,11 @@ bool ComboBox(
|
||||
|
||||
bool FileComboBox(
|
||||
ox::CStringView lbl,
|
||||
studio::StudioContext &sctx,
|
||||
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;
|
||||
return ComboBox(lbl, list, selectedIdx);
|
||||
}
|
||||
|
||||
bool ListBox(
|
||||
@@ -164,14 +156,14 @@ bool ListBox(
|
||||
}
|
||||
|
||||
bool ListBox(ox::CStringView name, ox::SpanView<ox::String> const&list, size_t &selIdx) noexcept {
|
||||
return ig::ListBox(name, [list](size_t i) -> ox::CStringView {
|
||||
return ListBox(name, [list](size_t i) -> ox::CStringView {
|
||||
return list[i];
|
||||
}, list.size(), selIdx);
|
||||
}
|
||||
|
||||
|
||||
FilePicker::FilePicker(
|
||||
studio::StudioContext &sctx,
|
||||
StudioContext &sctx,
|
||||
ox::String title,
|
||||
ox::String fileExt,
|
||||
ImVec2 const&size) noexcept:
|
||||
@@ -186,12 +178,12 @@ void FilePicker::draw() noexcept {
|
||||
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)) {
|
||||
IDStackItem const idStackItem(m_title);
|
||||
if (BeginPopup(m_sctx.tctx, m_title, 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) {
|
||||
ComboBox(m_title, list, selIdx);
|
||||
if (PopupControlsOkCancel(popupSz.x, m_show) == ig::PopupResponse::OK) {
|
||||
filePicked.emit(list[selIdx]);
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
|
Reference in New Issue
Block a user