[UI] Redesigned "Install Content" window
- Added ID for each ImGui window - Added filesystem::CreateFolder function
This commit is contained in:
committed by
Radosław Gliński
parent
5d5eb03127
commit
56703e52e2
@@ -16,9 +16,12 @@
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
||||
uint64_t ImGuiDialog::next_window_id_ = 0;
|
||||
|
||||
ImGuiDialog::ImGuiDialog(ImGuiDrawer* imgui_drawer)
|
||||
: imgui_drawer_(imgui_drawer) {
|
||||
imgui_drawer_->AddDialog(this);
|
||||
next_window_id_++;
|
||||
}
|
||||
|
||||
ImGuiDialog::~ImGuiDialog() {
|
||||
|
||||
@@ -40,6 +40,7 @@ class ImGuiDialog {
|
||||
ImGuiDrawer* imgui_drawer() const { return imgui_drawer_; }
|
||||
ImGuiIO& GetIO();
|
||||
|
||||
uint64_t GetWindowId() const { return next_window_id_; }
|
||||
// Closes the dialog and returns to any waiters.
|
||||
void Close();
|
||||
|
||||
@@ -48,6 +49,8 @@ class ImGuiDialog {
|
||||
virtual void OnDraw(ImGuiIO& io) {}
|
||||
|
||||
private:
|
||||
static uint64_t next_window_id_;
|
||||
|
||||
ImGuiDrawer* imgui_drawer_ = nullptr;
|
||||
bool has_close_pending_ = false;
|
||||
std::vector<xe::threading::Fence*> waiting_fences_;
|
||||
|
||||
@@ -234,6 +234,25 @@ std::optional<ImGuiKey> ImGuiDrawer::VirtualKeyToImGuiKey(VirtualKey vkey) {
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<ImmediateTexture> ImGuiDrawer::LoadImGuiIcon(
|
||||
std::span<const uint8_t> data) {
|
||||
if (!immediate_drawer_) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int width, height, channels;
|
||||
unsigned char* image_data =
|
||||
stbi_load_from_memory(data.data(), static_cast<int>(data.size()), &width,
|
||||
&height, &channels, STBI_rgb_alpha);
|
||||
if (!image_data) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return immediate_drawer_->CreateTexture(
|
||||
width, height, ImmediateTextureFilter::kLinear, true,
|
||||
reinterpret_cast<uint8_t*>(image_data));
|
||||
}
|
||||
|
||||
std::map<uint32_t, std::unique_ptr<ImmediateTexture>> ImGuiDrawer::LoadIcons(
|
||||
IconsData data) {
|
||||
std::map<uint32_t, std::unique_ptr<ImmediateTexture>> icons_;
|
||||
@@ -242,21 +261,9 @@ std::map<uint32_t, std::unique_ptr<ImmediateTexture>> ImGuiDrawer::LoadIcons(
|
||||
return icons_;
|
||||
}
|
||||
|
||||
int width, height, channels;
|
||||
|
||||
for (const auto& icon : data) {
|
||||
unsigned char* image_data = stbi_load_from_memory(
|
||||
icon.second.data(), static_cast<int>(icon.second.size()), &width,
|
||||
&height, &channels, STBI_rgb_alpha);
|
||||
|
||||
if (!image_data) {
|
||||
continue;
|
||||
}
|
||||
icons_[icon.first] = (immediate_drawer_->CreateTexture(
|
||||
width, height, ImmediateTextureFilter::kLinear, true,
|
||||
reinterpret_cast<uint8_t*>(image_data)));
|
||||
icons_[icon.first] = LoadImGuiIcon(icon.second);
|
||||
}
|
||||
|
||||
return icons_;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ class Window;
|
||||
|
||||
using IconsData = std::map<uint32_t, std::span<const uint8_t>>;
|
||||
|
||||
constexpr ImVec2 default_image_icon_size = ImVec2(75.f, 75.f);
|
||||
|
||||
class ImGuiDrawer : public WindowInputListener, public UIDrawer {
|
||||
public:
|
||||
ImGuiDrawer(Window* window, size_t z_order);
|
||||
@@ -64,6 +66,8 @@ class ImGuiDrawer : public WindowInputListener, public UIDrawer {
|
||||
void ClearDialogs();
|
||||
void EnableNotifications(bool enable) { are_notifications_enabled_ = enable; }
|
||||
|
||||
std::unique_ptr<ImmediateTexture> LoadImGuiIcon(
|
||||
std::span<const uint8_t> data);
|
||||
std::map<uint32_t, std::unique_ptr<ImmediateTexture>> LoadIcons(
|
||||
IconsData data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user