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
/mnt/nas/libepaper/include/epaper/draw/builders.hpp

Fluent builder for constructing LineCommand.

Fluent builder for constructing LineCommand.Provides a fluent interface for specifying line drawing parameters. Call build() to produce a LineCommand that can be passed to Display::draw().

Method Overloads:

Defaults:

// Minimal usage (uses defaults)
auto cmd1 = LineBuilder().from({10, 10}).to({100, 100}).build();
// Full specification
auto cmd2 = LineBuilder()
.from({10, 10})
.to({100, 100})
.color(Color::Black)
.width(DotPixel::Pixel2x2)
.style(LineStyle::Dotted)
.build();
display.draw(cmd2);
// Using coordinate pairs instead of Point
auto cmd3 = LineBuilder().from(0, 0).to(100, 100).build();
// Applying reusable style
LineStyleSpec dashed_red{Color::Red, DotPixel::Pixel1x1, LineStyle::Dotted};
auto cmd4 = LineBuilder().from(a).to(b).with_style(dashed_red).build();
See also
LineCommand, LineStyleSpec, Display::draw()
#pragma once
#include <cstdint>
#include <string>
#include <string_view>
namespace epaper {
class LineBuilder {
public:
LineBuilder() noexcept = default;
auto from(Point pt) noexcept -> LineBuilder & {
from_ = pt;
return *this;
}
auto from(std::size_t x, std::size_t y) noexcept -> LineBuilder & {
from_ = Point{x, y};
return *this;
}
auto to(Point pt) noexcept -> LineBuilder & {
to_ = pt;
return *this;
}
auto to(std::size_t x, std::size_t y) noexcept -> LineBuilder & {
to_ = Point{x, y};
return *this;
}
auto color(Color c) noexcept -> LineBuilder & {
color_ = c;
return *this;
}
auto width(DotPixel w) noexcept -> LineBuilder & {
width_ = w;
return *this;
}
auto style(LineStyle s) noexcept -> LineBuilder & {
style_ = s;
return *this;
}
auto with_style(const LineStyleSpec &line_style) noexcept -> LineBuilder & {
color_ = line_style.color;
width_ = line_style.width;
style_ = line_style.style;
return *this;
}
[[nodiscard]] auto build() const noexcept -> LineCommand { return LineCommand{from_, to_, color_, width_, style_}; }
private:
Point from_{0, 0};
Point to_{0, 0};
Color color_ = Color::Black;
};
class RectangleBuilder {
public:
RectangleBuilder() noexcept = default;
auto top_left(Point pt) noexcept -> RectangleBuilder & {
top_left_ = pt;
return *this;
}
auto top_left(std::size_t x, std::size_t y) noexcept -> RectangleBuilder & {
top_left_ = Point{x, y};
return *this;
}
auto bottom_right(Point pt) noexcept -> RectangleBuilder & {
bottom_right_ = pt;
return *this;
}
auto bottom_right(std::size_t x, std::size_t y) noexcept -> RectangleBuilder & {
bottom_right_ = Point{x, y};
return *this;
}
auto at(Point pt) noexcept -> RectangleBuilder & {
top_left_ = pt;
return *this;
}
auto at(std::size_t x, std::size_t y) noexcept -> RectangleBuilder & {
top_left_ = Point{x, y};
return *this;
}
auto size(Size sz) noexcept -> RectangleBuilder & {
bottom_right_ = Point{top_left_.x + sz.width, top_left_.y + sz.height};
return *this;
}
auto size(std::size_t w, std::size_t h) noexcept -> RectangleBuilder & {
bottom_right_ = Point{top_left_.x + w, top_left_.y + h};
return *this;
}
auto color(Color c) noexcept -> RectangleBuilder & {
color_ = c;
return *this;
}
auto border_width(DotPixel w) noexcept -> RectangleBuilder & {
border_width_ = w;
return *this;
}
auto fill(DrawFill f) noexcept -> RectangleBuilder & {
fill_ = f;
return *this;
}
auto with_style(const ShapeStyleSpec &shape_style) noexcept -> RectangleBuilder & {
color_ = shape_style.color;
border_width_ = shape_style.border_width;
fill_ = shape_style.fill;
return *this;
}
[[nodiscard]] auto build() const noexcept -> RectangleCommand {
return RectangleCommand{top_left_, bottom_right_, color_, border_width_, fill_};
}
private:
Point top_left_{0, 0};
Point bottom_right_{0, 0};
Color color_ = Color::Black;
DotPixel border_width_ = DotPixel::Pixel1x1;
};
class CircleBuilder {
public:
CircleBuilder() noexcept = default;
auto center(Point pt) noexcept -> CircleBuilder & {
center_ = pt;
return *this;
}
auto center(std::size_t x, std::size_t y) noexcept -> CircleBuilder & {
center_ = Point{x, y};
return *this;
}
auto radius(std::size_t r) noexcept -> CircleBuilder & {
radius_ = r;
return *this;
}
auto color(Color c) noexcept -> CircleBuilder & {
color_ = c;
return *this;
}
auto border_width(DotPixel w) noexcept -> CircleBuilder & {
border_width_ = w;
return *this;
}
auto fill(DrawFill f) noexcept -> CircleBuilder & {
fill_ = f;
return *this;
}
auto with_style(const ShapeStyleSpec &shape_style) noexcept -> CircleBuilder & {
color_ = shape_style.color;
border_width_ = shape_style.border_width;
fill_ = shape_style.fill;
return *this;
}
[[nodiscard]] auto build() const noexcept -> CircleCommand {
return CircleCommand{center_, radius_, color_, border_width_, fill_};
}
private:
Point center_{0, 0};
std::size_t radius_ = 0;
Color color_ = Color::Black;
DotPixel border_width_ = DotPixel::Pixel1x1;
};
class PointBuilder {
public:
PointBuilder() noexcept = default;
auto at(Point pt) noexcept -> PointBuilder & {
position_ = pt;
return *this;
}
auto at(std::size_t x, std::size_t y) noexcept -> PointBuilder & {
position_ = Point{x, y};
return *this;
}
auto color(Color c) noexcept -> PointBuilder & {
color_ = c;
return *this;
}
auto size(DotPixel s) noexcept -> PointBuilder & {
pixel_size_ = s;
return *this;
}
[[nodiscard]] auto build() const noexcept -> PointCommand { return PointCommand{position_, color_, pixel_size_}; }
private:
Point position_{0, 0};
Color color_ = Color::Black;
};
class TextBuilder {
public:
TextBuilder() noexcept : content_type_(TextContent::String), number_(0), decimal_(0.0), decimal_places_(0) {}
explicit TextBuilder(std::string_view txt) noexcept
: text_(txt), content_type_(TextContent::String), number_(0), decimal_(0.0), decimal_places_(0) {}
auto text(std::string_view txt) noexcept -> TextBuilder & {
text_ = txt;
content_type_ = TextContent::String;
return *this;
}
auto number(std::int32_t num) noexcept -> TextBuilder & {
number_ = num;
content_type_ = TextContent::Number;
return *this;
}
auto decimal(double dec, std::uint8_t places) noexcept -> TextBuilder & {
decimal_ = dec;
decimal_places_ = places;
content_type_ = TextContent::Decimal;
return *this;
}
auto at(Point pt) noexcept -> TextBuilder & {
position_ = pt;
return *this;
}
auto at(std::size_t x, std::size_t y) noexcept -> TextBuilder & {
position_ = Point{x, y};
return *this;
}
auto font(const Font *f) noexcept -> TextBuilder & {
font_ = f;
return *this;
}
auto foreground(Color c) noexcept -> TextBuilder & {
foreground_ = c;
return *this;
}
auto background(Color c) noexcept -> TextBuilder & {
background_ = c;
return *this;
}
auto with_style(const TextStyleSpec &text_style) noexcept -> TextBuilder & {
font_ = text_style.font;
foreground_ = text_style.foreground;
background_ = text_style.background;
return *this;
}
[[nodiscard]] auto build() const -> TextCommand {
switch (content_type_) {
return TextCommand{position_, text_, font_, foreground_, background_};
return TextCommand{position_, number_, font_, foreground_, background_};
return TextCommand{position_, decimal_, decimal_places_, font_, foreground_, background_};
}
// Should never reach here, but return string version as fallback
return TextCommand{position_, text_, font_, foreground_, background_};
}
private:
Point position_{0, 0};
std::string text_;
const Font *font_ = nullptr;
Color foreground_ = Color::Black;
Color background_ = Color::White;
TextContent content_type_;
std::int32_t number_;
double decimal_;
std::uint8_t decimal_places_;
};
} // namespace epaper
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 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
auto width(DotPixel w) noexcept -> LineBuilder &
Set the line width.
Definition builders.hpp:183
auto style(LineStyle s) noexcept -> LineBuilder &
Set the line style.
Definition builders.hpp:194
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
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 build() const noexcept -> PointCommand
Build the final PointCommand.
Definition builders.hpp:700
PointBuilder() noexcept=default
Default constructor creates a builder with default values.
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
RectangleBuilder() noexcept=default
Default constructor creates a builder with default values.
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 fill(DrawFill f) noexcept -> RectangleBuilder &
Set the fill mode.
Definition builders.hpp:413
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 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
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.
std::size_t y
Y coordinate (vertical position)
Definition geometry.hpp:39
std::size_t x
X coordinate (horizontal position)
Definition geometry.hpp:38
Reusable style specifications for drawing commands.