Add string view overloads (#1154)
Some checks failed
Build / Bazel, cl, windows-latest (push) Has been cancelled
Build / Bazel, clang++, macos-latest (push) Has been cancelled
Build / Bazel, clang++, ubuntu-latest (push) Has been cancelled
Build / Bazel, g++, macos-latest (push) Has been cancelled
Build / Bazel, g++, ubuntu-latest (push) Has been cancelled
Build / CMake, cl, windows-latest (push) Has been cancelled
Build / CMake, gcc, ubuntu-latest (push) Has been cancelled
Build / CMake, llvm, ubuntu-latest (push) Has been cancelled
Build / CMake, llvm, macos-latest (push) Has been cancelled
Build / Test modules (llvm, ubuntu-latest) (push) Has been cancelled
Documentation / documentation (push) Has been cancelled

This is better ergonomic, as `std::string_view` is lightweight and accept more conversion than `const std::string&`.

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Miko
2025-12-13 11:22:11 -08:00
committed by GitHub
parent 117417e841
commit 9f4b2bcf96
29 changed files with 275 additions and 151 deletions

View File

@@ -106,9 +106,9 @@ struct Canvas {
// Draw using character of size 2x4 at position (x,y)
// x is considered to be a multiple of 2.
// y is considered to be a multiple of 4.
void DrawText(int x, int y, const std::string& value);
void DrawText(int x, int y, const std::string& value, const Color& color);
void DrawText(int x, int y, const std::string& value, const Stylizer& style);
void DrawText(int x, int y, std::string_view value);
void DrawText(int x, int y, std::string_view value, const Color& color);
void DrawText(int x, int y, std::string_view value, const Stylizer& style);
// Draw using directly pixels or images --------------------------------------
// x is considered to be a multiple of 2.

View File

@@ -7,6 +7,7 @@
#include <functional>
#include <memory>
#include <string_view>
#include "ftxui/dom/canvas.hpp"
#include "ftxui/dom/direction.hpp"
#include "ftxui/dom/flexbox_config.hpp"
@@ -51,8 +52,8 @@ Elements operator|(Elements, Decorator);
Decorator operator|(Decorator, Decorator);
// --- Widget ---
Element text(std::string text);
Element vtext(std::string text);
Element text(std::string_view text);
Element vtext(std::string_view text);
Element separator();
Element separatorLight();
Element separatorDashed();
@@ -61,7 +62,7 @@ Element separatorDouble();
Element separatorEmpty();
Element separatorStyled(BorderStyle);
Element separator(Pixel);
Element separatorCharacter(std::string);
Element separatorCharacter(std::string_view);
Element separatorHSelector(float left,
float right,
Color unselected_color,
@@ -89,11 +90,11 @@ Decorator borderStyled(Color);
Decorator borderWith(const Pixel&);
Element window(Element title, Element content, BorderStyle border = ROUNDED);
Element spinner(int charset_index, size_t image_index);
Element paragraph(const std::string& text);
Element paragraphAlignLeft(const std::string& text);
Element paragraphAlignRight(const std::string& text);
Element paragraphAlignCenter(const std::string& text);
Element paragraphAlignJustify(const std::string& text);
Element paragraph(std::string_view text);
Element paragraphAlignLeft(std::string_view text);
Element paragraphAlignRight(std::string_view text);
Element paragraphAlignCenter(std::string_view text);
Element paragraphAlignJustify(std::string_view text);
Element graph(GraphFunction);
Element emptyElement();
Element canvas(ConstRef<Canvas>);
@@ -120,8 +121,8 @@ Element bgcolor(const LinearGradient&, Element);
Decorator focusPosition(int x, int y);
Decorator focusPositionRelative(float x, float y);
Element automerge(Element child);
Decorator hyperlink(std::string link);
Element hyperlink(std::string link, Element child);
Decorator hyperlink(std::string_view link);
Element hyperlink(std::string_view link, Element child);
Element selectionStyleReset(Element);
Decorator selectionColor(Color foreground);
Decorator selectionBackgroundColor(Color foreground);

View File

@@ -30,7 +30,7 @@ class Selection {
Selection SaturateVertical(Box box);
bool IsEmpty() const { return empty_; }
void AddPart(const std::string& part, int y, int left, int right);
void AddPart(std::string_view part, int y, int left, int right);
std::string GetParts() { return parts_.str(); }
private: