Skip to content

Commit

Permalink
added font size setting
Browse files Browse the repository at this point in the history
  • Loading branch information
SayakaIsBaka committed Aug 5, 2024
1 parent a699839 commit eff5e15
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lang/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,7 @@
"filter": "过滤",
"autoscroll": "自动滚屏",
"keysound_end_offset": "Key end offset",
"keysound_export_error": "Errors occured when exporting some keysounds, please check the Console tab for more details"
"keysound_export_error": "Errors occured when exporting some keysounds, please check the Console tab for more details",
"font_size": "Font size",
"restart_sayaslicer_font": "Restart sayaslicer for font changes to take effect!"
}
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,7 @@
"filter": "Filter",
"autoscroll": "Auto-scroll",
"keysound_end_offset": "Key end offset",
"keysound_export_error": "Errors occured when exporting some keysounds, please check the Console tab for more details"
"keysound_export_error": "Errors occured when exporting some keysounds, please check the Console tab for more details",
"font_size": "Font size",
"restart_sayaslicer_font": "Restart sayaslicer for font changes to take effect!"
}
4 changes: 3 additions & 1 deletion lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,7 @@
"filter": "Filtro",
"autoscroll": "Autodesplazamiento",
"keysound_end_offset": "Offset de final de tecla",
"keysound_export_error": "Se ocurrieron errores al exportar algunos sonidos de tecla, favor de revisar la pestaña Console para más detalles"
"keysound_export_error": "Se ocurrieron errores al exportar algunos sonidos de tecla, favor de revisar la pestaña Console para más detalles",
"font_size": "Font size",
"restart_sayaslicer_font": "Restart sayaslicer for font changes to take effect!"
}
4 changes: 3 additions & 1 deletion lang/jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,7 @@
"filter": "フィルター",
"autoscroll": "オートスクロール",
"keysound_end_offset": "Key end offset",
"keysound_export_error": "Errors occured when exporting some keysounds, please check the Console tab for more details"
"keysound_export_error": "Errors occured when exporting some keysounds, please check the Console tab for more details",
"font_size": "Font size",
"restart_sayaslicer_font": "Restart sayaslicer for font changes to take effect!"
}
4 changes: 3 additions & 1 deletion lang/kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,7 @@
"filter": "필터",
"autoscroll": "자동 스크롤",
"keysound_end_offset": "Key end offset",
"keysound_export_error": "Errors occured when exporting some keysounds, please check the Console tab for more details"
"keysound_export_error": "Errors occured when exporting some keysounds, please check the Console tab for more details",
"font_size": "Font size",
"restart_sayaslicer_font": "Restart sayaslicer for font changes to take effect!"
}
3 changes: 3 additions & 0 deletions sayaslicer/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void ShowPreferencesModal(UserPreferences& pref) {
if (ImGui::BeginPopupModal("Preferences", 0, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize)) {
ImGui::Checkbox("autodetect_starting_keysound"_t.c_str(), &pTmp.detectStartingKey);
ImGui::Checkbox("check_for_updates_startup"_t.c_str(), &pTmp.checkForUpdates);
ImGui::SliderInt("font_size"_t.c_str(), &pTmp.fontSize, 10, 20);
auto langs = GetLanguages();
auto langsPretty = GetLanguagesPretty();
auto combo_preview_value = GetLangPrettyFromId(pTmp.language);
Expand All @@ -53,6 +54,8 @@ void ShowPreferencesModal(UserPreferences& pref) {
ImGui::EndCombo();
}
if (ImGui::Button("save"_t.c_str())) {
if (pTmp.fontSize != pref.fontSize)
InsertNotification({ ImGuiToastType::Info, 3000, "restart_sayaslicer_font"_t.c_str() });
pref = pTmp;
pTmp = pref;
i18n::set_locale(pref.language);
Expand Down
4 changes: 3 additions & 1 deletion sayaslicer/preferences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
#include <imgui.h>
#include <fstream>
#include "translations.hpp"
#include "notifications.hpp"

class UserPreferences {
public:
bool detectStartingKey = false;
bool openPreferencesModalTemp = false;
bool checkForUpdates = false;
bool updateAvailable = false;
int fontSize = 14;
std::string language = "en";

template<class Archive>
void serialize(Archive& archive)
{
archive(CEREAL_NVP(detectStartingKey), CEREAL_NVP(language), CEREAL_NVP(checkForUpdates));
archive(CEREAL_NVP(detectStartingKey), CEREAL_NVP(language), CEREAL_NVP(checkForUpdates), CEREAL_NVP(fontSize));
}
};

Expand Down
7 changes: 4 additions & 3 deletions sayaslicer/sayaslicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ void ShowMainMenuBar(sf::SoundBuffer& buffer, SlicerSettings &settings, sf::Rend
}
}

void SetupFonts(ImGuiIO& io) {
float mainFontSize = 14.0f;
void SetupFonts(ImGuiIO& io, int fontSize) {
float mainFontSize = (float)fontSize;
float iconFontSize = mainFontSize * 2.0f / 3.0f;

ImVector<ImWchar> ranges;
Expand Down Expand Up @@ -425,7 +425,6 @@ int main() {
ImGui::SFML::Init(window, false);
auto &io = ImGui::GetIO();

SetupFonts(io);
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;

SetupImGuiStyle();
Expand All @@ -448,6 +447,8 @@ int main() {
LoadPreferences(settings.prefs);
InitTranslations(settings.prefs.language);

SetupFonts(io, settings.prefs.fontSize);

#if _WIN32
OleInitialize(NULL);
HWND handle = window.getSystemHandle();
Expand Down

0 comments on commit eff5e15

Please sign in to comment.