[studio] Change FilePicker consturctor to take StringParams
This commit is contained in:
parent
fcdcfd10d1
commit
dc07f3d58b
@ -24,7 +24,7 @@ constexpr ImTextureID toImTextureID(ox::Unsigned_c auto id) noexcept
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ox::Result<T> getDragDropPayload(ox::CStringView name) noexcept {
|
||||
ox::Result<T> getDragDropPayload(ox::CStringViewCR name) noexcept {
|
||||
auto const payload = ImGui::AcceptDragDropPayload(name.c_str());
|
||||
if (!payload) {
|
||||
return ox::Error(1, "No drag/drop payload");
|
||||
@ -34,11 +34,7 @@ ox::Result<T> getDragDropPayload(ox::CStringView name) noexcept {
|
||||
static_cast<size_t>(payload->DataSize)});
|
||||
}
|
||||
|
||||
ox::Error setDragDropPayload(ox::CStringView name, auto const&obj) noexcept {
|
||||
oxRequire(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
|
||||
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
|
||||
return {};
|
||||
}
|
||||
ox::Error setDragDropPayload(ox::CStringViewCR name, auto const&obj) noexcept;
|
||||
|
||||
|
||||
class DragDropSource {
|
||||
@ -88,7 +84,7 @@ class DragDropTarget {
|
||||
}
|
||||
};
|
||||
|
||||
inline auto dragDropTarget(auto const&cb) noexcept {
|
||||
auto dragDropTarget(auto const&cb) noexcept {
|
||||
if constexpr(ox::is_same_v<decltype(cb()), ox::Error>) {
|
||||
if (ig::DragDropTarget const tgt; tgt) [[unlikely]] {
|
||||
return cb();
|
||||
@ -104,7 +100,7 @@ inline auto dragDropTarget(auto const&cb) noexcept {
|
||||
|
||||
class ChildStackItem {
|
||||
public:
|
||||
explicit ChildStackItem(ox::CStringView id, ImVec2 const&sz = {}) noexcept;
|
||||
explicit ChildStackItem(ox::CStringViewCR id, ImVec2 const&sz = {}) noexcept;
|
||||
~ChildStackItem() noexcept;
|
||||
};
|
||||
|
||||
@ -112,7 +108,7 @@ class IDStackItem {
|
||||
public:
|
||||
explicit IDStackItem(int id) noexcept;
|
||||
explicit IDStackItem(const char *id) noexcept;
|
||||
explicit IDStackItem(ox::CStringView id) noexcept;
|
||||
explicit IDStackItem(ox::CStringViewCR id) noexcept;
|
||||
~IDStackItem() noexcept;
|
||||
};
|
||||
|
||||
@ -126,7 +122,7 @@ class IndentStackItem {
|
||||
|
||||
void centerNextWindow(turbine::Context &ctx) noexcept;
|
||||
|
||||
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz = BtnSz) noexcept;
|
||||
bool PushButton(ox::CStringViewCR lbl, ImVec2 const&btnSz = BtnSz) noexcept;
|
||||
|
||||
template<typename Str>
|
||||
struct TextInput {
|
||||
@ -180,7 +176,7 @@ 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});
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz = {285, 0});
|
||||
|
||||
/**
|
||||
*
|
||||
@ -199,20 +195,20 @@ bool ComboBox(ox::CStringView lbl, ox::Span<const ox::String> list, size_t &sele
|
||||
* @return true if new value selected, false otherwise
|
||||
*/
|
||||
bool ComboBox(
|
||||
ox::CStringView lbl,
|
||||
ox::CStringViewCR lbl,
|
||||
std::function<ox::CStringView(size_t)> const&f,
|
||||
size_t strCnt,
|
||||
size_t &selectedIdx) noexcept;
|
||||
|
||||
bool FileComboBox(
|
||||
ox::CStringView lbl,
|
||||
studio::StudioContext &sctx,
|
||||
ox::StringView fileExt,
|
||||
ox::CStringViewCR lbl,
|
||||
StudioContext &sctx,
|
||||
ox::StringViewCR fileExt,
|
||||
size_t &selectedIdx) noexcept;
|
||||
|
||||
bool ListBox(
|
||||
ox::CStringView name,
|
||||
std::function<ox::CStringView(size_t)> const&f,
|
||||
ox::CStringViewCR name,
|
||||
std::function<ox::CStringViewCR(size_t)> const&f,
|
||||
size_t strCnt,
|
||||
size_t &selIdx) noexcept;
|
||||
|
||||
@ -223,7 +219,7 @@ bool ListBox(
|
||||
* @param selIdx
|
||||
* @return true if new value selected, false otherwise
|
||||
*/
|
||||
bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t &selIdx) noexcept;
|
||||
bool ListBox(ox::CStringViewCR name, ox::Span<const ox::String> const&list, size_t &selIdx) noexcept;
|
||||
|
||||
class FilePicker {
|
||||
private:
|
||||
@ -237,8 +233,8 @@ class FilePicker {
|
||||
|
||||
FilePicker(
|
||||
studio::StudioContext &sctx,
|
||||
ox::String title,
|
||||
ox::String fileExt,
|
||||
ox::StringParam title,
|
||||
ox::StringParam fileExt,
|
||||
ImVec2 const&size = {}) noexcept;
|
||||
|
||||
void draw() noexcept;
|
||||
|
@ -10,7 +10,14 @@
|
||||
|
||||
namespace studio::ig {
|
||||
|
||||
ChildStackItem::ChildStackItem(ox::CStringView id, ImVec2 const&sz) noexcept {
|
||||
ox::Error setDragDropPayload(ox::CStringViewCR name, auto const&obj) noexcept {
|
||||
oxRequire(buff, ox::writeClaw(obj, ox::ClawFormat::Metal));
|
||||
ImGui::SetDragDropPayload(name.c_str(), buff.data(), buff.size());
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
ChildStackItem::ChildStackItem(ox::CStringViewCR id, ImVec2 const&sz) noexcept {
|
||||
ImGui::BeginChild(id.c_str(), sz);
|
||||
}
|
||||
|
||||
@ -26,7 +33,7 @@ IDStackItem::IDStackItem(const char *id) noexcept {
|
||||
ImGui::PushID(id);
|
||||
}
|
||||
|
||||
IDStackItem::IDStackItem(ox::CStringView id) noexcept: IDStackItem(id.c_str()) {}
|
||||
IDStackItem::IDStackItem(ox::CStringViewCR id) noexcept: IDStackItem(id.c_str()) {}
|
||||
|
||||
IDStackItem::~IDStackItem() noexcept {
|
||||
ImGui::PopID();
|
||||
@ -50,7 +57,7 @@ void centerNextWindow(turbine::Context &ctx) noexcept {
|
||||
ImGui::SetNextWindowPos(ImVec2(screenW / mod, screenH / mod), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
}
|
||||
|
||||
bool PushButton(ox::CStringView lbl, ImVec2 const&btnSz) noexcept {
|
||||
bool PushButton(ox::CStringViewCR lbl, ImVec2 const&btnSz) noexcept {
|
||||
return ImGui::Button(lbl.c_str(), btnSz);
|
||||
}
|
||||
|
||||
@ -77,7 +84,7 @@ PopupResponse PopupControlsOkCancel(bool &popupOpen) {
|
||||
return PopupControlsOkCancel(ImGui::GetContentRegionAvail().x + 17, popupOpen);
|
||||
}
|
||||
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringView popupName, bool &show, ImVec2 const&sz) {
|
||||
bool BeginPopup(turbine::Context &ctx, ox::CStringViewCR popupName, bool &show, ImVec2 const&sz) {
|
||||
constexpr auto modalFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;
|
||||
centerNextWindow(ctx);
|
||||
ImGui::OpenPopup(popupName.c_str());
|
||||
@ -105,7 +112,7 @@ bool ComboBox(
|
||||
}
|
||||
|
||||
bool ComboBox(
|
||||
ox::CStringView lbl,
|
||||
ox::CStringViewCR lbl,
|
||||
std::function<ox::CStringView(size_t)> const&f,
|
||||
size_t strCnt,
|
||||
size_t &selectedIdx) noexcept {
|
||||
@ -125,17 +132,17 @@ bool ComboBox(
|
||||
}
|
||||
|
||||
bool FileComboBox(
|
||||
ox::CStringView lbl,
|
||||
ox::CStringViewCR lbl,
|
||||
StudioContext &sctx,
|
||||
ox::StringView fileExt,
|
||||
ox::StringViewCR fileExt,
|
||||
size_t &selectedIdx) noexcept {
|
||||
auto const&list = sctx.project->fileList(fileExt);
|
||||
return ComboBox(lbl, list, selectedIdx);
|
||||
}
|
||||
|
||||
bool ListBox(
|
||||
ox::CStringView name,
|
||||
std::function<ox::CStringView(size_t)> const&f,
|
||||
ox::CStringViewCR name,
|
||||
std::function<ox::CStringViewCR(size_t)> const&f,
|
||||
size_t strCnt,
|
||||
size_t &selIdx) noexcept {
|
||||
auto out = false;
|
||||
@ -155,7 +162,7 @@ bool ListBox(
|
||||
return out;
|
||||
}
|
||||
|
||||
bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t &selIdx) noexcept {
|
||||
bool ListBox(ox::CStringViewCR name, ox::Span<const ox::String> const&list, size_t &selIdx) noexcept {
|
||||
return ListBox(name, [list](size_t i) -> ox::CStringView {
|
||||
return list[i];
|
||||
}, list.size(), selIdx);
|
||||
@ -164,8 +171,8 @@ bool ListBox(ox::CStringView name, ox::Span<const ox::String> const&list, size_t
|
||||
|
||||
FilePicker::FilePicker(
|
||||
StudioContext &sctx,
|
||||
ox::String title,
|
||||
ox::String fileExt,
|
||||
ox::StringParam title,
|
||||
ox::StringParam fileExt,
|
||||
ImVec2 const&size) noexcept:
|
||||
m_sctx(sctx),
|
||||
m_title(std::move(title)),
|
||||
|
Loading…
Reference in New Issue
Block a user