libepaper 2.0.0
A C++23 library for controlling Waveshare e-paper displays on Raspberry Pi, featuring transparent sleep/wake management and a fluent builder API.
Loading...
Searching...
No Matches
builders.hpp
Go to the documentation of this file.
1#pragma once
2
65#include <cstdint>
66#include <string>
67#include <string_view>
68
69namespace epaper {
70
114public:
118 LineBuilder() noexcept = default;
119
126 auto from(Point pt) noexcept -> LineBuilder & {
127 from_ = pt;
128 return *this;
129 }
130
138 auto from(std::size_t x, std::size_t y) noexcept -> LineBuilder & {
139 from_ = Point{x, y};
140 return *this;
141 }
142
149 auto to(Point pt) noexcept -> LineBuilder & {
150 to_ = pt;
151 return *this;
152 }
153
161 auto to(std::size_t x, std::size_t y) noexcept -> LineBuilder & {
162 to_ = Point{x, y};
163 return *this;
164 }
165
172 auto color(Color c) noexcept -> LineBuilder & {
173 color_ = c;
174 return *this;
175 }
176
183 auto width(DotPixel w) noexcept -> LineBuilder & {
184 width_ = w;
185 return *this;
186 }
187
194 auto style(LineStyle s) noexcept -> LineBuilder & {
195 style_ = s;
196 return *this;
197 }
198
205 auto with_style(const LineStyleSpec &line_style) noexcept -> LineBuilder & {
206 color_ = line_style.color;
207 width_ = line_style.width;
208 style_ = line_style.style;
209 return *this;
210 }
211
217 [[nodiscard]] auto build() const noexcept -> LineCommand { return LineCommand{from_, to_, color_, width_, style_}; }
218
219private:
220 Point from_{0, 0};
221 Point to_{0, 0};
222 Color color_ = Color::Black;
225};
226
284public:
288 RectangleBuilder() noexcept = default;
289
296 auto top_left(Point pt) noexcept -> RectangleBuilder & {
297 top_left_ = pt;
298 return *this;
299 }
300
308 auto top_left(std::size_t x, std::size_t y) noexcept -> RectangleBuilder & {
309 top_left_ = Point{x, y};
310 return *this;
311 }
312
319 auto bottom_right(Point pt) noexcept -> RectangleBuilder & {
320 bottom_right_ = pt;
321 return *this;
322 }
323
331 auto bottom_right(std::size_t x, std::size_t y) noexcept -> RectangleBuilder & {
332 bottom_right_ = Point{x, y};
333 return *this;
334 }
335
342 auto at(Point pt) noexcept -> RectangleBuilder & {
343 top_left_ = pt;
344 return *this;
345 }
346
354 auto at(std::size_t x, std::size_t y) noexcept -> RectangleBuilder & {
355 top_left_ = Point{x, y};
356 return *this;
357 }
358
368 auto size(Size sz) noexcept -> RectangleBuilder & {
369 bottom_right_ = Point{top_left_.x + sz.width, top_left_.y + sz.height};
370 return *this;
371 }
372
380 auto size(std::size_t w, std::size_t h) noexcept -> RectangleBuilder & {
381 bottom_right_ = Point{top_left_.x + w, top_left_.y + h};
382 return *this;
383 }
384
391 auto color(Color c) noexcept -> RectangleBuilder & {
392 color_ = c;
393 return *this;
394 }
395
402 auto border_width(DotPixel w) noexcept -> RectangleBuilder & {
403 border_width_ = w;
404 return *this;
405 }
406
413 auto fill(DrawFill f) noexcept -> RectangleBuilder & {
414 fill_ = f;
415 return *this;
416 }
417
424 auto with_style(const ShapeStyleSpec &shape_style) noexcept -> RectangleBuilder & {
425 color_ = shape_style.color;
426 border_width_ = shape_style.border_width;
427 fill_ = shape_style.fill;
428 return *this;
429 }
430
436 [[nodiscard]] auto build() const noexcept -> RectangleCommand {
437 return RectangleCommand{top_left_, bottom_right_, color_, border_width_, fill_};
438 }
439
440private:
441 Point top_left_{0, 0};
442 Point bottom_right_{0, 0};
443 Color color_ = Color::Black;
444 DotPixel border_width_ = DotPixel::Pixel1x1;
446};
447
494public:
498 CircleBuilder() noexcept = default;
499
506 auto center(Point pt) noexcept -> CircleBuilder & {
507 center_ = pt;
508 return *this;
509 }
510
518 auto center(std::size_t x, std::size_t y) noexcept -> CircleBuilder & {
519 center_ = Point{x, y};
520 return *this;
521 }
522
529 auto radius(std::size_t r) noexcept -> CircleBuilder & {
530 radius_ = r;
531 return *this;
532 }
533
540 auto color(Color c) noexcept -> CircleBuilder & {
541 color_ = c;
542 return *this;
543 }
544
551 auto border_width(DotPixel w) noexcept -> CircleBuilder & {
552 border_width_ = w;
553 return *this;
554 }
555
562 auto fill(DrawFill f) noexcept -> CircleBuilder & {
563 fill_ = f;
564 return *this;
565 }
566
573 auto with_style(const ShapeStyleSpec &shape_style) noexcept -> CircleBuilder & {
574 color_ = shape_style.color;
575 border_width_ = shape_style.border_width;
576 fill_ = shape_style.fill;
577 return *this;
578 }
579
585 [[nodiscard]] auto build() const noexcept -> CircleCommand {
586 return CircleCommand{center_, radius_, color_, border_width_, fill_};
587 }
588
589private:
590 Point center_{0, 0};
591 std::size_t radius_ = 0;
592 Color color_ = Color::Black;
593 DotPixel border_width_ = DotPixel::Pixel1x1;
595};
596
644public:
648 PointBuilder() noexcept = default;
649
656 auto at(Point pt) noexcept -> PointBuilder & {
657 position_ = pt;
658 return *this;
659 }
660
668 auto at(std::size_t x, std::size_t y) noexcept -> PointBuilder & {
669 position_ = Point{x, y};
670 return *this;
671 }
672
679 auto color(Color c) noexcept -> PointBuilder & {
680 color_ = c;
681 return *this;
682 }
683
690 auto size(DotPixel s) noexcept -> PointBuilder & {
691 pixel_size_ = s;
692 return *this;
693 }
694
700 [[nodiscard]] auto build() const noexcept -> PointCommand { return PointCommand{position_, color_, pixel_size_}; }
701
702private:
703 Point position_{0, 0};
704 Color color_ = Color::Black;
705 DotPixel pixel_size_ = DotPixel::Pixel1x1;
706};
707
780public:
784 TextBuilder() noexcept : content_type_(TextContent::String), number_(0), decimal_(0.0), decimal_places_(0) {}
785
791 explicit TextBuilder(std::string_view txt) noexcept
792 : text_(txt), content_type_(TextContent::String), number_(0), decimal_(0.0), decimal_places_(0) {}
793
800 auto text(std::string_view txt) noexcept -> TextBuilder & {
801 text_ = txt;
802 content_type_ = TextContent::String;
803 return *this;
804 }
805
812 auto number(std::int32_t num) noexcept -> TextBuilder & {
813 number_ = num;
814 content_type_ = TextContent::Number;
815 return *this;
816 }
817
825 auto decimal(double dec, std::uint8_t places) noexcept -> TextBuilder & {
826 decimal_ = dec;
827 decimal_places_ = places;
828 content_type_ = TextContent::Decimal;
829 return *this;
830 }
831
838 auto at(Point pt) noexcept -> TextBuilder & {
839 position_ = pt;
840 return *this;
841 }
842
850 auto at(std::size_t x, std::size_t y) noexcept -> TextBuilder & {
851 position_ = Point{x, y};
852 return *this;
853 }
854
861 auto font(const Font *f) noexcept -> TextBuilder & {
862 font_ = f;
863 return *this;
864 }
865
872 auto foreground(Color c) noexcept -> TextBuilder & {
873 foreground_ = c;
874 return *this;
875 }
876
883 auto background(Color c) noexcept -> TextBuilder & {
884 background_ = c;
885 return *this;
886 }
887
894 auto with_style(const TextStyleSpec &text_style) noexcept -> TextBuilder & {
895 font_ = text_style.font;
896 foreground_ = text_style.foreground;
897 background_ = text_style.background;
898 return *this;
899 }
900
906 [[nodiscard]] auto build() const -> TextCommand {
907 switch (content_type_) {
909 return TextCommand{position_, text_, font_, foreground_, background_};
911 return TextCommand{position_, number_, font_, foreground_, background_};
913 return TextCommand{position_, decimal_, decimal_places_, font_, foreground_, background_};
914 }
915 // Should never reach here, but return string version as fallback
916 return TextCommand{position_, text_, font_, foreground_, background_};
917 }
918
919private:
920 Point position_{0, 0};
921 std::string text_;
922 const Font *font_ = nullptr;
923 Color foreground_ = Color::Black;
924 Color background_ = Color::White;
925 TextContent content_type_;
926 std::int32_t number_;
927 double decimal_;
928 std::uint8_t decimal_places_;
929};
930
931} // namespace epaper
Definition builders.hpp:493
auto center(Point pt) noexcept -> CircleBuilder &
Set the center point of the circle.
Definition builders.hpp:506
auto radius(std::size_t r) noexcept -> CircleBuilder &
Set the circle radius.
Definition builders.hpp:529
auto build() const noexcept -> CircleCommand
Build the final CircleCommand.
Definition builders.hpp:585
CircleBuilder() noexcept=default
Default constructor creates a builder with default values.
auto color(Color c) noexcept -> CircleBuilder &
Set the circle color.
Definition builders.hpp:540
auto border_width(DotPixel w) noexcept -> CircleBuilder &
Set the border width.
Definition builders.hpp:551
auto center(std::size_t x, std::size_t y) noexcept -> CircleBuilder &
Set the center point using coordinates.
Definition builders.hpp:518
auto fill(DrawFill f) noexcept -> CircleBuilder &
Set the fill mode.
Definition builders.hpp:562
auto with_style(const ShapeStyleSpec &shape_style) noexcept -> CircleBuilder &
Apply a reusable shape style.
Definition builders.hpp:573
Definition font.hpp:142
Definition builders.hpp:113
auto width(DotPixel w) noexcept -> LineBuilder &
Set the line width.
Definition builders.hpp:183
auto to(std::size_t x, std::size_t y) noexcept -> LineBuilder &
Set the ending point of the line using coordinates.
Definition builders.hpp:161
auto style(LineStyle s) noexcept -> LineBuilder &
Set the line style.
Definition builders.hpp:194
auto from(std::size_t x, std::size_t y) noexcept -> LineBuilder &
Set the starting point of the line using coordinates.
Definition builders.hpp:138
auto from(Point pt) noexcept -> LineBuilder &
Set the starting point of the line.
Definition builders.hpp:126
auto color(Color c) noexcept -> LineBuilder &
Set the line color.
Definition builders.hpp:172
auto to(Point pt) noexcept -> LineBuilder &
Set the ending point of the line.
Definition builders.hpp:149
auto build() const noexcept -> LineCommand
Build the final LineCommand.
Definition builders.hpp:217
LineBuilder() noexcept=default
Default constructor creates a builder with default values.
auto with_style(const LineStyleSpec &line_style) noexcept -> LineBuilder &
Apply a reusable line style.
Definition builders.hpp:205
Definition builders.hpp:643
auto size(DotPixel s) noexcept -> PointBuilder &
Set the point size.
Definition builders.hpp:690
auto color(Color c) noexcept -> PointBuilder &
Set the point color.
Definition builders.hpp:679
auto at(Point pt) noexcept -> PointBuilder &
Set the position of the point.
Definition builders.hpp:656
auto at(std::size_t x, std::size_t y) noexcept -> PointBuilder &
Set the position using coordinates.
Definition builders.hpp:668
auto build() const noexcept -> PointCommand
Build the final PointCommand.
Definition builders.hpp:700
PointBuilder() noexcept=default
Default constructor creates a builder with default values.
Definition builders.hpp:283
auto at(Point pt) noexcept -> RectangleBuilder &
Set the position (top-left corner) of the rectangle.
Definition builders.hpp:342
auto color(Color c) noexcept -> RectangleBuilder &
Set the rectangle color.
Definition builders.hpp:391
auto size(Size sz) noexcept -> RectangleBuilder &
Set the size of the rectangle.
Definition builders.hpp:368
auto border_width(DotPixel w) noexcept -> RectangleBuilder &
Set the border width.
Definition builders.hpp:402
auto build() const noexcept -> RectangleCommand
Build the final RectangleCommand.
Definition builders.hpp:436
auto top_left(Point pt) noexcept -> RectangleBuilder &
Set the top-left corner of the rectangle.
Definition builders.hpp:296
auto bottom_right(std::size_t x, std::size_t y) noexcept -> RectangleBuilder &
Set the bottom-right corner using coordinates.
Definition builders.hpp:331
auto size(std::size_t w, std::size_t h) noexcept -> RectangleBuilder &
Set the size using width and height.
Definition builders.hpp:380
RectangleBuilder() noexcept=default
Default constructor creates a builder with default values.
auto top_left(std::size_t x, std::size_t y) noexcept -> RectangleBuilder &
Set the top-left corner using coordinates.
Definition builders.hpp:308
auto with_style(const ShapeStyleSpec &shape_style) noexcept -> RectangleBuilder &
Apply a reusable shape style.
Definition builders.hpp:424
auto bottom_right(Point pt) noexcept -> RectangleBuilder &
Set the bottom-right corner of the rectangle.
Definition builders.hpp:319
auto at(std::size_t x, std::size_t y) noexcept -> RectangleBuilder &
Set the position using coordinates.
Definition builders.hpp:354
auto fill(DrawFill f) noexcept -> RectangleBuilder &
Set the fill mode.
Definition builders.hpp:413
Definition builders.hpp:779
auto with_style(const TextStyleSpec &text_style) noexcept -> TextBuilder &
Apply a reusable text style.
Definition builders.hpp:894
auto font(const Font *f) noexcept -> TextBuilder &
Set the font.
Definition builders.hpp:861
auto number(std::int32_t num) noexcept -> TextBuilder &
Set the content to an integer number.
Definition builders.hpp:812
auto background(Color c) noexcept -> TextBuilder &
Set the background color.
Definition builders.hpp:883
auto at(std::size_t x, std::size_t y) noexcept -> TextBuilder &
Set the text position using coordinates.
Definition builders.hpp:850
auto text(std::string_view txt) noexcept -> TextBuilder &
Set the text content.
Definition builders.hpp:800
TextBuilder() noexcept
Default constructor creates a builder with empty text.
Definition builders.hpp:784
auto build() const -> TextCommand
Build the final TextCommand.
Definition builders.hpp:906
auto at(Point pt) noexcept -> TextBuilder &
Set the text position.
Definition builders.hpp:838
TextBuilder(std::string_view txt) noexcept
Construct a text builder with string content.
Definition builders.hpp:791
auto decimal(double dec, std::uint8_t places) noexcept -> TextBuilder &
Set the content to a decimal number.
Definition builders.hpp:825
auto foreground(Color c) noexcept -> TextBuilder &
Set the foreground (text) color.
Definition builders.hpp:872
Immutable command structures for drawing operations.
Bitmap font rendering for e-paper displays.
Definition color.hpp:5
DrawFill
Definition types.hpp:151
@ Empty
Draw outline only (border with no fill)
TextContent
Content type for text rendering.
Definition commands.hpp:240
@ String
Direct string content (text field used as-is)
@ Decimal
Decimal number (decimal field formatted with decimal_places precision)
@ Number
Integer number (number field converted to text via sprintf)
DotPixel
Definition types.hpp:92
@ Pixel1x1
Single pixel (finest resolution)
Color
Definition types.hpp:32
@ White
White (or lightest gray in grayscale modes)
@ Black
Black (or darkest gray in grayscale modes)
LineStyle
Definition types.hpp:120
@ Solid
Continuous solid line.
Command for drawing a circle.
Definition commands.hpp:174
Command for drawing a line between two points.
Definition commands.hpp:84
Definition styles.hpp:68
Command for drawing a point (pixel or multi-pixel dot).
Definition commands.hpp:218
Definition geometry.hpp:37
std::size_t y
Y coordinate (vertical position)
Definition geometry.hpp:39
std::size_t x
X coordinate (horizontal position)
Definition geometry.hpp:38
Command for drawing a rectangle.
Definition commands.hpp:129
Definition styles.hpp:96
Definition geometry.hpp:105
Command for drawing text.
Definition commands.hpp:281
Definition styles.hpp:124
Reusable style specifications for drawing commands.