From 70ce423d00293d5ddec098f0fc65e242b1ee7a5f Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 19 Jul 2019 18:26:59 -1000 Subject: [PATCH] Compile-time locale refactor --- specter/CMakeLists.txt | 4 +- specter/include/specter/FileBrowser.hpp | 14 +++--- specter/include/specter/IViewManager.hpp | 12 +++-- specter/include/specter/ScrollView.hpp | 4 +- specter/include/specter/Translator.hpp | 31 ------------- specter/lib/Button.cpp | 4 +- specter/lib/FileBrowser.cpp | 29 +++++------- specter/lib/FontCache.cpp | 18 ++++---- specter/lib/MessageWindow.cpp | 4 +- specter/lib/MultiLineTextView.cpp | 4 +- specter/lib/RootView.cpp | 6 +-- specter/lib/SplitView.cpp | 2 +- specter/lib/Table.cpp | 6 +-- specter/lib/TextView.cpp | 10 ++--- specter/lib/Toolbar.cpp | 2 +- specter/lib/Translator.cpp | 57 ------------------------ specter/lib/ViewResources.cpp | 2 +- specter/shaders/CMakeLists.txt | 3 +- 18 files changed, 58 insertions(+), 154 deletions(-) delete mode 100644 specter/include/specter/Translator.hpp delete mode 100644 specter/lib/Translator.cpp diff --git a/specter/CMakeLists.txt b/specter/CMakeLists.txt index 4298fb796..46868f8de 100644 --- a/specter/CMakeLists.txt +++ b/specter/CMakeLists.txt @@ -37,7 +37,6 @@ list(APPEND SPECTER_HEADERS include/specter/FileBrowser.hpp include/specter/Icon.hpp include/specter/FontCache.hpp - include/specter/Translator.hpp include/specter/genie.hpp) list(APPEND SPECTER_SOURCES @@ -61,8 +60,7 @@ list(APPEND SPECTER_SOURCES lib/PathButtons.cpp lib/FileBrowser.cpp lib/Icon.cpp - lib/FontCache.cpp - lib/Translator.cpp) + lib/FontCache.cpp) add_library(specter ${SPECTER_SOURCES} ${SPECTER_HEADERS}) target_link_libraries(specter PUBLIC specter-fonts freetype hecl-full zeus) diff --git a/specter/include/specter/FileBrowser.hpp b/specter/include/specter/FileBrowser.hpp index cdae13b2c..ce33cb7d3 100644 --- a/specter/include/specter/FileBrowser.hpp +++ b/specter/include/specter/FileBrowser.hpp @@ -78,7 +78,7 @@ private: FileBrowser& m_browser; std::string m_name; FileFieldBind(FileBrowser& browser, const IViewManager& vm) - : m_browser(browser), m_name(vm.translateOr("file_name", "File Name")) {} + : m_browser(browser), m_name(vm.translate()) {} std::string_view name(const Control* control) const { return m_name; } void changed(const Control* control, std::string_view val) {} } m_fileFieldBind; @@ -196,12 +196,12 @@ private: void rowActivated(size_t rIdx) { m_fb.okActivated(false); } FileListingDataBind(FileBrowser& fb, const IViewManager& vm) : m_fb(fb) { - m_nameCol = vm.translateOr("name", "Name"); - m_typeCol = vm.translateOr("type", "Type"); - m_sizeCol = vm.translateOr("size", "Size"); - m_dirStr = vm.translateOr("directory", "Directory"); - m_projStr = vm.translateOr("hecl_project", "HECL Project"); - m_fileStr = vm.translateOr("file", "File"); + m_nameCol = vm.translate(); + m_typeCol = vm.translate(); + m_sizeCol = vm.translate(); + m_dirStr = vm.translate(); + m_projStr = vm.translate(); + m_fileStr = vm.translate(); } } m_fileListingBind; diff --git a/specter/include/specter/IViewManager.hpp b/specter/include/specter/IViewManager.hpp index 5dbd97455..19fe41e99 100644 --- a/specter/include/specter/IViewManager.hpp +++ b/specter/include/specter/IViewManager.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Translator.hpp" +#include #include "SplitView.hpp" #include @@ -9,12 +9,10 @@ struct ISpaceController; struct IViewManager { public: - virtual const Translator* getTranslator() const { return nullptr; } - virtual std::string_view translateOr(std::string_view key, std::string_view vor) const { - const Translator* trans = getTranslator(); - if (trans) - return trans->translateOr(key, vor); - return vor; + virtual locale::ELocale getTranslatorLocale() const { return locale::ELocale::en_US; } + template + constexpr auto translate(Args&&... args) const { + return locale::Translate(getTranslatorLocale(), std::forward(args)...); } virtual void deferSpaceSplit(ISpaceController* split, SplitView::Axis axis, int thisSlot, diff --git a/specter/include/specter/ScrollView.hpp b/specter/include/specter/ScrollView.hpp index 30aedbbee..667491810 100644 --- a/specter/include/specter/ScrollView.hpp +++ b/specter/include/specter/ScrollView.hpp @@ -32,8 +32,8 @@ private: std::string m_leftName, m_rightName; SideButtonBinding(ScrollView& sv, IViewManager& vm) : m_sv(sv) - , m_leftName(vm.translateOr("scroll_left", "Scroll Left")) - , m_rightName(vm.translateOr("scroll_right", "Scroll Right")) {} + , m_leftName(vm.translate()) + , m_rightName(vm.translate()) {} std::string_view name(const Control* control) const { return (control == reinterpret_cast(m_sv.m_sideButtons[0].m_view.get())) ? m_leftName.c_str() : m_rightName.c_str(); diff --git a/specter/include/specter/Translator.hpp b/specter/include/specter/Translator.hpp deleted file mode 100644 index 94078f4c7..000000000 --- a/specter/include/specter/Translator.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include -#include - -namespace specter { - -class Locale { - std::string_view m_name; - std::string_view m_fullName; - std::unique_ptr m_rootNode; - const athena::io::YAMLNode* m_langNode; - -public: - Locale(std::string_view name, std::string_view fullName, const unsigned char* yamlSource, size_t yamlLength); - std::string_view name() const { return m_name; } - std::string_view fullName() const { return m_fullName; } - const athena::io::YAMLNode* rootNode() const { return m_langNode; } -}; - -class Translator { - const Locale* m_targetLocale; - -public: - Translator(const Locale* targetLocale) { setLocale(targetLocale); } - void setLocale(const Locale* targetLocale); - std::string_view translate(std::string_view key) const; - std::string_view translateOr(std::string_view key, std::string_view vor) const; -}; - -} // namespace specter diff --git a/specter/lib/Button.cpp b/specter/lib/Button.cpp index 779330f2d..9947156bd 100644 --- a/specter/lib/Button.cpp +++ b/specter/lib/Button.cpp @@ -365,7 +365,7 @@ void Button::MenuTarget::mouseDown(const boo::SWindowCoord& coord, boo::EMouseBu m_pressed = true; setPressed(); if (m_hovered) { - Log.report(logvisor::Info, "button menu '%s' activated", m_button.m_textStr.c_str()); + Log.report(logvisor::Info, fmt("button menu '{}' activated"), m_button.m_textStr); if (m_button.m_controlBinding) { m_button.m_modalMenu.m_view = static_cast(*m_button.m_controlBinding).buildMenu(&m_button); rootView().setActiveMenuButton(&m_button); @@ -385,7 +385,7 @@ void Button::ButtonTarget::mouseUp(const boo::SWindowCoord& coord, boo::EMouseBu if (m_button.m_controlBinding) static_cast(*m_button.m_controlBinding).up(&m_button, coord); if (m_hovered) { - Log.report(logvisor::Info, "button '%s' activated", m_button.m_textStr.c_str()); + Log.report(logvisor::Info, fmt("button '{}' activated"), m_button.m_textStr); if (m_button.m_controlBinding) static_cast(*m_button.m_controlBinding).activated(&m_button, coord); } diff --git a/specter/lib/FileBrowser.cpp b/specter/lib/FileBrowser.cpp index d30ca2a5f..65d8aebdb 100644 --- a/specter/lib/FileBrowser.cpp +++ b/specter/lib/FileBrowser.cpp @@ -46,7 +46,7 @@ FileBrowser::FileBrowser(ViewResources& res, View& parentView, std::string_view , m_left(*this, res) , m_right(*this, res) , m_ok(*this, res, title) -, m_cancel(*this, res, rootView().viewManager().translateOr("cancel", "Cancel")) +, m_cancel(*this, res, rootView().viewManager().translate()) , m_fileFieldBind(*this, rootView().viewManager()) , m_fileListingBind(*this, rootView().viewManager()) , m_systemBookmarkBind(*this) @@ -61,15 +61,15 @@ FileBrowser::FileBrowser(ViewResources& res, View& parentView, std::string_view m_fileListing.m_view.reset(new Table(res, *this, &m_fileListingBind, &m_fileListingBind, 3)); m_systemBookmarks.m_view.reset(new Table(res, *this, &m_systemBookmarkBind, &m_systemBookmarkBind, 1)); m_systemBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); - m_systemBookmarksLabel->typesetGlyphs(vm.translateOr("system_locations", "System Locations"), + m_systemBookmarksLabel->typesetGlyphs(vm.translate(), res.themeData().uiText()); m_projectBookmarks.m_view.reset(new Table(res, *this, &m_projectBookmarkBind, &m_projectBookmarkBind, 1)); m_projectBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); - m_projectBookmarksLabel->typesetGlyphs(vm.translateOr("recent_projects", "Recent Projects"), + m_projectBookmarksLabel->typesetGlyphs(vm.translate(), res.themeData().uiText()); m_recentBookmarks.m_view.reset(new Table(res, *this, &m_recentBookmarkBind, &m_recentBookmarkBind, 1)); m_recentBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); - m_recentBookmarksLabel->typesetGlyphs(vm.translateOr("recent_files", "Recent Files"), res.themeData().uiText()); + m_recentBookmarksLabel->typesetGlyphs(vm.translate(), res.themeData().uiText()); /* Populate system bookmarks */ std::vector> systemLocs = hecl::GetSystemLocations(); @@ -184,8 +184,7 @@ void FileBrowser::okActivated(bool viaButton) { hecl::Sstat theStat; if (hecl::Stat(path.c_str(), &theStat) || !S_ISDIR(theStat.st_mode)) { hecl::SystemUTF8Conv utf8(path); - m_fileField.m_view->setErrorState( - hecl::Format(vm.translateOr("no_access_as_dir", "Unable to access '%s' as directory").data(), utf8.c_str())); + m_fileField.m_view->setErrorState(vm.translate(utf8)); return; } @@ -195,13 +194,13 @@ void FileBrowser::okActivated(bool viaButton) { int err = hecl::Stat(path.c_str(), &theStat); if (m_type == Type::SaveFile) { if (m_fileField.m_view->getText().empty()) { - m_fileField.m_view->setErrorState(vm.translateOr("file_field_empty", "Unable to save empty file")); + m_fileField.m_view->setErrorState(vm.translate()); return; } if (!err && !S_ISDIR(theStat.st_mode)) { m_confirmWindow.reset( new MessageWindow(rootView().viewRes(), *this, MessageWindow::Type::ConfirmOkCancel, - hecl::Format(vm.translateOr("overwrite_confirm", "Overwrite '%s'?").data(), path.c_str()), + vm.translate(path), [&, path](bool ok) { if (ok) { m_returnFunc(true, path); @@ -222,20 +221,18 @@ void FileBrowser::okActivated(bool viaButton) { return; } else if (m_type == Type::SaveDirectory || m_type == Type::NewHECLProject) { if (m_fileField.m_view->getText().empty()) { - m_fileField.m_view->setErrorState( - vm.translateOr("directory_field_empty", "Unable to make empty-named directory")); + m_fileField.m_view->setErrorState(vm.translate()); return; } if (!err && !S_ISDIR(theStat.st_mode)) { - m_fileField.m_view->setErrorState(vm.translateOr("no_overwrite_file", "Unable to make directory over file")); + m_fileField.m_view->setErrorState(vm.translate()); return; } if (!err && S_ISDIR(theStat.st_mode)) { if (m_type == Type::NewHECLProject) { hecl::ProjectRootPath projRoot = hecl::SearchForProject(path); if (projRoot) { - m_fileField.m_view->setErrorState( - vm.translateOr("no_overwrite_project", "Unable to make project within existing project")); + m_fileField.m_view->setErrorState(vm.translate()); return; } } @@ -253,8 +250,7 @@ void FileBrowser::okActivated(bool viaButton) { return; } else if (err || !S_ISREG(theStat.st_mode)) { hecl::SystemUTF8Conv utf8(path); - m_fileField.m_view->setErrorState( - hecl::Format(vm.translateOr("no_access_as_file", "Unable to access '%s' as file").data(), utf8.c_str())); + m_fileField.m_view->setErrorState(vm.translate(utf8)); return; } m_returnFunc(true, path); @@ -275,8 +271,7 @@ void FileBrowser::okActivated(bool viaButton) { } if (err || !S_ISDIR(theStat.st_mode)) { hecl::SystemUTF8Conv utf8(path); - m_fileField.m_view->setErrorState( - hecl::Format(vm.translateOr("no_access_as_dir", "Unable to access '%s' as directory").data(), utf8.c_str())); + m_fileField.m_view->setErrorState(vm.translate(utf8)); return; } m_returnFunc(true, path); diff --git a/specter/lib/FontCache.cpp b/specter/lib/FontCache.cpp index 8562db216..a6806f767 100644 --- a/specter/lib/FontCache.cpp +++ b/specter/lib/FontCache.cpp @@ -60,12 +60,12 @@ void FreeTypeGZipMemFace::open() { return; if (FT_Stream_OpenGzip(&m_decomp, &m_comp)) - Log.report(logvisor::Fatal, "unable to open FreeType gzip stream"); + Log.report(logvisor::Fatal, fmt("unable to open FreeType gzip stream")); FT_Open_Args args = {FT_OPEN_STREAM, nullptr, 0, nullptr, &m_decomp}; if (FT_Open_Face(m_lib, &args, 0, &m_face)) - Log.report(logvisor::Fatal, "unable to open FreeType gzip face"); + Log.report(logvisor::Fatal, fmt("unable to open FreeType gzip face")); } void FreeTypeGZipMemFace::close() { @@ -116,7 +116,7 @@ static void MemcpyRect(RgbaPixel* img, const FT_Bitmap* bmp, unsigned slice, uns } } -static inline void GridFitGlyph(FT_GlyphSlot slot, FT_UInt& width, FT_UInt& height) { +static void GridFitGlyph(FT_GlyphSlot slot, FT_UInt& width, FT_UInt& height) { width = slot->metrics.width >> 6; height = slot->metrics.height >> 6; } @@ -585,7 +585,7 @@ boo::ObjToken FontAtlas::texture(boo::IGraphicsDataFactory* gf) FontCache::Library::Library() { FT_Error err = FT_Init_FreeType(&m_lib); if (err) - Log.report(logvisor::Fatal, "unable to FT_Init_FreeType"); + Log.report(logvisor::Fatal, fmt("unable to FT_Init_FreeType")); } FontCache::Library::~Library() { FT_Done_FreeType(m_lib); } @@ -603,10 +603,10 @@ FontTag FontCache::prepCustomFont(std::string_view name, FT_Face face, FCharFilt uint32_t dpi) { /* Quick validation */ if (!face) - Log.report(logvisor::Fatal, "invalid freetype face"); + Log.report(logvisor::Fatal, fmt("invalid freetype face")); if (!face->charmap || face->charmap->encoding != FT_ENCODING_UNICODE) - Log.report(logvisor::Fatal, "font does not contain a unicode char map"); + Log.report(logvisor::Fatal, fmt("font does not contain a unicode char map")); /* Set size with FreeType */ FT_Set_Char_Size(face, 0, points * 64.0, 0, dpi); @@ -618,7 +618,7 @@ FontTag FontCache::prepCustomFont(std::string_view name, FT_Face face, FCharFilt return tag; /* Now check filesystem cache */ - hecl::SystemString cachePath = m_cacheRoot + _SYS_STR('/') + hecl::SysFormat(_SYS_STR("%" PRIx64), tag.hash()); + hecl::SystemString cachePath = m_cacheRoot + _SYS_STR('/') + fmt::format(fmt(_SYS_STR("{}")), tag.hash()); hecl::Sstat st; if (!hecl::Stat(cachePath.c_str(), &st) && S_ISREG(st.st_mode)) { athena::io::FileReader r(cachePath); @@ -637,7 +637,7 @@ FontTag FontCache::prepCustomFont(std::string_view name, FT_Face face, FCharFilt /* Nada, build and cache now */ athena::io::FileWriter w(cachePath); if (w.hasError()) - Log.report(logvisor::Fatal, "unable to open '%s' for writing", cachePath.c_str()); + Log.report(logvisor::Fatal, fmt("unable to open '{}' for writing"), cachePath); w.writeUint32Big('FONT'); m_cachedAtlases.emplace(tag, std::make_unique(face, dpi, subpixel, filter, w)); return tag; @@ -646,7 +646,7 @@ FontTag FontCache::prepCustomFont(std::string_view name, FT_Face face, FCharFilt const FontAtlas& FontCache::lookupAtlas(FontTag tag) const { auto search = m_cachedAtlases.find(tag); if (search == m_cachedAtlases.cend()) - Log.report(logvisor::Fatal, "invalid font"); + Log.report(logvisor::Fatal, fmt("invalid font")); return *search->second.get(); } diff --git a/specter/lib/MessageWindow.cpp b/specter/lib/MessageWindow.cpp index c88ce24fe..feadf148d 100644 --- a/specter/lib/MessageWindow.cpp +++ b/specter/lib/MessageWindow.cpp @@ -11,8 +11,8 @@ MessageWindow::MessageWindow(ViewResources& res, View& parentView, Type type, st type == Type::ErrorOk ? res.themeData().splashErrorBackground() : res.themeData().splashBackground()) , m_type(type) , m_func(func) -, m_okBind(*this, rootView().viewManager().translateOr("ok", "OK")) -, m_cancelBind(*this, rootView().viewManager().translateOr("cancel", "Cancel")) { +, m_okBind(*this, rootView().viewManager().translate()) +, m_cancelBind(*this, rootView().viewManager().translate()) { m_text.reset(new MultiLineTextView(res, *this, res.m_mainFont, TextView::Alignment::Center)); m_text->typesetGlyphs(message, res.themeData().uiText(), 380 * res.pixelFactor()); constraint() = RectangleConstraint(400 * res.pixelFactor(), 80 * res.pixelFactor() + m_text->nominalHeight()); diff --git a/specter/lib/MultiLineTextView.cpp b/specter/lib/MultiLineTextView.cpp index e32c5a226..dee1dac44 100644 --- a/specter/lib/MultiLineTextView.cpp +++ b/specter/lib/MultiLineTextView.cpp @@ -19,7 +19,7 @@ std::string MultiLineTextView::LineWrap(std::string_view str, int wrap) { utf8proc_int32_t ch; utf8proc_ssize_t sz = utf8proc_iterate(it, -1, &ch); if (sz < 0) - Log.report(logvisor::Fatal, "invalid UTF-8 char"); + Log.report(logvisor::Fatal, fmt("invalid UTF-8 char")); if (ch == '\n') { ret += '\n'; lCh = -1; @@ -147,7 +147,7 @@ void MultiLineTextView::typesetGlyphs(std::string_view str, const zeus::CColor& utf8proc_int32_t ch; utf8proc_ssize_t sz = utf8proc_iterate(it, -1, &ch); if (sz < 0) - Log.report(logvisor::Fatal, "invalid UTF-8 char"); + Log.report(logvisor::Fatal, fmt("invalid UTF-8 char")); if (ch == '\n' || ch == '\0') ++lineCount; rem -= sz; diff --git a/specter/lib/RootView.cpp b/specter/lib/RootView.cpp index 3bedd2653..84e9bc449 100644 --- a/specter/lib/RootView.cpp +++ b/specter/lib/RootView.cpp @@ -23,7 +23,7 @@ RootView::~RootView() { m_window->setCallback(nullptr); } RootView::SplitMenuSystem::SplitMenuSystem(RootView& rv, boo::IGraphicsDataFactory::Context& ctx) : m_rv(rv) -, m_text(rv.m_viewMan.translateOr("boundary_action", "Boundary Action")) +, m_text(rv.m_viewMan.translate()) , m_splitActionNode(*this) , m_joinActionNode(*this) { ViewResources& res = *rv.m_viewRes; @@ -76,10 +76,10 @@ RootView::SplitMenuSystem::SplitMenuSystem(RootView& rv, boo::IGraphicsDataFacto } RootView::SplitMenuSystem::SplitActionNode::SplitActionNode(SplitMenuSystem& smn) -: m_smn(smn), m_text(smn.m_rv.m_viewMan.translateOr("split", "Split")) {} +: m_smn(smn), m_text(smn.m_rv.m_viewMan.translate()) {} RootView::SplitMenuSystem::JoinActionNode::JoinActionNode(SplitMenuSystem& smn) -: m_smn(smn), m_text(smn.m_rv.m_viewMan.translateOr("join", "Join")) {} +: m_smn(smn), m_text(smn.m_rv.m_viewMan.translate()) {} void RootView::SplitMenuSystem::setArrowVerts(const boo::SWindowRect& rect, SplitView::ArrowDir dir) { const boo::SWindowRect& root = m_rv.subRect(); diff --git a/specter/lib/SplitView.cpp b/specter/lib/SplitView.cpp index e352949c0..207738485 100644 --- a/specter/lib/SplitView.cpp +++ b/specter/lib/SplitView.cpp @@ -31,7 +31,7 @@ SplitView::SplitView(ViewResources& res, View& parentView, ISplitSpaceController View* SplitView::setContentView(int slot, View* view) { if (slot < 0 || slot > 1) - Log.report(logvisor::Fatal, "out-of-range slot to RootView::SplitView::setContentView"); + Log.report(logvisor::Fatal, fmt("out-of-range slot to RootView::SplitView::setContentView")); View* ret = m_views[slot].m_view; m_views[slot].m_view = view; m_views[slot].m_mouseDown = 0; diff --git a/specter/lib/Table.cpp b/specter/lib/Table.cpp index 76800a979..3e46362bb 100644 --- a/specter/lib/Table.cpp +++ b/specter/lib/Table.cpp @@ -17,7 +17,7 @@ Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITab , m_hVerts(new SolidShaderVert[maxColumns * 6]) , m_rowsView(*this, res) { if (!maxColumns) - Log.report(logvisor::Fatal, "0-column tables not supported"); + Log.report(logvisor::Fatal, fmt("0-column tables not supported")); m_scroll.m_view.reset(new ScrollView(res, *this, ScrollView::Style::ThinIndicator)); @@ -170,7 +170,7 @@ void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWind void Table::cycleSortColumn(size_t c) { if (c >= m_columns) - Log.report(logvisor::Fatal, "cycleSortColumn out of bounds (%" PRISize ", %" PRISize ")", c, m_columns); + Log.report(logvisor::Fatal, fmt("cycleSortColumn out of bounds ({}, {})"), c, m_columns); if (m_state) { size_t cIdx; SortDirection dir = m_state->getSort(cIdx); @@ -187,7 +187,7 @@ void Table::selectRow(size_t r) { if (m_inSelectRow) return; if (r >= m_rows && r != SIZE_MAX) - Log.report(logvisor::Fatal, "selectRow out of bounds (%" PRISize ", %" PRISize ")", r, m_rows); + Log.report(logvisor::Fatal, fmt("selectRow out of bounds ({}, {})"), r, m_rows); if (r == m_selectedRow) { if (m_state) { m_inSelectRow = true; diff --git a/specter/lib/TextView.cpp b/specter/lib/TextView.cpp index 3b9b78e04..dffe489bc 100644 --- a/specter/lib/TextView.cpp +++ b/specter/lib/TextView.cpp @@ -48,7 +48,7 @@ void TextView::_commitResources(size_t capacity) { TextView::TextView(ViewResources& res, View& parentView, const FontAtlas& font, Alignment align, size_t capacity) : View(res, parentView), m_capacity(capacity), m_fontAtlas(font), m_align(align) { if (size_t(hecl::VertexBufferPool::bucketCapacity()) < capacity) - Log.report(logvisor::Fatal, "bucket overflow [%" PRISize "/%" PRISize "]", capacity, + Log.report(logvisor::Fatal, fmt("bucket overflow [{}/{}]"), capacity, hecl::VertexBufferPool::bucketCapacity()); _commitResources(0); @@ -105,7 +105,7 @@ void TextView::typesetGlyphs(std::string_view str, const zeus::CColor& defaultCo for (; it.iter() < str.end(); ++it) { utf8proc_int32_t ch = *it; if (ch == -1) { - Log.report(logvisor::Warning, "invalid UTF-8 char"); + Log.report(logvisor::Warning, fmt("invalid UTF-8 char")); break; } if (ch == '\n' || ch == '\0') @@ -237,7 +237,7 @@ void TextView::draw(boo::IGraphicsCommandQueue* gfxQ) { std::pair TextView::queryGlyphDimensions(size_t pos) const { if (pos >= m_glyphInfo.size()) - Log.report(logvisor::Fatal, "TextView::queryGlyphWidth(%" PRISize ") out of bounds: %" PRISize, pos, + Log.report(logvisor::Fatal, fmt("TextView::queryGlyphWidth({}) out of bounds: {}"), pos, m_glyphInfo.size()); return m_glyphInfo[pos].m_dims; @@ -260,7 +260,7 @@ size_t TextView::reverseSelectGlyph(int x) const { int TextView::queryReverseAdvance(size_t idx) const { if (idx > m_glyphInfo.size()) - Log.report(logvisor::Fatal, "TextView::queryReverseGlyph(%" PRISize ") out of inclusive bounds: %" PRISize, idx, + Log.report(logvisor::Fatal, fmt("TextView::queryReverseGlyph({}) out of inclusive bounds: {}"), idx, m_glyphInfo.size()); if (!idx) return 0; @@ -269,7 +269,7 @@ int TextView::queryReverseAdvance(size_t idx) const { std::pair TextView::queryWholeWordRange(size_t idx) const { if (idx > m_glyphInfo.size()) - Log.report(logvisor::Fatal, "TextView::queryWholeWordRange(%" PRISize ") out of inclusive bounds: %" PRISize, idx, + Log.report(logvisor::Fatal, fmt("TextView::queryWholeWordRange({}) out of inclusive bounds: {}"), idx, m_glyphInfo.size()); if (m_glyphInfo.empty()) return {0, 0}; diff --git a/specter/lib/Toolbar.cpp b/specter/lib/Toolbar.cpp index 65dbfd72b..3b071972c 100644 --- a/specter/lib/Toolbar.cpp +++ b/specter/lib/Toolbar.cpp @@ -111,7 +111,7 @@ void Toolbar::setVerticalVerts(int height) { void Toolbar::push_back(View* v, unsigned unit) { if (unit >= m_units) - Log.report(logvisor::Fatal, "unit %u out of range %u", unit, m_units); + Log.report(logvisor::Fatal, fmt("unit {} out of range {}"), unit, m_units); std::vector>& u = m_children[unit]; u.emplace_back(); u.back().m_view = v; diff --git a/specter/lib/Translator.cpp b/specter/lib/Translator.cpp deleted file mode 100644 index 668e062ac..000000000 --- a/specter/lib/Translator.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "specter/Translator.hpp" -#include "logvisor/logvisor.hpp" - -namespace specter { -static logvisor::Module Log("specter::Translator"); - -Locale::Locale(std::string_view name, std::string_view fullName, const unsigned char* yamlSource, size_t yamlLength) -: m_name(name), m_fullName(fullName) { - athena::io::YAMLDocReader reader; - yaml_parser_set_input_string(reader.getParser(), yamlSource, yamlLength); - reader.parse(nullptr); - m_rootNode = reader.releaseRootNode(); - if (m_rootNode) { - m_langNode = m_rootNode->findMapChild(name.data()); - if (!m_langNode) - Log.report(logvisor::Fatal, "no root node '%s' found in locale", name.data()); - } else - Log.report(logvisor::Warning, "locale empty"); -} - -void Translator::setLocale(const Locale* targetLocale) { - if (!targetLocale) - Log.report(logvisor::Fatal, "null locale"); - m_targetLocale = targetLocale; -} - -static std::string_view RecursiveLookup(const athena::io::YAMLNode* node, std::string_view::const_iterator start, - std::string_view::const_iterator end) { - for (std::string_view::const_iterator it = start; it != end; ++it) { - if (*it == '/') { - const athena::io::YAMLNode* ch = node->findMapChild(std::string(start, it)); - if (!ch) - return {}; - return RecursiveLookup(ch, it + 1, end); - } - } - const athena::io::YAMLNode* ch = node->findMapChild(std::string(start, end)); - if (!ch) - return {}; - return ch->m_scalarString; -} - -std::string_view Translator::translate(std::string_view key) const { - if (!m_targetLocale->rootNode()) - return {}; - - return RecursiveLookup(m_targetLocale->rootNode(), key.cbegin(), key.cend()); -} - -std::string_view Translator::translateOr(std::string_view key, std::string_view vor) const { - std::string_view find = translate(key); - if (!find.empty()) - return find; - return vor; -} - -} // namespace specter diff --git a/specter/lib/ViewResources.cpp b/specter/lib/ViewResources.cpp index 60ef4ddfb..1cf6eba26 100644 --- a/specter/lib/ViewResources.cpp +++ b/specter/lib/ViewResources.cpp @@ -5,7 +5,7 @@ static logvisor::Module Log("specter::ViewResources"); void ViewResources::init(boo::IGraphicsDataFactory* factory, FontCache* fcache, const IThemeData* theme, float pf) { if (!factory || !fcache || !theme) - Log.report(logvisor::Fatal, "all arguments of ViewResources::init() must be non-null"); + Log.report(logvisor::Fatal, fmt("all arguments of ViewResources::init() must be non-null")); m_pixelFactor = pf; m_factory = factory; m_theme = theme; diff --git a/specter/shaders/CMakeLists.txt b/specter/shaders/CMakeLists.txt index 47bdccc92..c69e4ac0b 100644 --- a/specter/shaders/CMakeLists.txt +++ b/specter/shaders/CMakeLists.txt @@ -1,5 +1,6 @@ include_directories(../../hecl/include ../../hecl/extern/boo/include - ../../hecl/extern/boo/logvisor/include) + ../../hecl/extern/boo/logvisor/include + ../../nod/logvisor/fmt/include) add_shader(SpecterViewShaders) add_shader(SpecterTextViewShaders)