Update imgui 1.91.3 -> 1.92.1
This commit is contained in:
+39
-139
@@ -382,46 +382,9 @@ imgui_context::imgui_context(vk::raii::PhysicalDevice physical_device, vk::raii:
|
||||
style.Colors[ImGuiCol_ModalWindowDimBg] = {0, 0, 0, 0};
|
||||
}
|
||||
|
||||
void imgui_context::add_chars(std::string_view sv)
|
||||
{
|
||||
for (auto it = sv.begin(); it != sv.end();)
|
||||
{
|
||||
ImWchar c = (ImWchar)*it;
|
||||
if (c < 0x80)
|
||||
++it;
|
||||
else
|
||||
it += ImTextCharFromUtf8(&c, it, sv.end());
|
||||
|
||||
if (!glyph_range_builder.GetBit(c))
|
||||
{
|
||||
glyph_range_builder.AddChar(c);
|
||||
glyph_range_dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
static std::vector<std::string> find_font(const ImFontGlyphRangesBuilder & glyph_range_builder, const std::string & locale)
|
||||
static std::vector<std::string> find_font(std::u16string_view sample_text, const std::string & locale)
|
||||
{
|
||||
std::u16string wtext;
|
||||
std::u16string_view wtextview;
|
||||
for (int i = 0; i < glyph_range_builder.UsedChars.Size; ++i)
|
||||
{
|
||||
std::uint32_t used_chars = glyph_range_builder.UsedChars[i];
|
||||
if (used_chars == 0)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < 32; ++j)
|
||||
{
|
||||
ImWchar c = i * 32 + j;
|
||||
if (used_chars & (1 << j))
|
||||
{
|
||||
wtext += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
wtextview = wtext;
|
||||
|
||||
AFontMatcher * font_matcher = AFontMatcher_create();
|
||||
if (!font_matcher)
|
||||
throw std::runtime_error("AFontMatcher_create");
|
||||
@@ -432,18 +395,18 @@ static std::vector<std::string> find_font(const ImFontGlyphRangesBuilder & glyph
|
||||
|
||||
std::vector<std::string> fonts;
|
||||
|
||||
while (!wtextview.empty())
|
||||
while (!sample_text.empty())
|
||||
{
|
||||
uint32_t runlength = 0;
|
||||
|
||||
AFont * font = AFontMatcher_match(font_matcher, "sans-serif", (uint16_t *)wtextview.data(), wtextview.size(), &runlength);
|
||||
AFont * font = AFontMatcher_match(font_matcher, "sans-serif", (uint16_t *)sample_text.data(), sample_text.size(), &runlength);
|
||||
fonts.emplace_back(AFont_getFontFilePath(font));
|
||||
AFont_close(font);
|
||||
|
||||
if (runlength == 0)
|
||||
break;
|
||||
|
||||
wtextview = wtextview.substr(runlength);
|
||||
sample_text = sample_text.substr(runlength);
|
||||
}
|
||||
|
||||
AFontMatcher_destroy(font_matcher);
|
||||
@@ -451,7 +414,7 @@ static std::vector<std::string> find_font(const ImFontGlyphRangesBuilder & glyph
|
||||
return fonts;
|
||||
}
|
||||
#else
|
||||
static std::vector<std::string> find_font(ImFontGlyphRangesBuilder glyph_range_builder, const std::string & locale)
|
||||
static std::vector<std::string> find_font(std::u16string sample_text, const std::string & locale)
|
||||
{
|
||||
// See https://www.camconn.cc/post/how-to-fontconfig-lib-c/
|
||||
|
||||
@@ -470,21 +433,8 @@ static std::vector<std::string> find_font(ImFontGlyphRangesBuilder glyph_range_b
|
||||
// Add the text to the pattern (to determine appropriate characters)
|
||||
FcCharSet * charset = FcCharSetCreate();
|
||||
|
||||
for (int i = 8; i < glyph_range_builder.UsedChars.Size; ++i)
|
||||
{
|
||||
std::uint32_t used_chars = glyph_range_builder.UsedChars[i];
|
||||
if (used_chars == 0)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < 32; ++j)
|
||||
{
|
||||
ImWchar c = i * 32 + j;
|
||||
if (used_chars & (1 << j))
|
||||
{
|
||||
FcCharSetAddChar(charset, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (char16_t c: sample_text)
|
||||
FcCharSetAddChar(charset, c);
|
||||
|
||||
FcPatternAddCharSet(pattern, FC_CHARSET, charset);
|
||||
FcCharSetDestroy(charset);
|
||||
@@ -513,28 +463,26 @@ static std::vector<std::string> find_font(ImFontGlyphRangesBuilder glyph_range_b
|
||||
continue;
|
||||
|
||||
bool keep_this_font = false;
|
||||
for (int i = 0; i < glyph_range_builder.UsedChars.Size; ++i)
|
||||
{
|
||||
std::uint32_t & used_chars = glyph_range_builder.UsedChars[i];
|
||||
if (used_chars == 0)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < 32; ++j)
|
||||
std::u16string tmp = sample_text;
|
||||
for (int i = 0; i < tmp.size();)
|
||||
{
|
||||
char16_t c = tmp[i];
|
||||
|
||||
if (FcCharSetHasChar(font_charset, c))
|
||||
{
|
||||
ImWchar c = i * 32 + j;
|
||||
if (used_chars & (1 << j))
|
||||
{
|
||||
if (FcCharSetHasChar(font_charset, c))
|
||||
{
|
||||
keep_this_font = true;
|
||||
used_chars &= ~(1 << j);
|
||||
}
|
||||
}
|
||||
keep_this_font = true;
|
||||
|
||||
tmp[i] = tmp[tmp.size() - 1];
|
||||
tmp.resize(tmp.size() - 1);
|
||||
}
|
||||
else
|
||||
++i;
|
||||
}
|
||||
|
||||
if (keep_this_font)
|
||||
fonts.emplace_back((const char *)font_file);
|
||||
break;
|
||||
}
|
||||
|
||||
FcFontSetDestroy(fs);
|
||||
@@ -546,29 +494,19 @@ static std::vector<std::string> find_font(ImFontGlyphRangesBuilder glyph_range_b
|
||||
|
||||
void imgui_context::initialize_fonts()
|
||||
{
|
||||
glyph_ranges.clear();
|
||||
std::u16string sample_text = u"Hello world";
|
||||
|
||||
// Always include Basic Latin and Latin-1 Supplement without control characters
|
||||
ImWchar default_ranges[] = {0x20, 0x7f, 0xa0, 0xff, 0};
|
||||
glyph_range_builder.AddRanges(default_ranges);
|
||||
const auto & locale = application::get_messages_info();
|
||||
auto it = glyph_set_per_language.find(locale.language + "_" + locale.country);
|
||||
if (it == glyph_set_per_language.end())
|
||||
it = glyph_set_per_language.find(locale.language);
|
||||
|
||||
{
|
||||
const auto & locale = application::get_messages_info();
|
||||
auto it = glyph_set_per_language.find(locale.language + "_" + locale.country);
|
||||
if (it == glyph_set_per_language.end())
|
||||
it = glyph_set_per_language.find(locale.language);
|
||||
|
||||
if (it != glyph_set_per_language.end())
|
||||
{
|
||||
for (ImWchar c: it->second)
|
||||
glyph_range_builder.AddChar(c);
|
||||
}
|
||||
}
|
||||
|
||||
glyph_range_builder.BuildRanges(&glyph_ranges);
|
||||
if (it != glyph_set_per_language.end())
|
||||
for (char16_t c: it->second)
|
||||
sample_text += c;
|
||||
|
||||
// Load Fonts
|
||||
auto fonts = find_font(glyph_range_builder, application::get_messages_info().language);
|
||||
auto fonts = find_font(sample_text, application::get_messages_info().language);
|
||||
for (auto & i: fonts)
|
||||
{
|
||||
spdlog::info("Font {}", i);
|
||||
@@ -577,40 +515,20 @@ void imgui_context::initialize_fonts()
|
||||
asset font_awesome_regular("Font Awesome 6 Free-Regular-400.otf");
|
||||
asset font_awesome_solid("Font Awesome 6 Free-Solid-900.otf");
|
||||
|
||||
IM_DELETE(io.Fonts);
|
||||
io.Fonts = IM_NEW(ImFontAtlas);
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
|
||||
for (auto & font: fonts)
|
||||
{
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
|
||||
for (auto & font: fonts)
|
||||
{
|
||||
spdlog::info("Using font {}", font, application::get_messages_info().language);
|
||||
io.Fonts->AddFontFromFileTTF(font.c_str(), constants::gui::font_size_small, &config, glyph_ranges.Data);
|
||||
config.MergeMode = true;
|
||||
}
|
||||
|
||||
spdlog::info("Using font {}", font, application::get_messages_info().language);
|
||||
io.Fonts->AddFontFromFileTTF(font.c_str(), constants::gui::font_size_small, &config);
|
||||
config.MergeMode = true;
|
||||
config.GlyphMinAdvanceX = 40; // Use if you want to make the icon monospaced
|
||||
static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(font_awesome_regular.data()), font_awesome_regular.size(), constants::gui::font_size_small, &config, icon_ranges);
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(font_awesome_solid.data()), font_awesome_solid.size(), constants::gui::font_size_small, &config, icon_ranges);
|
||||
}
|
||||
|
||||
{
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
for (auto & font: fonts)
|
||||
{
|
||||
large_font = io.Fonts->AddFontFromFileTTF(font.c_str(), constants::gui::font_size_large, &config, glyph_ranges.Data);
|
||||
config.MergeMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
glyph_range_dirty = false;
|
||||
|
||||
ImGui_ImplVulkan_CreateFontsTexture();
|
||||
config.MergeMode = true;
|
||||
config.GlyphMinAdvanceX = 40; // Use if you want to make the icon monospaced
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(font_awesome_regular.data()), font_awesome_regular.size(), constants::gui::font_size_small, &config);
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(font_awesome_solid.data()), font_awesome_solid.size(), constants::gui::font_size_small, &config);
|
||||
}
|
||||
|
||||
std::vector<imgui_context::controller_state> imgui_context::read_controllers_state(XrTime display_time)
|
||||
@@ -844,24 +762,6 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
controller.second = next_state;
|
||||
}
|
||||
|
||||
// Force recreation of the font atlas
|
||||
if (glyph_range_dirty)
|
||||
{
|
||||
// Wait for fences before ImGui_ImplVulkan_DestroyFontsTexture is called
|
||||
std::vector<vk::Fence> fences;
|
||||
for (auto & f: command_buffers)
|
||||
{
|
||||
fences.push_back(*f.fence);
|
||||
}
|
||||
|
||||
if (auto result = device.waitForFences(fences, true, 1'000'000'000); result != vk::Result::eSuccess)
|
||||
spdlog::error("vkWaitForfences: {}", vk::to_string(result));
|
||||
|
||||
ImGui_ImplVulkan_DestroyFontsTexture();
|
||||
initialize_fonts();
|
||||
ImGui_ImplVulkan_CreateFontsTexture();
|
||||
}
|
||||
|
||||
// Start the Dear ImGui frame
|
||||
ImGui_ImplVulkan_NewFrame();
|
||||
|
||||
@@ -1143,7 +1043,7 @@ ImTextureID imgui_context::load_texture(const std::string & filename, vk::raii::
|
||||
|
||||
device.updateDescriptorSets(ds_write, nullptr);
|
||||
|
||||
ImTextureID id = *ds;
|
||||
ImTextureID id = reinterpret_cast<ImTextureID>(VkDescriptorSet(*ds));
|
||||
|
||||
textures.emplace(
|
||||
id,
|
||||
|
||||
@@ -160,10 +160,6 @@ private:
|
||||
bool button_pressed = false;
|
||||
bool fingertip_touching = false;
|
||||
|
||||
ImFontGlyphRangesBuilder glyph_range_builder;
|
||||
ImVector<ImWchar> glyph_ranges;
|
||||
bool glyph_range_dirty = true;
|
||||
|
||||
ImGuiID hovered_item = 0; // Hovered item in the current frame, reset at the beginning of the frame
|
||||
ImGuiID hovered_item_prev = 0; // Hovered item at the previous frame
|
||||
|
||||
@@ -198,7 +194,6 @@ public:
|
||||
void new_frame(XrTime display_time);
|
||||
std::vector<std::pair<int, XrCompositionLayerQuad>> end_frame();
|
||||
|
||||
ImFont * large_font;
|
||||
size_t get_focused_controller() const
|
||||
{
|
||||
return focused_controller;
|
||||
@@ -215,7 +210,6 @@ public:
|
||||
void free_texture(ImTextureID);
|
||||
void set_current();
|
||||
|
||||
void add_chars(std::string_view sv);
|
||||
bool is_modal_popup_shown() const;
|
||||
|
||||
void vibrate_on_hover();
|
||||
|
||||
@@ -915,7 +915,7 @@ void scenes::lobby::on_unfocused()
|
||||
|
||||
renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets
|
||||
|
||||
about_picture = nullptr;
|
||||
about_picture = 0;
|
||||
imgui_ctx.reset();
|
||||
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ static void InputText(const char * label, std::string & text, const ImVec2 & siz
|
||||
|
||||
static void display_recentering_tip(imgui_context & ctx, const std::string & tip)
|
||||
{
|
||||
ImGui::PushFont(ctx.large_font);
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 2);
|
||||
ImGui::SetNextWindowPos(ctx.layers()[3].vp_center(), ImGuiCond_Always, {0.5, 0.5});
|
||||
@@ -216,7 +216,7 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
|
||||
|
||||
ImGui::Dummy({1000, 1});
|
||||
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
if (server_name == "")
|
||||
CenterTextH(fmt::format(_F("Connection")));
|
||||
else
|
||||
@@ -245,7 +245,7 @@ void scenes::lobby::gui_enter_pin(locked_notifiable<pin_request_data> & pin_requ
|
||||
const int pin_size = 6;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, constants::style::pin_entry_item_spacing);
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
|
||||
const auto & style = ImGui::GetStyle();
|
||||
const auto window = ImGui::GetCurrentWindow();
|
||||
@@ -447,7 +447,7 @@ void scenes::lobby::gui_server_list()
|
||||
std::string cookie_to_remove;
|
||||
if (sorted_cookies.empty())
|
||||
{
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.5));
|
||||
CenterTextHV(_("Start a WiVRn server on your\nlocal network"));
|
||||
ImGui::PopStyleColor();
|
||||
@@ -835,7 +835,7 @@ void scenes::lobby::gui_settings()
|
||||
ImPlot::PushStyleColor(ImPlotCol_AxisBgActive, IM_COL32(0, 0, 0, 0));
|
||||
ImPlot::PushStyleColor(ImPlotCol_AxisBgHovered, IM_COL32(0, 0, 0, 0));
|
||||
|
||||
if (ImPlot::BeginPlot(_S("CPU time"), plot_size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild))
|
||||
if (ImPlot::BeginPlot(_S("CPU time"), plot_size, ImPlotFlags_CanvasOnly))
|
||||
{
|
||||
auto col = ImPlot::GetColormapColor(0);
|
||||
|
||||
@@ -849,7 +849,7 @@ void scenes::lobby::gui_settings()
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImPlot::BeginPlot(_S("GPU time"), plot_size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild))
|
||||
if (ImPlot::BeginPlot(_S("GPU time"), plot_size, ImPlotFlags_CanvasOnly))
|
||||
{
|
||||
auto col = ImPlot::GetColormapColor(1);
|
||||
|
||||
@@ -1077,7 +1077,7 @@ void scenes::lobby::gui_debug()
|
||||
|
||||
void scenes::lobby::gui_about()
|
||||
{
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
CenterTextH(std::string("WiVRn ") + wivrn::git_version);
|
||||
ImGui::PopFont();
|
||||
|
||||
@@ -1091,7 +1091,7 @@ void scenes::lobby::gui_about()
|
||||
|
||||
void scenes::lobby::gui_licenses()
|
||||
{
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
ImGui::Text("%s", _("Licenses").c_str());
|
||||
ImGui::PopFont();
|
||||
|
||||
@@ -1630,11 +1630,6 @@ static bool is_gui_visible(imgui_context & ctx, XrTime predicted_display_time)
|
||||
|
||||
std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTime predicted_display_time)
|
||||
{
|
||||
for (const auto & [key, server]: application::get_config().servers)
|
||||
{
|
||||
imgui_ctx->add_chars(server.service.name);
|
||||
}
|
||||
|
||||
imgui_ctx->new_frame(predicted_display_time);
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
|
||||
|
||||
@@ -319,14 +319,14 @@ virtual_keyboard::key_status virtual_keyboard::button_behavior(const ImRect & bb
|
||||
|
||||
float prev_held_duration = held_duration;
|
||||
held_duration += g.IO.DeltaTime;
|
||||
if ((flags & ImGuiButtonFlags_Repeat) and held_duration > g.IO.KeyRepeatDelay)
|
||||
{
|
||||
int n1 = (prev_held_duration - g.IO.KeyRepeatDelay) / g.IO.KeyRepeatRate;
|
||||
int n2 = (held_duration - g.IO.KeyRepeatDelay) / g.IO.KeyRepeatRate;
|
||||
|
||||
if (n2 != n1)
|
||||
pressed = true;
|
||||
}
|
||||
// if ((flags & ImGuiButtonFlags_Repeat) and held_duration > g.IO.KeyRepeatDelay)
|
||||
// {
|
||||
// int n1 = (prev_held_duration - g.IO.KeyRepeatDelay) / g.IO.KeyRepeatRate;
|
||||
// int n2 = (held_duration - g.IO.KeyRepeatDelay) / g.IO.KeyRepeatRate;
|
||||
//
|
||||
// if (n2 != n1)
|
||||
// pressed = true;
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -381,8 +381,8 @@ virtual_keyboard::key_status virtual_keyboard::draw_single_key(const key & k, in
|
||||
|
||||
ImGuiButtonFlags flags = ImGuiButtonFlags_None;
|
||||
|
||||
if (k.flag & key_flag_repeat)
|
||||
flags |= ImGuiButtonFlags_Repeat;
|
||||
// if (k.flag & key_flag_repeat)
|
||||
// flags |= ImGuiButtonFlags_Repeat;
|
||||
|
||||
auto status = button_behavior(bb, id, window_hovered, flags);
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ void scenes::stream::gui_performance_metrics()
|
||||
int n = 0;
|
||||
for (const auto & [title, subplots, unit]: plots)
|
||||
{
|
||||
if (ImPlot::BeginPlot(title.c_str(), plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoChild))
|
||||
if (ImPlot::BeginPlot(title.c_str(), plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText))
|
||||
{
|
||||
float min_v = 0;
|
||||
float max_v = 0;
|
||||
@@ -279,7 +279,7 @@ void scenes::stream::gui_performance_metrics()
|
||||
for (auto && [index, metrics]: utils::enumerate(decoder_metrics))
|
||||
{
|
||||
std::string title = fmt::format(_F("Decoder {}"), std::to_string(index));
|
||||
if (ImPlot::BeginPlot(title.c_str(), plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText | ImPlotFlags_NoChild))
|
||||
if (ImPlot::BeginPlot(title.c_str(), plot_size, ImPlotFlags_NoTitle | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText))
|
||||
{
|
||||
float min_v = 0;
|
||||
float max_v = compute_plot_max_value(&(metrics.data()->displayed), metrics.size(), sizeof(decoder_metric));
|
||||
|
||||
Reference in New Issue
Block a user