Skip to content

Commit

Permalink
fix font reloading scale issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Feb 14, 2023
1 parent 27a9782 commit f0b4ae6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <imgui.h>

namespace ImGui {
void SetTheme(const char* theme);
std::vector<const char*> Themes();
void SetTheme(const char* theme, ImGuiStyle* dst = nullptr);
void StyleColorsSpectrum(ImGuiStyle* dst = nullptr);
void StyleColorsDracula(ImGuiStyle* dst = nullptr);
void StyleColorsDeepDark(ImGuiStyle* dst = nullptr);
Expand Down
14 changes: 7 additions & 7 deletions source/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ std::vector<const char*> ImGui::Themes() {
return themes;
}

void ImGui::SetTheme(const char* theme) {
void ImGui::SetTheme(const char* theme, ImGuiStyle* dst) {
if (strcmp(theme, "dark") == 0)
ImGui::StyleColorsDark();
ImGui::StyleColorsDark(dst);
else if (strcmp(theme, "light") == 0)
ImGui::StyleColorsLight();
ImGui::StyleColorsLight(dst);
else if (strcmp(theme, "classic") == 0)
ImGui::StyleColorsClassic();
ImGui::StyleColorsClassic(dst);
else if (strcmp(theme, "spectrum") == 0)
ImGui::StyleColorsSpectrum();
ImGui::StyleColorsSpectrum(dst);
else if (strcmp(theme, "dracula") == 0)
ImGui::StyleColorsDracula();
ImGui::StyleColorsDracula(dst);
else if (strcmp(theme, "deepdark") == 0)
ImGui::StyleColorsDeepDark();
ImGui::StyleColorsDeepDark(dst);
}

// https://github.com/adobe/imgui/blob/master/docs/Spectrum.md
Expand Down
12 changes: 6 additions & 6 deletions source/views/quickview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace ImPlay::Views {
Quickview::Quickview(Config *config, Dispatch *dispatch, Mpv *mpv) : View(config, dispatch, mpv) {
addTab("playlist", "views.quickview.playlist"_i18n, [this]() { drawPlaylistTabContent(); });
addTab("chapters", "views.quickview.chapters"_i18n, [this]() { drawChaptersTabContent(); });
addTab("video", "views.quickview.video"_i18n, [this]() { drawVideoTabContent(); }, true);
addTab("audio", "views.quickview.audio"_i18n, [this]() { drawAudioTabContent(); }, true);
addTab("subtitle", "views.quickview.subtitle"_i18n, [this]() { drawSubtitleTabContent(); }, true);
addTab("playlist", "views.quickview.playlist", [this]() { drawPlaylistTabContent(); });
addTab("chapters", "views.quickview.chapters", [this]() { drawChaptersTabContent(); });
addTab("video", "views.quickview.video", [this]() { drawVideoTabContent(); }, true);
addTab("audio", "views.quickview.audio", [this]() { drawAudioTabContent(); }, true);
addTab("subtitle", "views.quickview.subtitle", [this]() { drawSubtitleTabContent(); }, true);

mpv->observeEvent(MPV_EVENT_FILE_LOADED, [this](void *data) {
updateAudioEqChannels();
Expand Down Expand Up @@ -39,7 +39,7 @@ void Quickview::draw() {
flags |= ImGuiTabItemFlags_SetSelected;
tabSwitched = true;
}
if (ImGui::BeginTabItem(title.c_str(), nullptr, flags)) {
if (ImGui::BeginTabItem(i18n(title).c_str(), nullptr, flags)) {
if (child) ImGui::BeginChild(name.c_str());
draw();
if (child) ImGui::EndChild();
Expand Down
6 changes: 4 additions & 2 deletions source/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,11 @@ void Window::loadFonts() {
iconSize = std::floor(iconSize * scale);

ImGuiIO& io = ImGui::GetIO();
ImGuiStyle& style = ImGui::GetStyle();
ImGuiStyle style;
std::string theme = config.Data.Interface.Theme;

{
ImGui::SetTheme(config.Data.Interface.Theme.c_str());
ImGui::SetTheme(theme.c_str(), &style);
style.TabRounding = 4;
style.ScrollbarRounding = 9;
style.WindowRounding = 7;
Expand All @@ -292,6 +293,7 @@ void Window::loadFonts() {
#else
style.ScaleAllSizes(scale);
#endif
ImGui::GetStyle() = style;

io.Fonts->Clear();

Expand Down

0 comments on commit f0b4ae6

Please sign in to comment.