mirror of https://github.com/AxioDL/metaforce.git
string_view refactor
This commit is contained in:
parent
4ba4022277
commit
1b7874a7b2
|
@ -92,11 +92,11 @@ public:
|
|||
|
||||
~Button() {closeMenu({});}
|
||||
Button(ViewResources& res, View& parentView,
|
||||
IButtonBinding* controlBinding, const std::string& text, Icon* icon=nullptr,
|
||||
IButtonBinding* controlBinding, std::string_view text, Icon* icon=nullptr,
|
||||
Style style=Style::Block, const zeus::CColor& bgColor=zeus::CColor::skWhite,
|
||||
RectangleConstraint constraint=RectangleConstraint());
|
||||
Button(ViewResources& res, View& parentView,
|
||||
IButtonBinding* controlBinding, const std::string& text, const zeus::CColor& textColor,
|
||||
IButtonBinding* controlBinding, std::string_view text, const zeus::CColor& textColor,
|
||||
Icon* icon=nullptr, Style style=Style::Block, const zeus::CColor& bgColor=zeus::CColor::skWhite,
|
||||
RectangleConstraint constraint=RectangleConstraint());
|
||||
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
||||
|
@ -107,10 +107,10 @@ public:
|
|||
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
|
||||
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
||||
|
||||
void setText(const std::string& text, const zeus::CColor& textColor);
|
||||
void setText(const std::string& text);
|
||||
void setText(std::string_view text, const zeus::CColor& textColor);
|
||||
void setText(std::string_view text);
|
||||
void setIcon(Icon* icon=nullptr);
|
||||
const std::string& getText() const {return m_textStr;}
|
||||
std::string_view getText() const {return m_textStr;}
|
||||
void colorGlyphs(const zeus::CColor& newColor);
|
||||
int nominalWidth() const {return m_nomWidth;}
|
||||
int nominalHeight() const {return m_nomHeight;}
|
||||
|
|
|
@ -10,8 +10,8 @@ class Button;
|
|||
|
||||
struct IControlBinding
|
||||
{
|
||||
virtual const char* name(const Control* control) const=0;
|
||||
virtual const char* help(const Control* control) const {return nullptr;}
|
||||
virtual std::string_view name(const Control* control) const=0;
|
||||
virtual std::string_view help(const Control* control) const {return {};}
|
||||
};
|
||||
|
||||
struct IButtonBinding : IControlBinding
|
||||
|
@ -58,7 +58,7 @@ struct IIntBinding : IControlBinding
|
|||
struct IStringBinding : IControlBinding
|
||||
{
|
||||
virtual std::string getDefault(const Control* control) const {return "";}
|
||||
virtual void changed(const Control* control, const std::string& val)=0;
|
||||
virtual void changed(const Control* control, std::string_view val)=0;
|
||||
};
|
||||
|
||||
struct CVarControlBinding : IControlBinding
|
||||
|
@ -66,8 +66,8 @@ struct CVarControlBinding : IControlBinding
|
|||
hecl::CVar* m_cvar;
|
||||
CVarControlBinding(hecl::CVar* cvar)
|
||||
: m_cvar(cvar) {}
|
||||
const char* name(const Control* control) const {return m_cvar->name().c_str();}
|
||||
const char* help(const Control* control) const {return m_cvar->rawHelp().c_str();}
|
||||
std::string_view name(const Control* control) const {return m_cvar->name();}
|
||||
std::string_view help(const Control* control) const {return m_cvar->rawHelp();}
|
||||
};
|
||||
|
||||
class Control : public View
|
||||
|
|
|
@ -60,13 +60,13 @@ private:
|
|||
FileBrowser& m_fb;
|
||||
ViewChild<std::unique_ptr<Button>> m_button;
|
||||
std::string m_text;
|
||||
OKButton(FileBrowser& fb, ViewResources& res, const std::string& text)
|
||||
OKButton(FileBrowser& fb, ViewResources& res, std::string_view text)
|
||||
: m_fb(fb), m_text(text)
|
||||
{
|
||||
m_button.m_view.reset(new Button(res, fb, this, text, nullptr, Button::Style::Block, zeus::CColor::skWhite,
|
||||
RectangleConstraint(100 * res.pixelFactor(), -1, RectangleConstraint::Test::Minimum)));
|
||||
}
|
||||
const char* name(const Control* control) const {return m_text.c_str();}
|
||||
std::string_view name(const Control* control) const {return m_text;}
|
||||
void activated(const Button* button, const boo::SWindowCoord&) {m_fb.okActivated(true);}
|
||||
} m_ok;
|
||||
|
||||
|
@ -76,13 +76,13 @@ private:
|
|||
FileBrowser& m_fb;
|
||||
ViewChild<std::unique_ptr<Button>> m_button;
|
||||
std::string m_text;
|
||||
CancelButton(FileBrowser& fb, ViewResources& res, const std::string& text)
|
||||
CancelButton(FileBrowser& fb, ViewResources& res, std::string_view text)
|
||||
: m_fb(fb), m_text(text)
|
||||
{
|
||||
m_button.m_view.reset(new Button(res, fb, this, text, nullptr, Button::Style::Block, zeus::CColor::skWhite,
|
||||
RectangleConstraint(m_fb.m_ok.m_button.m_view->nominalWidth(), -1, RectangleConstraint::Test::Minimum)));
|
||||
}
|
||||
const char* name(const Control* control) const {return m_text.c_str();}
|
||||
std::string_view name(const Control* control) const {return m_text;}
|
||||
void activated(const Button* button, const boo::SWindowCoord&) {m_fb.cancelActivated();}
|
||||
} m_cancel;
|
||||
|
||||
|
@ -96,8 +96,8 @@ private:
|
|||
std::string m_name;
|
||||
FileFieldBind(FileBrowser& browser, const IViewManager& vm)
|
||||
: m_browser(browser), m_name(vm.translateOr("file_name", "File Name")) {}
|
||||
const char* name(const Control* control) const {return m_name.c_str();}
|
||||
void changed(const Control* control, const std::string& val)
|
||||
std::string_view name(const Control* control) const {return m_name;}
|
||||
void changed(const Control* control, std::string_view val)
|
||||
{
|
||||
}
|
||||
} m_fileFieldBind;
|
||||
|
@ -128,34 +128,34 @@ private:
|
|||
size_t columnCount() const {return 3;}
|
||||
size_t rowCount() const {return m_entries.size();}
|
||||
|
||||
const std::string* header(size_t cIdx) const
|
||||
std::string_view header(size_t cIdx) const
|
||||
{
|
||||
switch (cIdx)
|
||||
{
|
||||
case 0:
|
||||
return &m_nameCol;
|
||||
return m_nameCol;
|
||||
case 1:
|
||||
return &m_typeCol;
|
||||
return m_typeCol;
|
||||
case 2:
|
||||
return &m_sizeCol;
|
||||
return m_sizeCol;
|
||||
default: break;
|
||||
}
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
const std::string* cell(size_t cIdx, size_t rIdx) const
|
||||
std::string_view cell(size_t cIdx, size_t rIdx) const
|
||||
{
|
||||
switch (cIdx)
|
||||
{
|
||||
case 0:
|
||||
return &m_entries.at(rIdx).m_name;
|
||||
return m_entries.at(rIdx).m_name;
|
||||
case 1:
|
||||
return &m_entries.at(rIdx).m_type;
|
||||
return m_entries.at(rIdx).m_type;
|
||||
case 2:
|
||||
return &m_entries.at(rIdx).m_size;
|
||||
return m_entries.at(rIdx).m_size;
|
||||
default: break;
|
||||
}
|
||||
return nullptr;
|
||||
return {};
|
||||
}
|
||||
|
||||
float m_columnSplits[3] = {0.0f, 0.7f, 0.9f};
|
||||
|
@ -182,7 +182,7 @@ private:
|
|||
m_entries.emplace_back();
|
||||
Entry& ent = m_entries.back();
|
||||
ent.m_path = d.m_path;
|
||||
hecl::SystemUTF8View nameUtf8(d.m_name);
|
||||
hecl::SystemUTF8Conv nameUtf8(d.m_name);
|
||||
ent.m_name = nameUtf8.str();
|
||||
if (d.m_isDir)
|
||||
{
|
||||
|
@ -262,10 +262,10 @@ private:
|
|||
Entry(std::pair<hecl::SystemString, std::string>&& path)
|
||||
: m_path(std::move(path.first)), m_name(std::move(path.second)) {}
|
||||
|
||||
Entry(const hecl::SystemString& path)
|
||||
Entry(hecl::SystemStringView path)
|
||||
: m_path(path)
|
||||
{
|
||||
hecl::SystemUTF8View utf8(path);
|
||||
hecl::SystemUTF8Conv utf8(path);
|
||||
if (utf8.str().size() == 1 && utf8.str()[0] == '/')
|
||||
{
|
||||
m_name = "/";
|
||||
|
@ -283,9 +283,9 @@ private:
|
|||
size_t columnCount() const {return 1;}
|
||||
size_t rowCount() const {return m_entries.size();}
|
||||
|
||||
const std::string* cell(size_t, size_t rIdx) const
|
||||
std::string_view cell(size_t, size_t rIdx) const
|
||||
{
|
||||
return &m_entries.at(rIdx).m_name;
|
||||
return m_entries.at(rIdx).m_name;
|
||||
}
|
||||
|
||||
void setSelectedRow(size_t rIdx)
|
||||
|
@ -312,21 +312,21 @@ private:
|
|||
std::unique_ptr<TextView> m_recentBookmarksLabel;
|
||||
ViewChild<std::unique_ptr<Table>> m_recentBookmarks;
|
||||
|
||||
std::function<void(bool, const hecl::SystemString&)> m_returnFunc;
|
||||
std::function<void(bool, hecl::SystemStringView)> m_returnFunc;
|
||||
|
||||
public:
|
||||
FileBrowser(ViewResources& res, View& parentView, const std::string& title, Type type,
|
||||
std::function<void(bool, const hecl::SystemString&)> returnFunc)
|
||||
FileBrowser(ViewResources& res, View& parentView, std::string_view title, Type type,
|
||||
std::function<void(bool, hecl::SystemStringView)> returnFunc)
|
||||
: FileBrowser(res, parentView, title, type, hecl::GetcwdStr(), returnFunc) {}
|
||||
FileBrowser(ViewResources& res, View& parentView, const std::string& title, Type type,
|
||||
const hecl::SystemString& initialPath,
|
||||
std::function<void(bool, const hecl::SystemString&)> returnFunc);
|
||||
FileBrowser(ViewResources& res, View& parentView, std::string_view title, Type type,
|
||||
hecl::SystemStringView initialPath,
|
||||
std::function<void(bool, hecl::SystemStringView)> returnFunc);
|
||||
|
||||
static std::vector<hecl::SystemString> PathComponents(const hecl::SystemString& path);
|
||||
static std::vector<hecl::SystemString> PathComponents(hecl::SystemStringView path);
|
||||
static void SyncBookmarkSelections(Table& table, BookmarkDataBind& binding,
|
||||
const hecl::SystemString& sel);
|
||||
|
||||
void navigateToPath(const hecl::SystemString& path);
|
||||
void navigateToPath(hecl::SystemStringView path);
|
||||
bool showingHidden() const {return m_showingHidden;}
|
||||
void setShowingHidden(bool showingHidden)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ class FontTag
|
|||
{
|
||||
friend class FontCache;
|
||||
uint64_t m_hash = 0;
|
||||
FontTag(const std::string& name, bool subpixel, float points, unsigned dpi);
|
||||
FontTag(std::string_view name, bool subpixel, float points, unsigned dpi);
|
||||
public:
|
||||
FontTag() = default;
|
||||
operator bool() const {return m_hash != 0;}
|
||||
|
@ -171,7 +171,7 @@ public:
|
|||
FontCache(const FontCache& other) = delete;
|
||||
FontCache& operator=(const FontCache& other) = delete;
|
||||
|
||||
FontTag prepCustomFont(boo::IGraphicsDataFactory* gf, const std::string& name, FT_Face face,
|
||||
FontTag prepCustomFont(boo::IGraphicsDataFactory* gf, std::string_view name, FT_Face face,
|
||||
FCharFilter filter=AllCharFilter, bool subpixel=false,
|
||||
float points=10.0, uint32_t dpi=72);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ struct IViewManager
|
|||
{
|
||||
public:
|
||||
virtual const Translator* getTranslator() const {return nullptr;}
|
||||
virtual std::string translateOr(const std::string& key, const char* vor) const
|
||||
virtual std::string_view translateOr(std::string_view key, std::string_view vor) const
|
||||
{
|
||||
const Translator* trans = getTranslator();
|
||||
if (trans)
|
||||
|
@ -25,10 +25,10 @@ public:
|
|||
const boo::SWindowCoord& coord) {}
|
||||
|
||||
virtual const std::vector<hecl::SystemString>* recentProjects() const {return nullptr;}
|
||||
virtual void pushRecentProject(const hecl::SystemString& path) {}
|
||||
virtual void pushRecentProject(hecl::SystemStringView path) {}
|
||||
|
||||
virtual const std::vector<hecl::SystemString>* recentFiles() const {return nullptr;}
|
||||
virtual void pushRecentFile(const hecl::SystemString& path) {}
|
||||
virtual void pushRecentFile(hecl::SystemStringView path) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class Menu : public View
|
|||
std::unique_ptr<TextView> m_textView;
|
||||
size_t m_idx;
|
||||
IMenuNode* m_node;
|
||||
ItemView(ViewResources& res, Menu& menu, const std::string& text, size_t idx, IMenuNode* node);
|
||||
ItemView(ViewResources& res, Menu& menu, std::string_view text, size_t idx, IMenuNode* node);
|
||||
|
||||
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
||||
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
||||
|
|
|
@ -28,8 +28,8 @@ private:
|
|||
{
|
||||
MessageWindow& m_mw;
|
||||
std::string m_name;
|
||||
OKBinding(MessageWindow& mw, std::string&& name) : m_mw(mw), m_name(std::move(name)) {}
|
||||
const char* name(const Control* control) const {return m_name.c_str();}
|
||||
OKBinding(MessageWindow& mw, std::string_view name) : m_mw(mw), m_name(name) {}
|
||||
std::string_view name(const Control* control) const {return m_name;}
|
||||
void activated(const Button* button, const boo::SWindowCoord& coord)
|
||||
{
|
||||
m_mw.m_func(true);
|
||||
|
@ -41,8 +41,8 @@ private:
|
|||
{
|
||||
MessageWindow& m_mw;
|
||||
std::string m_name;
|
||||
CancelBinding(MessageWindow& mw, std::string&& name) : m_mw(mw), m_name(std::move(name)) {}
|
||||
const char* name(const Control* control) const {return m_name.c_str();}
|
||||
CancelBinding(MessageWindow& mw, std::string_view name) : m_mw(mw), m_name(name) {}
|
||||
std::string_view name(const Control* control) const {return m_name;}
|
||||
void activated(const Button* button, const boo::SWindowCoord& coord)
|
||||
{
|
||||
m_mw.m_func(false);
|
||||
|
@ -52,7 +52,7 @@ private:
|
|||
|
||||
public:
|
||||
MessageWindow(ViewResources& res, View& parentView,
|
||||
Type type, const std::string& message, std::function<void(bool ok)> func);
|
||||
Type type, std::string_view message, std::function<void(bool ok)> func);
|
||||
|
||||
void updateContentOpacity(float opacity)
|
||||
{
|
||||
|
|
|
@ -17,8 +17,8 @@ class MultiLineTextView : public View
|
|||
size_t m_lineCapacity;
|
||||
float m_lineHeight;
|
||||
int m_width;
|
||||
std::string LineWrap(const std::string& str, int wrap);
|
||||
std::wstring LineWrap(const std::wstring& str, int wrap);
|
||||
std::string LineWrap(std::string_view str, int wrap);
|
||||
std::wstring LineWrap(std::wstring_view str, int wrap);
|
||||
|
||||
public:
|
||||
MultiLineTextView(ViewResources& res, View& parentView, const FontAtlas& font,
|
||||
|
@ -28,10 +28,10 @@ public:
|
|||
TextView::Alignment align=TextView::Alignment::Left,
|
||||
size_t lineCapacity=256, float lineHeight=1.0);
|
||||
|
||||
void typesetGlyphs(const std::string& str,
|
||||
void typesetGlyphs(std::string_view str,
|
||||
const zeus::CColor& defaultColor=zeus::CColor::skWhite,
|
||||
unsigned wrap=0);
|
||||
void typesetGlyphs(const std::wstring& str,
|
||||
void typesetGlyphs(std::wstring_view str,
|
||||
const zeus::CColor& defaultColor=zeus::CColor::skWhite,
|
||||
unsigned wrap=0);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
void init(boo::IGraphicsDataFactory* factory, const IThemeData& theme);
|
||||
};
|
||||
|
||||
NumericField(ViewResources& res, View& parentView, const std::string& text);
|
||||
NumericField(ViewResources& res, View& parentView, std::string_view text);
|
||||
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
||||
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
||||
void mouseEnter(const boo::SWindowCoord&);
|
||||
|
@ -45,7 +45,7 @@ public:
|
|||
void resized(const boo::SWindowRect& rootView, const boo::SWindowRect& sub);
|
||||
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
||||
|
||||
void setText(const std::string& text);
|
||||
void setText(std::string_view text);
|
||||
int nominalWidth() const {return m_nomWidth;}
|
||||
int nominalHeight() const {return m_nomHeight;}
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ class Outliner
|
|||
void init(boo::IGraphicsDataFactory* factory, const IThemeData& theme);
|
||||
};
|
||||
|
||||
Node(ViewResources& res, View& parentView, const std::string& description);
|
||||
Node(ViewResources& res, View& parentView, std::string_view description);
|
||||
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
||||
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
|
||||
void mouseEnter(const boo::SWindowCoord&);
|
||||
|
|
|
@ -55,9 +55,9 @@ class PathButtons : public ScrollView
|
|||
PathButton(PathButtons& pb, ViewResources& res, size_t idx, const hecl::SystemString& str)
|
||||
: m_pb(pb), m_idx(idx)
|
||||
{
|
||||
m_button.m_view.reset(new Button(res, pb, this, hecl::SystemUTF8View(str).str()));
|
||||
m_button.m_view.reset(new Button(res, pb, this, hecl::SystemUTF8Conv(str).str()));
|
||||
}
|
||||
const char* name(const Control* control) const {return m_button.m_view->getText().c_str();}
|
||||
std::string_view name(const Control* control) const {return m_button.m_view->getText();}
|
||||
void activated(const Button* button, const boo::SWindowCoord&) {m_pb.m_pathButtonPending = m_idx;}
|
||||
};
|
||||
friend struct PathButton;
|
||||
|
|
|
@ -220,7 +220,7 @@ public:
|
|||
}
|
||||
|
||||
void resetTooltip(ViewResources& res);
|
||||
void displayTooltip(const std::string& name, const std::string& help);
|
||||
void displayTooltip(std::string_view name, std::string_view help);
|
||||
|
||||
void beginInteractiveJoin(SplitView* sv, const boo::SWindowCoord& coord)
|
||||
{
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
: m_sv(sv),
|
||||
m_leftName(vm.translateOr("scroll_left", "Scroll Left")),
|
||||
m_rightName(vm.translateOr("scroll_right", "Scroll Right")) {}
|
||||
const char* name(const Control* control) const
|
||||
std::string_view name(const Control* control) const
|
||||
{
|
||||
return (control == reinterpret_cast<Control*>(m_sv.m_sideButtons[0].m_view.get())) ?
|
||||
m_leftName.c_str() : m_rightName.c_str();
|
||||
|
|
|
@ -21,8 +21,8 @@ struct ITableDataBinding
|
|||
{
|
||||
virtual size_t columnCount() const=0;
|
||||
virtual size_t rowCount() const=0;
|
||||
virtual const std::string* header(size_t cIdx) const {return nullptr;}
|
||||
virtual const std::string* cell(size_t cIdx, size_t rIdx) const {return nullptr;}
|
||||
virtual std::string_view header(size_t cIdx) const {return nullptr;}
|
||||
virtual std::string_view cell(size_t cIdx, size_t rIdx) const {return nullptr;}
|
||||
};
|
||||
|
||||
struct ITableStateBinding
|
||||
|
|
|
@ -69,8 +69,8 @@ class TextField : public ITextInputView
|
|||
public:
|
||||
TextField(ViewResources& res, View& parentView, IStringBinding* strBind);
|
||||
|
||||
const std::string& getText() const {return m_textStr;}
|
||||
void setText(const std::string& str);
|
||||
std::string_view getText() const {return m_textStr;}
|
||||
void setText(std::string_view str);
|
||||
|
||||
void clipboardCopy();
|
||||
void clipboardCut();
|
||||
|
@ -86,14 +86,14 @@ public:
|
|||
bool hasMarkedText() const;
|
||||
std::pair<int,int> markedRange() const;
|
||||
std::pair<int,int> selectedRange() const;
|
||||
void setMarkedText(const std::string& str,
|
||||
void setMarkedText(std::string_view str,
|
||||
const std::pair<int,int>& selectedRange,
|
||||
const std::pair<int,int>& replacementRange);
|
||||
void unmarkText();
|
||||
|
||||
std::string substringForRange(const std::pair<int,int>& range,
|
||||
std::pair<int,int>& actualRange) const;
|
||||
void insertText(const std::string& str, const std::pair<int,int>& range);
|
||||
void insertText(std::string_view str, const std::pair<int,int>& range);
|
||||
int characterIndexAtPoint(const boo::SWindowCoord& point) const;
|
||||
boo::SWindowRect rectForCharacterRange(const std::pair<int,int>& range,
|
||||
std::pair<int,int>& actualRange) const;
|
||||
|
@ -107,7 +107,7 @@ public:
|
|||
|
||||
void setActive(bool active);
|
||||
void setCursorPos(size_t pos);
|
||||
void setErrorState(const std::string& message);
|
||||
void setErrorState(std::string_view message);
|
||||
void clearErrorState();
|
||||
|
||||
void setSelectionRange(size_t start, size_t count);
|
||||
|
|
|
@ -117,9 +117,9 @@ public:
|
|||
std::vector<RenderGlyph>& accessGlyphs() {return m_glyphs;}
|
||||
const std::vector<RenderGlyph>& accessGlyphs() const {return m_glyphs;}
|
||||
|
||||
void typesetGlyphs(const std::string& str,
|
||||
void typesetGlyphs(std::string_view str,
|
||||
const zeus::CColor& defaultColor=zeus::CColor::skWhite);
|
||||
void typesetGlyphs(const std::wstring& str,
|
||||
void typesetGlyphs(std::wstring_view str,
|
||||
const zeus::CColor& defaultColor=zeus::CColor::skWhite);
|
||||
void invalidateGlyphs();
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ class Tooltip : public View
|
|||
std::unique_ptr<TextView> m_cornersOutline[4];
|
||||
std::unique_ptr<TextView> m_cornersFilled[4];
|
||||
public:
|
||||
Tooltip(ViewResources& res, View& parentView, const std::string& title,
|
||||
const std::string& message);
|
||||
Tooltip(ViewResources& res, View& parentView, std::string_view title,
|
||||
std::string_view message);
|
||||
void resized(const boo::SWindowRect& rootView, const boo::SWindowRect& sub);
|
||||
void draw(boo::IGraphicsCommandQueue* gfxQ);
|
||||
|
||||
|
|
|
@ -9,15 +9,15 @@ namespace specter
|
|||
|
||||
class Locale
|
||||
{
|
||||
std::string m_name;
|
||||
std::string m_fullName;
|
||||
std::string_view m_name;
|
||||
std::string_view m_fullName;
|
||||
std::unique_ptr<athena::io::YAMLNode> m_rootNode;
|
||||
const athena::io::YAMLNode* m_langNode;
|
||||
public:
|
||||
Locale(const std::string& name, const std::string& fullName,
|
||||
Locale(std::string_view name, std::string_view fullName,
|
||||
const unsigned char* yamlSource, size_t yamlLength);
|
||||
const std::string& name() const {return m_name;}
|
||||
const std::string& fullName() const {return m_fullName;}
|
||||
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;}
|
||||
};
|
||||
|
||||
|
@ -27,8 +27,8 @@ class Translator
|
|||
public:
|
||||
Translator(const Locale* targetLocale) {setLocale(targetLocale);}
|
||||
void setLocale(const Locale* targetLocale);
|
||||
const std::string* translate(const std::string& key) const;
|
||||
std::string translateOr(const std::string& key, const char* vor) const;
|
||||
std::string_view translate(std::string_view key) const;
|
||||
std::string_view translateOr(std::string_view key, std::string_view vor) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -12,12 +12,12 @@ void Button::Resources::init(boo::IGraphicsDataFactory::Context& ctx, const IThe
|
|||
}
|
||||
|
||||
Button::Button(ViewResources& res, View& parentView,
|
||||
IButtonBinding* controlBinding, const std::string& text, Icon* icon,
|
||||
IButtonBinding* controlBinding, std::string_view text, Icon* icon,
|
||||
Style style, const zeus::CColor& bgColor, RectangleConstraint constraint)
|
||||
: Button(res, parentView, controlBinding, text, res.themeData().uiText(), icon, style, bgColor, constraint) {}
|
||||
|
||||
Button::Button(ViewResources& res, View& parentView,
|
||||
IButtonBinding* controlBinding, const std::string& text, const zeus::CColor& textColor,
|
||||
IButtonBinding* controlBinding, std::string_view text, const zeus::CColor& textColor,
|
||||
Icon* icon, Style style, const zeus::CColor& bgColor, RectangleConstraint constraint)
|
||||
: Control(res, parentView, controlBinding),
|
||||
m_style(style), m_textColor(textColor), m_bgColor(bgColor), m_textStr(text), m_constraint(constraint)
|
||||
|
@ -71,12 +71,12 @@ Button::Button(ViewResources& res, View& parentView,
|
|||
setText(m_textStr);
|
||||
}
|
||||
|
||||
void Button::setText(const std::string& text)
|
||||
void Button::setText(std::string_view text)
|
||||
{
|
||||
setText(text, m_textColor);
|
||||
}
|
||||
|
||||
void Button::setText(const std::string& text, const zeus::CColor& textColor)
|
||||
void Button::setText(std::string_view text, const zeus::CColor& textColor)
|
||||
{
|
||||
m_textStr = text;
|
||||
m_textColor = textColor;
|
||||
|
|
|
@ -10,10 +10,10 @@ static logvisor::Module Log("specter::FileBrowser");
|
|||
#define BROWSER_MIN_WIDTH 600
|
||||
#define BROWSER_MIN_HEIGHT 300
|
||||
|
||||
std::vector<hecl::SystemString> FileBrowser::PathComponents(const hecl::SystemString& path)
|
||||
std::vector<hecl::SystemString> FileBrowser::PathComponents(hecl::SystemStringView path)
|
||||
{
|
||||
std::vector<hecl::SystemString> ret;
|
||||
hecl::SystemString sPath = path;
|
||||
hecl::SystemString sPath(path);
|
||||
hecl::SanitizePath(sPath);
|
||||
if (sPath.empty())
|
||||
return ret;
|
||||
|
@ -41,9 +41,9 @@ std::vector<hecl::SystemString> FileBrowser::PathComponents(const hecl::SystemSt
|
|||
return ret;
|
||||
}
|
||||
|
||||
FileBrowser::FileBrowser(ViewResources& res, View& parentView, const std::string& title,
|
||||
Type type, const hecl::SystemString& initialPath,
|
||||
std::function<void(bool, const hecl::SystemString&)> returnFunc)
|
||||
FileBrowser::FileBrowser(ViewResources& res, View& parentView, std::string_view title,
|
||||
Type type, hecl::SystemStringView initialPath,
|
||||
std::function<void(bool, hecl::SystemStringView)> returnFunc)
|
||||
: ModalWindow(res, parentView, RectangleConstraint(BROWSER_MIN_WIDTH * res.pixelFactor(),
|
||||
BROWSER_MIN_HEIGHT * res.pixelFactor(),
|
||||
RectangleConstraint::Test::Minimum,
|
||||
|
@ -121,18 +121,18 @@ void FileBrowser::SyncBookmarkSelections(Table& table, BookmarkDataBind& binding
|
|||
table.selectRow(-1);
|
||||
}
|
||||
|
||||
void FileBrowser::navigateToPath(const hecl::SystemString& path)
|
||||
void FileBrowser::navigateToPath(hecl::SystemStringView path)
|
||||
{
|
||||
hecl::Sstat theStat;
|
||||
if (hecl::Stat(path.c_str(), &theStat))
|
||||
if (hecl::Stat(path.data(), &theStat))
|
||||
return;
|
||||
|
||||
m_path = path;
|
||||
m_path = hecl::SystemString(path);
|
||||
m_comps = PathComponents(m_path);
|
||||
if (S_ISREG(theStat.st_mode))
|
||||
{
|
||||
hecl::SystemUTF8View utf8(m_comps.back());
|
||||
m_fileField.m_view->setText(utf8);
|
||||
hecl::SystemUTF8Conv utf8(m_comps.back());
|
||||
m_fileField.m_view->setText(utf8.str());
|
||||
m_fileField.m_view->clearErrorState();
|
||||
m_comps.pop_back();
|
||||
}
|
||||
|
@ -200,15 +200,15 @@ void FileBrowser::okActivated(bool viaButton)
|
|||
hecl::Sstat theStat;
|
||||
if (hecl::Stat(path.c_str(), &theStat) || !S_ISDIR(theStat.st_mode))
|
||||
{
|
||||
hecl::SystemUTF8View utf8(path);
|
||||
hecl::SystemUTF8Conv utf8(path);
|
||||
m_fileField.m_view->setErrorState(
|
||||
hecl::Format(vm.translateOr("no_access_as_dir", "Unable to access '%s' as directory").c_str(),
|
||||
hecl::Format(vm.translateOr("no_access_as_dir", "Unable to access '%s' as directory").data(),
|
||||
utf8.c_str()));
|
||||
return;
|
||||
}
|
||||
|
||||
path += _S('/');
|
||||
path += hecl::SystemStringView(m_fileField.m_view->getText()).sys_str();
|
||||
path += hecl::SystemStringConv(m_fileField.m_view->getText()).sys_str();
|
||||
|
||||
int err = hecl::Stat(path.c_str(), &theStat);
|
||||
if (m_type == Type::SaveFile)
|
||||
|
@ -216,15 +216,15 @@ void FileBrowser::okActivated(bool viaButton)
|
|||
if (m_fileField.m_view->getText().empty())
|
||||
{
|
||||
m_fileField.m_view->setErrorState(
|
||||
vm.translateOr("file_field_empty", "Unable to save empty file").c_str());
|
||||
vm.translateOr("file_field_empty", "Unable to save empty file"));
|
||||
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'?").c_str(), path.c_str()),
|
||||
[&,path](bool ok)
|
||||
MessageWindow::Type::ConfirmOkCancel,
|
||||
hecl::Format(vm.translateOr("overwrite_confirm", "Overwrite '%s'?").data(), path.c_str()),
|
||||
[&,path](bool ok)
|
||||
{
|
||||
if (ok)
|
||||
{
|
||||
|
@ -252,13 +252,13 @@ void FileBrowser::okActivated(bool viaButton)
|
|||
if (m_fileField.m_view->getText().empty())
|
||||
{
|
||||
m_fileField.m_view->setErrorState(
|
||||
vm.translateOr("directory_field_empty", "Unable to make empty-named directory").c_str());
|
||||
vm.translateOr("directory_field_empty", "Unable to make empty-named directory"));
|
||||
return;
|
||||
}
|
||||
if (!err && !S_ISDIR(theStat.st_mode))
|
||||
{
|
||||
m_fileField.m_view->setErrorState(
|
||||
vm.translateOr("no_overwrite_file", "Unable to make directory over file").c_str());
|
||||
vm.translateOr("no_overwrite_file", "Unable to make directory over file"));
|
||||
return;
|
||||
}
|
||||
if (!err && S_ISDIR(theStat.st_mode))
|
||||
|
@ -269,7 +269,7 @@ void FileBrowser::okActivated(bool viaButton)
|
|||
if (projRoot)
|
||||
{
|
||||
m_fileField.m_view->setErrorState(
|
||||
vm.translateOr("no_overwrite_project", "Unable to make project within existing project").c_str());
|
||||
vm.translateOr("no_overwrite_project", "Unable to make project within existing project"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -290,9 +290,9 @@ void FileBrowser::okActivated(bool viaButton)
|
|||
}
|
||||
else if (err || !S_ISREG(theStat.st_mode))
|
||||
{
|
||||
hecl::SystemUTF8View utf8(path);
|
||||
hecl::SystemUTF8Conv utf8(path);
|
||||
m_fileField.m_view->setErrorState(
|
||||
hecl::Format(vm.translateOr("no_access_as_file", "Unable to access '%s' as file").c_str(),
|
||||
hecl::Format(vm.translateOr("no_access_as_file", "Unable to access '%s' as file").data(),
|
||||
utf8.c_str()));
|
||||
return;
|
||||
}
|
||||
|
@ -319,9 +319,9 @@ void FileBrowser::okActivated(bool viaButton)
|
|||
}
|
||||
if (err || !S_ISDIR(theStat.st_mode))
|
||||
{
|
||||
hecl::SystemUTF8View utf8(path);
|
||||
hecl::SystemUTF8Conv utf8(path);
|
||||
m_fileField.m_view->setErrorState(
|
||||
hecl::Format(vm.translateOr("no_access_as_dir", "Unable to access '%s' as directory").c_str(),
|
||||
hecl::Format(vm.translateOr("no_access_as_dir", "Unable to access '%s' as directory").data(),
|
||||
utf8.c_str()));
|
||||
return;
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ void FileBrowser::cancelActivated()
|
|||
}
|
||||
|
||||
path += _S('/');
|
||||
path += hecl::SystemStringView(m_fileField.m_view->getText()).sys_str();
|
||||
path += hecl::SystemStringConv(m_fileField.m_view->getText()).sys_str();
|
||||
|
||||
m_returnFunc(false, path);
|
||||
close();
|
||||
|
|
|
@ -45,7 +45,7 @@ std::make_pair("latin-and-jp-glyphs", [](uint32_t c)->bool
|
|||
((c - 0x4E00) <= (0x9FFF - 0x4E00)) ||
|
||||
((c - 0xFF00) <= (0xFFEF - 0xFF00));});
|
||||
|
||||
FontTag::FontTag(const std::string& name, bool subpixel, float points, uint32_t dpi)
|
||||
FontTag::FontTag(std::string_view name, bool subpixel, float points, uint32_t dpi)
|
||||
{
|
||||
XXH64_state_t st;
|
||||
XXH64_reset(&st, 0);
|
||||
|
@ -711,7 +711,7 @@ FontCache::Library::~Library()
|
|||
|
||||
FontCache::FontCache(const hecl::Runtime::FileStoreManager& fileMgr)
|
||||
: m_fileMgr(fileMgr),
|
||||
m_cacheRoot(m_fileMgr.getStoreRoot() + _S("/fontcache")),
|
||||
m_cacheRoot(hecl::SystemString(m_fileMgr.getStoreRoot()) + _S("/fontcache")),
|
||||
m_regFace(m_fontLib, DROIDSANS_PERMISSIVE, DROIDSANS_PERMISSIVE_SZ),
|
||||
m_monoFace(m_fontLib, BMONOFONT, BMONOFONT_SZ),
|
||||
m_curvesFace(m_fontLib, SPECTERCURVES, SPECTERCURVES_SZ)
|
||||
|
@ -719,7 +719,7 @@ FontCache::FontCache(const hecl::Runtime::FileStoreManager& fileMgr)
|
|||
hecl::MakeDir(m_cacheRoot.c_str());
|
||||
}
|
||||
|
||||
FontTag FontCache::prepCustomFont(boo::IGraphicsDataFactory* gf, const std::string& name, FT_Face face,
|
||||
FontTag FontCache::prepCustomFont(boo::IGraphicsDataFactory* gf, std::string_view name, FT_Face face,
|
||||
FCharFilter filter, bool subpixel,
|
||||
float points, uint32_t dpi)
|
||||
{
|
||||
|
@ -734,7 +734,7 @@ FontTag FontCache::prepCustomFont(boo::IGraphicsDataFactory* gf, const std::stri
|
|||
FT_Set_Char_Size(face, 0, points * 64.0, 0, dpi);
|
||||
|
||||
/* Make tag and search for cached version */
|
||||
FontTag tag(name + '_' + filter.first, subpixel, points, dpi);
|
||||
FontTag tag(std::string(name) + '_' + filter.first, subpixel, points, dpi);
|
||||
auto search = m_cachedAtlases.find(tag);
|
||||
if (search != m_cachedAtlases.end())
|
||||
return tag;
|
||||
|
|
|
@ -100,7 +100,7 @@ Menu::ContentView::ContentView(ViewResources& res, Menu& menu)
|
|||
m_hlVerts[3].m_color = res.themeData().button2Hover();
|
||||
}
|
||||
|
||||
Menu::ItemView::ItemView(ViewResources& res, Menu& menu, const std::string& text, size_t idx, IMenuNode* node)
|
||||
Menu::ItemView::ItemView(ViewResources& res, Menu& menu, std::string_view text, size_t idx, IMenuNode* node)
|
||||
: View(res, menu), m_menu(menu), m_idx(idx), m_node(node)
|
||||
{
|
||||
commitResources(res, [&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace specter
|
|||
{
|
||||
|
||||
MessageWindow::MessageWindow(ViewResources& res, View& parentView,
|
||||
Type type, const std::string& message,
|
||||
Type type, std::string_view message,
|
||||
std::function<void (bool)> func)
|
||||
: ModalWindow(res, parentView, RectangleConstraint(),
|
||||
type==Type::ErrorOk ? res.themeData().splashErrorBackground() : res.themeData().splashBackground()),
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace specter
|
|||
{
|
||||
static logvisor::Module Log("specter::MultiLineTextView");
|
||||
|
||||
std::string MultiLineTextView::LineWrap(const std::string& str, int wrap)
|
||||
std::string MultiLineTextView::LineWrap(std::string_view str, int wrap)
|
||||
{
|
||||
size_t rem = str.size();
|
||||
const utf8proc_uint8_t* it = reinterpret_cast<const utf8proc_uint8_t*>(str.data());
|
||||
|
@ -74,16 +74,16 @@ std::string MultiLineTextView::LineWrap(const std::string& str, int wrap)
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::wstring MultiLineTextView::LineWrap(const std::wstring& str, int wrap)
|
||||
std::wstring MultiLineTextView::LineWrap(std::wstring_view str, int wrap)
|
||||
{
|
||||
uint32_t lCh = -1;
|
||||
int adv = 0;
|
||||
|
||||
std::wstring ret;
|
||||
ret.reserve(str.size());
|
||||
std::wstring::const_iterator lastSpaceIt = str.cend();
|
||||
std::wstring_view::const_iterator lastSpaceIt = str.cend();
|
||||
size_t rollbackPos;
|
||||
for (std::wstring::const_iterator it = str.cbegin() ; it != str.cend() ; ++it)
|
||||
for (std::wstring_view::const_iterator it = str.cbegin() ; it != str.cend() ; ++it)
|
||||
{
|
||||
wchar_t ch = *it;
|
||||
if (ch == L'\n')
|
||||
|
@ -159,7 +159,7 @@ MultiLineTextView::MultiLineTextView(ViewResources& res,
|
|||
lineCapacity,
|
||||
lineHeight) {}
|
||||
|
||||
void MultiLineTextView::typesetGlyphs(const std::string& str,
|
||||
void MultiLineTextView::typesetGlyphs(std::string_view str,
|
||||
const zeus::CColor& defaultColor,
|
||||
unsigned wrap)
|
||||
{
|
||||
|
@ -210,7 +210,7 @@ void MultiLineTextView::typesetGlyphs(const std::string& str,
|
|||
updateSize();
|
||||
}
|
||||
|
||||
void MultiLineTextView::typesetGlyphs(const std::wstring& str,
|
||||
void MultiLineTextView::typesetGlyphs(std::wstring_view str,
|
||||
const zeus::CColor& defaultColor,
|
||||
unsigned wrap)
|
||||
{
|
||||
|
|
|
@ -588,7 +588,7 @@ void RootView::resetTooltip(ViewResources& res)
|
|||
m_tooltip.reset(new Tooltip(res, *this, "Test", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi hendrerit nisl quis lobortis mattis. Mauris efficitur, est a vestibulum iaculis, leo orci pellentesque nunc, non rutrum ipsum lectus eget nisl. Aliquam accumsan vestibulum turpis. Duis id lacus ac lectus sollicitudin posuere vel sit amet metus. Aenean nec tortor id enim efficitur accumsan vitae eu ante. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce magna eros, lacinia a leo eget, volutpat rhoncus urna."));
|
||||
}
|
||||
|
||||
void RootView::displayTooltip(const std::string& name, const std::string& help)
|
||||
void RootView::displayTooltip(std::string_view name, std::string_view help)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -539,13 +539,13 @@ bool Table::CellView::reset(size_t c)
|
|||
{
|
||||
m_c = c;
|
||||
m_r = -1;
|
||||
const std::string* headerText = m_t.m_data->header(c);
|
||||
if (headerText)
|
||||
auto headerText = m_t.m_data->header(c);
|
||||
if (!headerText.empty())
|
||||
{
|
||||
uint64_t hash = XXH64(headerText->data(), headerText->size(), 0);
|
||||
uint64_t hash = XXH64(headerText.data(), headerText.size(), 0);
|
||||
if (hash != m_textHash)
|
||||
{
|
||||
m_text->typesetGlyphs(*headerText, rootView().themeData().uiText());
|
||||
m_text->typesetGlyphs(headerText, rootView().themeData().uiText());
|
||||
m_textHash = hash;
|
||||
}
|
||||
return true;
|
||||
|
@ -562,13 +562,13 @@ bool Table::CellView::reset(size_t c, size_t r)
|
|||
{
|
||||
m_c = c;
|
||||
m_r = r;
|
||||
const std::string* cellText = m_t.m_data->cell(c, r);
|
||||
if (cellText)
|
||||
auto cellText = m_t.m_data->cell(c, r);
|
||||
if (!cellText.empty())
|
||||
{
|
||||
uint64_t hash = XXH64(cellText->data(), cellText->size(), 0);
|
||||
uint64_t hash = XXH64(cellText.data(), cellText.size(), 0);
|
||||
if (hash != m_textHash)
|
||||
{
|
||||
m_text->typesetGlyphs(*cellText, rootView().themeData().uiText());
|
||||
m_text->typesetGlyphs(cellText, rootView().themeData().uiText());
|
||||
m_textHash = hash;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -69,12 +69,13 @@ void TextField::_setMarkedText()
|
|||
repEnd += m_markReplStart + m_markReplCount;
|
||||
}
|
||||
|
||||
size_t len = UTF8Iterator(m_textStr.cbegin()).countTo(m_textStr.cend());
|
||||
std::string_view textStr(m_textStr);
|
||||
size_t len = UTF8Iterator(textStr.cbegin()).countTo(textStr.cend());
|
||||
repPoint = std::min(repPoint, len);
|
||||
repEnd = std::min(repEnd, len);
|
||||
std::string compStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + repPoint).iter());
|
||||
std::string compStr(textStr.cbegin(), (UTF8Iterator(textStr.cbegin()) + repPoint).iter());
|
||||
compStr += m_deferredMarkStr;
|
||||
compStr += std::string((UTF8Iterator(m_textStr.cbegin()) + repEnd).iter(), m_textStr.cend());
|
||||
compStr += std::string((UTF8Iterator(textStr.cbegin()) + repEnd).iter(), textStr.cend());
|
||||
m_text->typesetGlyphs(compStr, m_error ? rootView().themeData().uiText() :
|
||||
rootView().themeData().fieldText());
|
||||
|
||||
|
@ -86,8 +87,9 @@ void TextField::_setMarkedText()
|
|||
else
|
||||
_reallySetCursorPos(pos);
|
||||
|
||||
std::string_view deferredMarkStr(m_deferredMarkStr);
|
||||
std::vector<TextView::RenderGlyph>& glyphs = m_text->accessGlyphs();
|
||||
size_t defLen = UTF8Iterator(m_deferredMarkStr.cbegin()).countTo(m_deferredMarkStr.cend());
|
||||
size_t defLen = UTF8Iterator(deferredMarkStr.cbegin()).countTo(deferredMarkStr.cend());
|
||||
for (auto it=glyphs.begin()+repPoint ; it<glyphs.begin()+repPoint+defLen ; ++it)
|
||||
it->m_color = rootView().themeData().fieldMarkedText();
|
||||
m_text->invalidateGlyphs();
|
||||
|
@ -97,7 +99,7 @@ void TextField::_setMarkedText()
|
|||
}
|
||||
}
|
||||
|
||||
void TextField::setText(const std::string& str)
|
||||
void TextField::setText(std::string_view str)
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> lk(m_textInputLk);
|
||||
UTF8Iterator it(str.cbegin());
|
||||
|
@ -211,7 +213,8 @@ void TextField::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton butt
|
|||
}
|
||||
else if (m_clickFrames2 < 15)
|
||||
{
|
||||
size_t len = UTF8Iterator(m_textStr.cbegin()).countTo(m_textStr.cend());
|
||||
std::string_view textStr(m_textStr);
|
||||
size_t len = UTF8Iterator(textStr.cbegin()).countTo(textStr.cend());
|
||||
setSelectionRange(0, len);
|
||||
}
|
||||
else if (m_clickFrames < 15)
|
||||
|
@ -273,7 +276,8 @@ void TextField::clipboardCopy()
|
|||
if (!m_selectionCount)
|
||||
return;
|
||||
|
||||
UTF8Iterator begin(m_textStr.cbegin());
|
||||
std::string_view textStr(m_textStr);
|
||||
UTF8Iterator begin(textStr.cbegin());
|
||||
begin += m_selectionStart;
|
||||
UTF8Iterator end(begin.iter());
|
||||
end += m_selectionCount;
|
||||
|
@ -289,7 +293,8 @@ void TextField::clipboardCut()
|
|||
if (!m_selectionCount)
|
||||
return;
|
||||
|
||||
UTF8Iterator begin(m_textStr.cbegin());
|
||||
std::string_view textStr(m_textStr);
|
||||
UTF8Iterator begin(textStr.cbegin());
|
||||
begin += m_selectionStart;
|
||||
UTF8Iterator end(begin.iter());
|
||||
end += m_selectionCount;
|
||||
|
@ -297,8 +302,8 @@ void TextField::clipboardCut()
|
|||
rootView().window()->clipboardCopy(boo::EClipboardType::UTF8String,
|
||||
(uint8_t*)&*begin.iter(), end.iter() - begin.iter());
|
||||
|
||||
std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_selectionStart).iter());
|
||||
newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), m_textStr.cend());
|
||||
std::string newStr(textStr.cbegin(), (UTF8Iterator(textStr.cbegin()) + m_selectionStart).iter());
|
||||
newStr.append((UTF8Iterator(textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), textStr.cend());
|
||||
size_t selStart = m_selectionStart;
|
||||
setText(newStr);
|
||||
setCursorPos(selStart);
|
||||
|
@ -334,21 +339,24 @@ void TextField::clipboardPaste()
|
|||
|
||||
if (retData && saniData.size())
|
||||
{
|
||||
std::string_view textStr(m_textStr);
|
||||
if (m_selectionCount)
|
||||
{
|
||||
std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_selectionStart).iter());
|
||||
std::string newStr(textStr.cbegin(), (UTF8Iterator(textStr.cbegin()) + m_selectionStart).iter());
|
||||
newStr.append(saniData);
|
||||
size_t newSel = UTF8Iterator(newStr.cbegin()).countTo(newStr.cend());
|
||||
newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), m_textStr.cend());
|
||||
std::string_view newStrView(newStr);
|
||||
size_t newSel = UTF8Iterator(newStrView.cbegin()).countTo(newStrView.cend());
|
||||
newStr.append((UTF8Iterator(textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), textStr.cend());
|
||||
setText(newStr);
|
||||
setCursorPos(newSel);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_cursorPos).iter());
|
||||
std::string newStr(textStr.cbegin(), (UTF8Iterator(textStr.cbegin()) + m_cursorPos).iter());
|
||||
newStr.append(saniData);
|
||||
size_t newSel = UTF8Iterator(newStr.cbegin()).countTo(newStr.cend());
|
||||
newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_cursorPos).iter(), m_textStr.cend());
|
||||
std::string_view newStrView(newStr);
|
||||
size_t newSel = UTF8Iterator(newStrView.cbegin()).countTo(newStrView.cend());
|
||||
newStr.append((UTF8Iterator(textStr.cbegin()) + m_cursorPos).iter(), textStr.cend());
|
||||
setText(newStr);
|
||||
setCursorPos(newSel);
|
||||
}
|
||||
|
@ -391,7 +399,8 @@ void TextField::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, boo
|
|||
{
|
||||
if ((mods & boo::EModifierKey::Shift) != boo::EModifierKey::None)
|
||||
{
|
||||
size_t len = UTF8Iterator(m_textStr.cbegin()).countTo(m_textStr.cend());
|
||||
std::string_view textStr(m_textStr);
|
||||
size_t len = UTF8Iterator(textStr.cbegin()).countTo(textStr.cend());
|
||||
if (m_cursorPos < len)
|
||||
{
|
||||
size_t origPos = m_cursorPos;
|
||||
|
@ -416,37 +425,39 @@ void TextField::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, boo
|
|||
}
|
||||
else if (key == boo::ESpecialKey::Backspace)
|
||||
{
|
||||
std::string_view textStr(m_textStr);
|
||||
if (m_selectionCount)
|
||||
{
|
||||
std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_selectionStart).iter());
|
||||
newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), m_textStr.cend());
|
||||
std::string newStr(textStr.cbegin(), (UTF8Iterator(textStr.cbegin()) + m_selectionStart).iter());
|
||||
newStr.append((UTF8Iterator(textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), textStr.cend());
|
||||
size_t selStart = m_selectionStart;
|
||||
setText(newStr);
|
||||
setCursorPos(selStart);
|
||||
}
|
||||
else if (m_cursorPos > 0)
|
||||
{
|
||||
std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + (m_cursorPos-1)).iter());
|
||||
newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_cursorPos).iter(), m_textStr.cend());
|
||||
std::string newStr(textStr.cbegin(), (UTF8Iterator(textStr.cbegin()) + (m_cursorPos-1)).iter());
|
||||
newStr.append((UTF8Iterator(textStr.cbegin()) + m_cursorPos).iter(), textStr.cend());
|
||||
setText(newStr);
|
||||
setCursorPos(m_cursorPos-1);
|
||||
}
|
||||
}
|
||||
else if (key == boo::ESpecialKey::Delete)
|
||||
{
|
||||
size_t len = UTF8Iterator(m_textStr.cbegin()).countTo(m_textStr.cend());
|
||||
std::string_view textStr(m_textStr);
|
||||
size_t len = UTF8Iterator(textStr.cbegin()).countTo(textStr.cend());
|
||||
if (m_selectionCount)
|
||||
{
|
||||
std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_selectionStart).iter());
|
||||
newStr.append((UTF8Iterator(m_textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), m_textStr.cend());
|
||||
std::string newStr(textStr.cbegin(), (UTF8Iterator(textStr.cbegin()) + m_selectionStart).iter());
|
||||
newStr.append((UTF8Iterator(textStr.cbegin()) + m_selectionStart + m_selectionCount).iter(), textStr.cend());
|
||||
size_t selStart = m_selectionStart;
|
||||
setText(newStr);
|
||||
setCursorPos(selStart);
|
||||
}
|
||||
else if (m_cursorPos < len)
|
||||
{
|
||||
std::string newStr(m_textStr.cbegin(), (UTF8Iterator(m_textStr.cbegin()) + m_cursorPos).iter());
|
||||
newStr.append((UTF8Iterator(m_textStr.cbegin()) + (m_cursorPos+1)).iter(), m_textStr.cend());
|
||||
std::string newStr(textStr.cbegin(), (UTF8Iterator(textStr.cbegin()) + m_cursorPos).iter());
|
||||
newStr.append((UTF8Iterator(textStr.cbegin()) + (m_cursorPos+1)).iter(), textStr.cend());
|
||||
setText(newStr);
|
||||
setCursorPos(m_cursorPos);
|
||||
}
|
||||
|
@ -463,7 +474,8 @@ std::pair<int,int> TextField::markedRange() const
|
|||
std::unique_lock<std::recursive_mutex> lk(m_textInputLk);
|
||||
if (m_deferredMarkStr.empty())
|
||||
return {-1, 0};
|
||||
return {m_cursorPos, UTF8Iterator(m_deferredMarkStr.cbegin()).countTo(m_deferredMarkStr.cend())};
|
||||
std::string_view deferredMarkStr(m_deferredMarkStr);
|
||||
return {m_cursorPos, UTF8Iterator(deferredMarkStr.cbegin()).countTo(deferredMarkStr.cend())};
|
||||
}
|
||||
std::pair<int,int> TextField::selectedRange() const
|
||||
{
|
||||
|
@ -472,7 +484,7 @@ std::pair<int,int> TextField::selectedRange() const
|
|||
return {-1, 0};
|
||||
return {m_deferredSelectionStart, m_deferredSelectionCount};
|
||||
}
|
||||
void TextField::setMarkedText(const std::string& str,
|
||||
void TextField::setMarkedText(std::string_view str,
|
||||
const std::pair<int,int>& selectedRange,
|
||||
const std::pair<int,int>& replacementRange)
|
||||
{
|
||||
|
@ -499,47 +511,51 @@ std::string TextField::substringForRange(const std::pair<int,int>& range,
|
|||
std::pair<int,int>& actualRange) const
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> lk(m_textInputLk);
|
||||
UTF8Iterator begin(m_deferredTextStr.cbegin());
|
||||
size_t curLen = UTF8Iterator(m_deferredTextStr.cbegin()).countTo(m_deferredTextStr.cend());
|
||||
std::string_view deferredTextStr(m_deferredTextStr);
|
||||
UTF8Iterator begin(deferredTextStr.cbegin());
|
||||
size_t curLen = UTF8Iterator(deferredTextStr.cbegin()).countTo(deferredTextStr.cend());
|
||||
if (range.first >= curLen)
|
||||
return std::string();
|
||||
begin += range.first;
|
||||
size_t endIdx = std::min(size_t(range.first + range.second), curLen);
|
||||
UTF8Iterator end(m_deferredTextStr.cbegin());
|
||||
UTF8Iterator end(deferredTextStr.cbegin());
|
||||
end += endIdx;
|
||||
actualRange.first = range.first;
|
||||
actualRange.second = endIdx;
|
||||
return std::string(begin.iter(), end.iter());
|
||||
}
|
||||
void TextField::insertText(const std::string& str, const std::pair<int,int>& range)
|
||||
void TextField::insertText(std::string_view str, const std::pair<int,int>& range)
|
||||
{
|
||||
std::string saniStr = SanitizeUTF8TextLine(str.data(), str.size());
|
||||
|
||||
std::unique_lock<std::recursive_mutex> lk(m_textInputLk);
|
||||
size_t curLen = UTF8Iterator(m_deferredTextStr.cbegin()).countTo(m_deferredTextStr.cend());
|
||||
std::string_view deferredTextStr(m_deferredTextStr);
|
||||
size_t curLen = UTF8Iterator(deferredTextStr.cbegin()).countTo(deferredTextStr.cend());
|
||||
if (range.first < 0 || range.first >= curLen)
|
||||
{
|
||||
size_t beginPos = m_deferredCursorPos;
|
||||
if (m_selectionCount)
|
||||
beginPos = m_selectionCount;
|
||||
beginPos = std::min(beginPos, curLen);
|
||||
std::string newStr(m_deferredTextStr.cbegin(), (UTF8Iterator(m_deferredTextStr.cbegin())+beginPos).iter());
|
||||
std::string newStr(deferredTextStr.cbegin(), (UTF8Iterator(deferredTextStr.cbegin())+beginPos).iter());
|
||||
newStr += saniStr;
|
||||
size_t newPos = UTF8Iterator(newStr.cbegin()).countTo(newStr.cend());
|
||||
newStr += std::string((UTF8Iterator(m_deferredTextStr.cbegin())+beginPos).iter(), m_deferredTextStr.cend());
|
||||
std::string_view newStrView(newStr);
|
||||
size_t newPos = UTF8Iterator(newStrView.cbegin()).countTo(newStrView.cend());
|
||||
newStr += std::string((UTF8Iterator(deferredTextStr.cbegin())+beginPos).iter(), deferredTextStr.cend());
|
||||
setText(newStr);
|
||||
setCursorPos(newPos);
|
||||
unmarkText();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string newStr(m_deferredTextStr.cbegin(), (UTF8Iterator(m_deferredTextStr.cbegin()) + range.first).iter());
|
||||
std::string newStr(deferredTextStr.cbegin(), (UTF8Iterator(deferredTextStr.cbegin()) + range.first).iter());
|
||||
newStr += saniStr;
|
||||
size_t newSel = UTF8Iterator(newStr.cbegin()).countTo(newStr.cend());
|
||||
std::string_view newStrView(newStr);
|
||||
size_t newSel = UTF8Iterator(newStrView.cbegin()).countTo(newStrView.cend());
|
||||
size_t endIdx = range.first + range.second;
|
||||
if (endIdx >= newSel)
|
||||
endIdx = newSel - 1;
|
||||
newStr.append((UTF8Iterator(m_deferredTextStr.cbegin()) + endIdx).iter(), m_deferredTextStr.cend());
|
||||
newStr.append((UTF8Iterator(deferredTextStr.cbegin()) + endIdx).iter(), deferredTextStr.cend());
|
||||
setText(newStr);
|
||||
setCursorPos(newSel);
|
||||
unmarkText();
|
||||
|
@ -553,8 +569,9 @@ boo::SWindowRect TextField::rectForCharacterRange(const std::pair<int,int>& rang
|
|||
std::pair<int,int>& actualRange) const
|
||||
{
|
||||
std::unique_lock<std::recursive_mutex> lk(m_textInputLk);
|
||||
UTF8Iterator begin(m_textStr.cbegin());
|
||||
size_t curLen = UTF8Iterator(m_textStr.cbegin()).countTo(m_textStr.cend());
|
||||
std::string_view textStr(m_textStr);
|
||||
UTF8Iterator begin(textStr.cbegin());
|
||||
size_t curLen = UTF8Iterator(textStr.cbegin()).countTo(textStr.cend());
|
||||
if (range.first >= curLen)
|
||||
{
|
||||
const std::vector<TextView::RenderGlyph>& glyphs = m_text->accessGlyphs();
|
||||
|
@ -563,7 +580,7 @@ boo::SWindowRect TextField::rectForCharacterRange(const std::pair<int,int>& rang
|
|||
}
|
||||
begin += range.first;
|
||||
size_t endIdx = std::min(size_t(range.first + range.second), curLen);
|
||||
UTF8Iterator end(m_textStr.cbegin());
|
||||
UTF8Iterator end(textStr.cbegin());
|
||||
end += endIdx;
|
||||
actualRange.first = range.first;
|
||||
actualRange.second = endIdx;
|
||||
|
@ -629,7 +646,8 @@ void TextField::setActive(bool active)
|
|||
}
|
||||
else if (!m_selectionCount)
|
||||
{
|
||||
size_t len = UTF8Iterator(m_textStr.cbegin()).countTo(m_textStr.cend());
|
||||
std::string_view textStr(m_textStr);
|
||||
size_t len = UTF8Iterator(textStr.cbegin()).countTo(textStr.cend());
|
||||
setSelectionRange(0, len);
|
||||
}
|
||||
}
|
||||
|
@ -660,7 +678,8 @@ void TextField::_setCursorPos()
|
|||
{
|
||||
m_hasSelectionClear = true;
|
||||
_clearSelectionRange();
|
||||
m_cursorPos = std::min(m_deferredCursorPos, UTF8Iterator(m_textStr.cbegin()).countTo(m_textStr.cend()));
|
||||
std::string_view textStr(m_textStr);
|
||||
m_cursorPos = std::min(m_deferredCursorPos, UTF8Iterator(textStr.cbegin()).countTo(textStr.cend()));
|
||||
m_deferredCursorPos = m_cursorPos;
|
||||
m_cursorFrames = 0;
|
||||
_reallySetCursorPos(m_cursorPos);
|
||||
|
@ -675,7 +694,7 @@ void TextField::setCursorPos(size_t pos)
|
|||
m_hasCursorSet = true;
|
||||
}
|
||||
|
||||
void TextField::setErrorState(const std::string& message)
|
||||
void TextField::setErrorState(std::string_view message)
|
||||
{
|
||||
m_error = true;
|
||||
if (m_selectionCount)
|
||||
|
@ -764,7 +783,8 @@ void TextField::_setSelectionRange()
|
|||
{
|
||||
if (m_hasSelectionSet)
|
||||
{
|
||||
size_t len = UTF8Iterator(m_textStr.cbegin()).countTo(m_textStr.cend());
|
||||
std::string_view textStr(m_textStr);
|
||||
size_t len = UTF8Iterator(textStr.cbegin()).countTo(textStr.cend());
|
||||
m_selectionStart = std::min(m_deferredSelectionStart, len-1);
|
||||
m_deferredSelectionStart = m_selectionStart;
|
||||
m_selectionCount = std::min(m_deferredSelectionCount, len-m_selectionStart);
|
||||
|
|
|
@ -401,7 +401,7 @@ int TextView::DoKern(FT_Pos val, const FontAtlas& atlas)
|
|||
return FT_PIX_ROUND(val) >> 6;
|
||||
}
|
||||
|
||||
void TextView::typesetGlyphs(const std::string& str, const zeus::CColor& defaultColor)
|
||||
void TextView::typesetGlyphs(std::string_view str, const zeus::CColor& defaultColor)
|
||||
{
|
||||
UTF8Iterator it(str.begin());
|
||||
size_t charLen = str.size() ? std::min(it.countTo(str.end()), m_capacity) : 0;
|
||||
|
@ -471,7 +471,7 @@ void TextView::typesetGlyphs(const std::string& str, const zeus::CColor& default
|
|||
updateSize();
|
||||
}
|
||||
|
||||
void TextView::typesetGlyphs(const std::wstring& str, const zeus::CColor& defaultColor)
|
||||
void TextView::typesetGlyphs(std::wstring_view str, const zeus::CColor& defaultColor)
|
||||
{
|
||||
size_t charLen = std::min(str.size(), m_capacity);
|
||||
_commitResources(charLen);
|
||||
|
|
|
@ -8,8 +8,8 @@ namespace specter
|
|||
#define TOOLTIP_MAX_WIDTH 316
|
||||
#define TOOLTIP_MAX_TEXT_WIDTH 300
|
||||
|
||||
Tooltip::Tooltip(ViewResources& res, View& parentView, const std::string& title,
|
||||
const std::string& message)
|
||||
Tooltip::Tooltip(ViewResources& res, View& parentView, std::string_view title,
|
||||
std::string_view message)
|
||||
: View(res, parentView), m_titleStr(title), m_messageStr(message)
|
||||
{
|
||||
for (int i=0 ; i<16 ; ++i)
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace specter
|
|||
{
|
||||
static logvisor::Module Log("specter::Translator");
|
||||
|
||||
Locale::Locale(const std::string& name, const std::string& fullName,
|
||||
Locale::Locale(std::string_view name, std::string_view fullName,
|
||||
const unsigned char* yamlSource, size_t yamlLength)
|
||||
: m_name(name), m_fullName(fullName)
|
||||
{
|
||||
|
@ -15,9 +15,9 @@ Locale::Locale(const std::string& name, const std::string& fullName,
|
|||
m_rootNode = reader.releaseRootNode();
|
||||
if (m_rootNode)
|
||||
{
|
||||
m_langNode = m_rootNode->findMapChild(name.c_str());
|
||||
m_langNode = m_rootNode->findMapChild(name.data());
|
||||
if (!m_langNode)
|
||||
Log.report(logvisor::Fatal, "no root node '%s' found in locale", name.c_str());
|
||||
Log.report(logvisor::Fatal, "no root node '%s' found in locale", name.data());
|
||||
}
|
||||
else
|
||||
Log.report(logvisor::Warning, "locale empty");
|
||||
|
@ -30,27 +30,27 @@ void Translator::setLocale(const Locale* targetLocale)
|
|||
m_targetLocale = targetLocale;
|
||||
}
|
||||
|
||||
static const std::string* RecursiveLookup(const athena::io::YAMLNode* node,
|
||||
std::string::const_iterator start,
|
||||
std::string::const_iterator end)
|
||||
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::const_iterator it = start ; it != end ; ++it)
|
||||
for (std::string_view::const_iterator it = start ; it != end ; ++it)
|
||||
{
|
||||
if (*it == '/')
|
||||
{
|
||||
const athena::io::YAMLNode* ch = node->findMapChild(std::string(start, it).c_str());
|
||||
const athena::io::YAMLNode* ch = node->findMapChild(std::string(start, it));
|
||||
if (!ch)
|
||||
return nullptr;
|
||||
return RecursiveLookup(ch, it+1, end);
|
||||
}
|
||||
}
|
||||
const athena::io::YAMLNode* ch = node->findMapChild(std::string(start, end).c_str());
|
||||
const athena::io::YAMLNode* ch = node->findMapChild(std::string(start, end));
|
||||
if (!ch)
|
||||
return nullptr;
|
||||
return &ch->m_scalarString;
|
||||
return {};
|
||||
return ch->m_scalarString;
|
||||
}
|
||||
|
||||
const std::string* Translator::translate(const std::string& key) const
|
||||
std::string_view Translator::translate(std::string_view key) const
|
||||
{
|
||||
if (!m_targetLocale->rootNode())
|
||||
return nullptr;
|
||||
|
@ -58,11 +58,11 @@ const std::string* Translator::translate(const std::string& key) const
|
|||
return RecursiveLookup(m_targetLocale->rootNode(), key.cbegin(), key.cend());
|
||||
}
|
||||
|
||||
std::string Translator::translateOr(const std::string& key, const char* vor) const
|
||||
std::string_view Translator::translateOr(std::string_view key, std::string_view vor) const
|
||||
{
|
||||
const std::string* find = translate(key);
|
||||
if (find)
|
||||
return *find;
|
||||
std::string_view find = translate(key);
|
||||
if (!find.empty())
|
||||
return find;
|
||||
return vor;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit de6dc8659609cb2de9e37a214d117f7a0b7c88f7
|
||||
Subproject commit db38dd95f782c27417d3aedc3956d97fe9cb50c7
|
Loading…
Reference in New Issue