| // Copyright 2024 The Pigweed Authors |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| // use this file except in compliance with the License. You may obtain a copy of |
| // the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| // License for the specific language governing permissions and limitations under |
| // the License. |
| #pragma once |
| |
| #include "pw_color/color.h" |
| #include "pw_draw/font_set.h" |
| #include "pw_framebuffer/framebuffer.h" |
| |
| namespace pw::draw { |
| |
| /// @ingroup pw_draw |
| /// |
| /// Class for drawing text to an area of a Framebuffer. Handles newlines and |
| /// wrapping to the next line on each character. |
| class TextArea { |
| public: |
| /// Initialize a TextArea with a Framebuffer and FontSet. |
| TextArea(pw::framebuffer::Framebuffer& fb, const FontSet& font); |
| |
| /// Enable or disable character wrapping. |
| void SetCharacterWrap(bool new_setting); |
| /// Set the cursor to position (x, y) then draw a single character. |
| void SetCursor(int x, int y); |
| /// Shift all lines in the text area up by a given character line count. |
| void ScrollUp(int lines); |
| |
| /// Draw a single character at the current cursor position. |
| void DrawCharacter(int character); |
| /// Set the cursor to position (x, y) then draw a single character. |
| void DrawCharacter(int character, int x, int y); |
| |
| /// Set the text foreground color. |
| void SetForegroundColor(pw::color::color_rgb565_t color); |
| /// Set the text background color. |
| void SetBackgroundColor(pw::color::color_rgb565_t color); |
| |
| /// Draw all characters in the current FontSet at position (x, y). |
| void DrawTestFontSheet(int character_column_width, int x, int y); |
| |
| /// Draw a string at the current cursor position. |
| void DrawText(const char* str); |
| /// Set the cursor to position (x, y) then draw a string. |
| void DrawText(const char* str, int x, int y); |
| /// Draw a string at the current cursor position. |
| void DrawText(const wchar_t* str); |
| /// Set the cursor to position (x, y) then draw a string. |
| void DrawText(const wchar_t* str, int x, int y); |
| |
| /// Move the cursor forward one character (to the right). |
| void MoveCursorRightOnce(); |
| /// Move the cursor down to the beginning of the next line. |
| void InsertLineBreak(); |
| |
| private: |
| int cursor_x_; |
| int cursor_y_; |
| int column_count_; |
| bool character_wrap_enabled_; |
| const FontSet& font_; |
| pw::color::color_rgb565_t foreground_color_; |
| pw::color::color_rgb565_t background_color_; |
| pw::framebuffer::Framebuffer& framebuffer_; |
| }; |
| |
| } // namespace pw::draw |