[studio] Add popup to warn about UUID duplication
This commit is contained in:
@@ -169,7 +169,9 @@ TextInput<ox::IString<MaxChars>> InputText(
|
||||
out.changed = ImGui::InputText(
|
||||
label.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
|
||||
if (out.changed) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -186,7 +188,9 @@ TextInput<ox::IString<MaxChars>> InputTextWithHint(
|
||||
out.changed = ImGui::InputTextWithHint(
|
||||
label.c_str(), hint.c_str(), out.text.data(), MaxChars + 1, flags, callback, user_data);
|
||||
if (out.changed) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = out.text.unsafeResize(ox::strlen(out.text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -201,7 +205,9 @@ bool InputText(
|
||||
auto const out = ImGui::InputText(
|
||||
label.c_str(), text.data(), StrCap + 1, flags, callback, user_data);
|
||||
if (out) {
|
||||
OX_ALLOW_UNSAFE_BUFFERS_BEGIN
|
||||
std::ignore = text.unsafeResize(ox::strlen(text.c_str()));
|
||||
OX_ALLOW_UNSAFE_BUFFERS_END
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -223,6 +229,10 @@ PopupResponse PopupControlsOkCancel(
|
||||
ox::CStringViewCR ok = "OK",
|
||||
ox::CStringViewCR cancel = "Cancel");
|
||||
|
||||
PopupResponse PopupControlsOk(
|
||||
bool &popupOpen,
|
||||
ox::CStringViewCR ok);
|
||||
|
||||
[[nodiscard]]
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0});
|
||||
|
||||
@@ -250,7 +260,7 @@ bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &sele
|
||||
/**
|
||||
*
|
||||
* @param lbl
|
||||
* @param callback
|
||||
* @param f callback function
|
||||
* @param selectedIdx
|
||||
* @return true if new value selected, false otherwise
|
||||
*/
|
||||
@@ -285,7 +295,7 @@ bool ListBox(ox::CStringViewCR name, ox::SpanView<ox::String> const&list, size_t
|
||||
class FilePicker {
|
||||
private:
|
||||
bool m_show{};
|
||||
studio::StudioContext &m_sctx;
|
||||
StudioContext &m_sctx;
|
||||
ox::String const m_title;
|
||||
ox::String const m_fileExt;
|
||||
ImVec2 const m_size;
|
||||
@@ -304,8 +314,8 @@ class FilePicker {
|
||||
|
||||
};
|
||||
|
||||
class QuestionPopup: public Widget {
|
||||
private:
|
||||
class Popup: public Widget {
|
||||
protected:
|
||||
enum class Stage {
|
||||
Closed,
|
||||
Opening,
|
||||
@@ -314,12 +324,11 @@ class QuestionPopup: public Widget {
|
||||
Stage m_stage = Stage::Closed;
|
||||
bool m_open{};
|
||||
ox::String m_title;
|
||||
ox::String m_question;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept;
|
||||
explicit Popup(ox::StringParam title) noexcept;
|
||||
|
||||
void open() noexcept;
|
||||
|
||||
@@ -328,7 +337,33 @@ class QuestionPopup: public Widget {
|
||||
[[nodiscard]]
|
||||
bool isOpen() const noexcept;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept;
|
||||
};
|
||||
|
||||
class QuestionPopup: public Popup {
|
||||
private:
|
||||
ox::String m_question;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
class MessagePopup: public Popup {
|
||||
private:
|
||||
ox::String m_msg;
|
||||
|
||||
public:
|
||||
ox::Signal<ox::Error(PopupResponse)> response;
|
||||
|
||||
MessagePopup(ox::StringParam title, ox::StringParam msg) noexcept;
|
||||
|
||||
void show(ox::StringParam msg) noexcept;
|
||||
|
||||
void draw(StudioContext &ctx) noexcept override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ PopupResponse PopupControlsOk(
|
||||
auto out = PopupResponse::None;
|
||||
constexpr auto btnSz = ImVec2{50, BtnSz.y};
|
||||
ImGui::Separator();
|
||||
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 101);
|
||||
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x - 42);
|
||||
if (ImGui::Button(ok.c_str(), btnSz)) {
|
||||
popupOpen = false;
|
||||
out = PopupResponse::OK;
|
||||
@@ -245,24 +245,28 @@ void FilePicker::show() noexcept {
|
||||
}
|
||||
|
||||
|
||||
QuestionPopup::QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept:
|
||||
m_title{std::move(title)},
|
||||
m_question{std::move(question)} {
|
||||
Popup::Popup(ox::StringParam title) noexcept: m_title{std::move(title)} {
|
||||
}
|
||||
|
||||
void QuestionPopup::open() noexcept {
|
||||
void Popup::open() noexcept {
|
||||
m_stage = Stage::Opening;
|
||||
}
|
||||
|
||||
void QuestionPopup::close() noexcept {
|
||||
void Popup::close() noexcept {
|
||||
m_stage = Stage::Closed;
|
||||
m_open = false;
|
||||
}
|
||||
|
||||
bool QuestionPopup::isOpen() const noexcept {
|
||||
bool Popup::isOpen() const noexcept {
|
||||
return m_open;
|
||||
}
|
||||
|
||||
|
||||
QuestionPopup::QuestionPopup(ox::StringParam title, ox::StringParam question) noexcept:
|
||||
Popup{std::move(title)},
|
||||
m_question{std::move(question)} {
|
||||
}
|
||||
|
||||
void QuestionPopup::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
@@ -298,6 +302,49 @@ void QuestionPopup::draw(StudioContext &ctx) noexcept {
|
||||
}
|
||||
|
||||
|
||||
MessagePopup::MessagePopup(ox::StringParam title, ox::StringParam msg) noexcept:
|
||||
Popup{std::move(title)},
|
||||
m_msg{std::move(msg)} {
|
||||
}
|
||||
|
||||
void MessagePopup::show(ox::StringParam msg) noexcept {
|
||||
m_msg = std::move(msg);
|
||||
open();
|
||||
}
|
||||
|
||||
void MessagePopup::draw(StudioContext &ctx) noexcept {
|
||||
switch (m_stage) {
|
||||
case Stage::Closed:
|
||||
break;
|
||||
case Stage::Opening:
|
||||
ImGui::OpenPopup(m_title.c_str());
|
||||
m_stage = Stage::Open;
|
||||
m_open = true;
|
||||
[[fallthrough]];
|
||||
case Stage::Open:
|
||||
centerNextWindow(ctx.tctx);
|
||||
ImGui::SetNextWindowSize({});
|
||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
if (ImGui::BeginPopupModal(m_title.c_str(), &m_open, modalFlags)) {
|
||||
ImGui::Text("%s", m_msg.c_str());
|
||||
auto const r = PopupControlsOk(m_open, "OK");
|
||||
switch (r) {
|
||||
case PopupResponse::None:
|
||||
break;
|
||||
case PopupResponse::OK:
|
||||
response.emit(r);
|
||||
close();
|
||||
break;
|
||||
case PopupResponse::Cancel:
|
||||
break;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool s_mainWinHasFocus{};
|
||||
bool mainWinHasFocus() noexcept {
|
||||
return s_mainWinHasFocus;
|
||||
|
||||
Reference in New Issue
Block a user