display: add BaseFont and introduce Font::draw methods (#4963)

This commit is contained in:
Kamil Trzciński
2023-06-19 01:04:19 +02:00
committed by GitHub
parent 5a8e93ed0a
commit 8c9d63f48f
7 changed files with 106 additions and 100 deletions
+6 -3
View File
@@ -1,6 +1,7 @@
#pragma once
#include "esphome/core/datatypes.h"
#include "display_buffer.h"
namespace esphome {
namespace display {
@@ -23,6 +24,8 @@ class Glyph {
bool get_pixel(int x, int y) const;
void draw(int x, int y, DisplayBuffer *display, Color color) const;
const char *get_char() const;
bool compare_to(const char *str) const;
@@ -33,12 +36,11 @@ class Glyph {
protected:
friend Font;
friend DisplayBuffer;
const GlyphData *glyph_data_;
};
class Font {
class Font : public BaseFont {
public:
/** Construct the font with the given glyphs.
*
@@ -50,7 +52,8 @@ class Font {
int match_next_glyph(const char *str, int *match_length);
void measure(const char *str, int *width, int *x_offset, int *baseline, int *height);
void print(int x_start, int y_start, DisplayBuffer *display, Color color, const char *text) override;
void measure(const char *str, int *width, int *x_offset, int *baseline, int *height) override;
inline int get_baseline() { return this->baseline_; }
inline int get_height() { return this->height_; }