experimental/editor: cleanup
Remove unneeded setText(). Change default font. EditorApplication constructor does no real work. Change-Id: Ie257fbc9873d99ccb3972842493d65a12b0e7904 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231479 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Ben Wagner <bungeman@google.com> Auto-Submit: Hal Canary <halcanary@google.com>
This commit is contained in:
parent
94d054b53c
commit
ebfcf0c073
@ -167,20 +167,9 @@ static const StringSlice remove_newline(const char* str, size_t len) {
|
||||
StringSlice(str, (len > 0 && str[len - 1] == '\n') ? len - 1 : len);
|
||||
}
|
||||
|
||||
void Editor::setText(const char* data, size_t length) {
|
||||
std::vector<Editor::TextLine> lines;
|
||||
if (data && length && valid_utf8(data, length)) {
|
||||
readlines(data, length, [&lines](const char* p, size_t s) {
|
||||
lines.push_back(remove_newline(p, s));
|
||||
});
|
||||
}
|
||||
fLines = std::move(lines);
|
||||
this->markAllDirty();
|
||||
}
|
||||
|
||||
void Editor::setFont(SkFont font) {
|
||||
if (font != fFont) {
|
||||
fFont = font;
|
||||
fFont = std::move(font);
|
||||
auto shaper = SkShaper::Make();
|
||||
const char kSpace[] = " ";
|
||||
TextLine textLine(StringSlice(kSpace, strlen(kSpace)));
|
||||
|
@ -24,8 +24,6 @@ namespace editor {
|
||||
class Editor {
|
||||
struct TextLine;
|
||||
public:
|
||||
// used to load a new file.
|
||||
void setText(const char* text, size_t len);
|
||||
// total height in canvas display units.
|
||||
int getHeight() const { return fHeight; }
|
||||
// spacing around the text, in canvas display units.
|
||||
|
@ -88,14 +88,11 @@ struct EditorLayer : public sk_app::Window::Layer {
|
||||
bool fShiftDown = false;
|
||||
bool fBlink = false;
|
||||
|
||||
EditorLayer() {
|
||||
fEditor.setFont(SkFont(SkTypeface::MakeFromName("monospace", SkFontStyle()), 18));
|
||||
}
|
||||
|
||||
void loadFile(const char* path) {
|
||||
if (sk_sp<SkData> data = SkData::MakeFromFileName(path)) {
|
||||
fPath = path;
|
||||
fEditor.setText((const char*)data->data(), data->size());
|
||||
fEditor.insert(editor::Editor::TextPosition{0, 0},
|
||||
(const char*)data->data(), data->size());
|
||||
} else {
|
||||
fPath = "output.txt";
|
||||
}
|
||||
@ -108,6 +105,7 @@ struct EditorLayer : public sk_app::Window::Layer {
|
||||
canvas->translate(0, -(float)fPos);
|
||||
editor::Editor::PaintOpts options;
|
||||
options.fCursor = fTextPos;
|
||||
options.fCursorColor = {1, 0, 0, fBlink ? 0.0f : 1.0f};
|
||||
options.fBackgroundColor = SkColor4f{0.8f, 0.8f, 0.8f, 1};
|
||||
options.fCursorColor = {1, 0, 0, fBlink ? 0.0f : 1.0f};
|
||||
if (fMarkPos != editor::Editor::TextPosition()) {
|
||||
@ -313,27 +311,37 @@ struct EditorLayer : public sk_app::Window::Layer {
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr float kFontSize = 18;
|
||||
// static constexpr char kTypefaceName[] = "monospace";
|
||||
static constexpr char kTypefaceName[] = "sans-serif";
|
||||
static constexpr SkFontStyle::Weight kFontWeight = SkFontStyle::kNormal_Weight;
|
||||
static constexpr SkFontStyle::Width kFontWidth = SkFontStyle::kNormal_Width;
|
||||
static constexpr SkFontStyle::Slant kFontSlant = SkFontStyle::kUpright_Slant;
|
||||
|
||||
//static constexpr sk_app::Window::BackendType kBackendType = sk_app::Window::kRaster_BackendType;
|
||||
static constexpr sk_app::Window::BackendType kBackendType = sk_app::Window::kNativeGL_BackendType;
|
||||
|
||||
struct EditorApplication : public sk_app::Application {
|
||||
std::unique_ptr<sk_app::Window> fWindow;
|
||||
EditorLayer fLayer;
|
||||
double fNextTime = -DBL_MAX;
|
||||
|
||||
EditorApplication(const char* path, void* platformData)
|
||||
: fWindow(sk_app::Window::CreateNativeWindow(platformData))
|
||||
{
|
||||
//sk_app::Window::BackendType backendType = sk_app::Window::kRaster_BackendType;
|
||||
sk_app::Window::BackendType backendType = sk_app::Window::kNativeGL_BackendType;
|
||||
fWindow->attach(backendType);
|
||||
EditorApplication(void* platformData)
|
||||
: fWindow(sk_app::Window::CreateNativeWindow(platformData)) {}
|
||||
|
||||
bool init(const char* path) {
|
||||
fWindow->attach(kBackendType);
|
||||
fLayer.inval();
|
||||
|
||||
fLayer.fEditor.setFont(SkFont(SkTypeface::MakeFromName(kTypefaceName,
|
||||
SkFontStyle(kFontWeight, kFontWidth, kFontSlant)), kFontSize));
|
||||
fLayer.loadFile(path);
|
||||
|
||||
fWindow->pushLayer(&fLayer);
|
||||
fWindow->setTitle(SkStringPrintf("Editor: \"%s\"", fLayer.fPath.c_str()).c_str());
|
||||
fWindow->show();
|
||||
fLayer.onResize(fWindow->width(), fWindow->height());
|
||||
#ifdef SK_EDITOR_DEBUG_OUT
|
||||
Timer timer("shaping");
|
||||
#endif // SK_EDITOR_DEBUG_OUT
|
||||
fLayer.fEditor.paint(nullptr, editor::Editor::PaintOpts());
|
||||
return true;
|
||||
}
|
||||
~EditorApplication() override { fWindow->detach(); }
|
||||
|
||||
@ -353,5 +361,7 @@ sk_app::Application* sk_app::Application::Create(int argc, char** argv, void* da
|
||||
if (!SkLoadICU()) {
|
||||
SK_ABORT("SkLoadICU failed.");
|
||||
}
|
||||
return new EditorApplication(argc > 1 ? argv[1] : nullptr, dat);
|
||||
EditorApplication* app = new EditorApplication(dat);
|
||||
SkASSERT(app->init(argc > 1 ? argv[1] : nullptr));
|
||||
return app;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user