Display Common Graphics Primitives
This module wraps libDaisy's common display graphics primitives and abstractions. It provides the base interfaces and types used by all display drivers.
Features:
- Rectangle - Geometric rectangle with rich manipulation API
- Alignment - Text and graphics alignment options
- OneBitGraphicsDisplay - Base interface for monochrome displays
Wrapped Headers:
- hid/disp/graphics_common.h - Rectangle and Alignment
- hid/disp/display.h - OneBitGraphicsDisplay interface
Example - Using Rectangle:
import nimphea/hid/disp/graphics_common var rect = initRectangle(10, 20, 100, 50) # x=10, y=20, w=100, h=50 echo rect.getCenterX() # 60 echo rect.getCenterY() # 45 # Fluent API for transformations var centered = rect.withCenter(64, 32) var reduced = rect.reduced(5) # Shrink by 5px on all sides
Example - Alignment enum:
import nimphea/hid/disp/graphics_common var align = Alignment.topLeft # Use for text rendering, UI layouts, etc.Alignment/Justification options for text and graphicsGeometric rectangle with rich manipulation API
Types
Alignment {.importcpp: "daisy::Alignment", size: 4.} = enum centered, ## Top-left corner topLeft, ## Top edge, centered horizontally topCentered, ## Top-right corner topRight, ## Bottom-left corner bottomLeft, ## Bottom edge, centered horizontally bottomCentered, ## Bottom-right corner bottomRight, ## Left edge, centered vertically centeredLeft, ## Right edge, centered vertically centeredRight
- Centered in both X and Y Source Edit
FontDef {.importcpp: "FontDef", header: "util/oled_fonts.h".} = object fontData*: ptr uint8 fontWidth*: uint8 fontHeight*: uint8
- Font definition structure Source Edit
OneBitGraphicsDisplay {.importcpp: "daisy::OneBitGraphicsDisplay".} = object
- Base interface for 1-bit-per-pixel graphics displays (monochrome). All monochrome OLED drivers inherit from this. Source Edit
Procs
proc currentX(this: var OneBitGraphicsDisplay): csize_t {. importcpp: "#.CurrentX()", ...raises: [], tags: [], forbids: [].}
- Get current cursor X position Source Edit
proc currentY(this: var OneBitGraphicsDisplay): csize_t {. importcpp: "#.CurrentY()", ...raises: [], tags: [], forbids: [].}
- Get current cursor Y position Source Edit
proc drawArc(this: var OneBitGraphicsDisplay; x, y, radius: uint8; startAngle, sweep: int16; on: bool) {. importcpp: "#.DrawArc(#, #, #, #, #, #)", ...raises: [], tags: [], forbids: [].}
- Draw arc centered at (x, y) from startAngle through sweep degrees Source Edit
proc drawCircle(this: var OneBitGraphicsDisplay; x, y, r: uint8; on: bool) {. importcpp: "#.DrawCircle(#, #, #, #)", ...raises: [], tags: [], forbids: [].}
- Draw circle centered at (x, y) with radius r Source Edit
proc drawLine(this: var OneBitGraphicsDisplay; x1, y1, x2, y2: uint8; on: bool) {. importcpp: "#.DrawLine(#, #, #, #, #)", ...raises: [], tags: [], forbids: [].}
- Draw line from (x1, y1) to (x2, y2) Source Edit
proc drawPixel(this: var OneBitGraphicsDisplay; x, y: uint8; on: bool) {. importcpp: "#.DrawPixel(#, #, #)", ...raises: [], tags: [], forbids: [].}
- Draw single pixel at (x, y) Source Edit
proc drawRect(this: var OneBitGraphicsDisplay; x1, y1, x2, y2: uint8; on: bool; fill = false) {.importcpp: "#.DrawRect(#, #, #, #, #, #)", ...raises: [], tags: [], forbids: [].}
- Draw rectangle from (x1, y1) to (x2, y2), optionally filled Source Edit
proc fill(this: var OneBitGraphicsDisplay; on: bool) {.importcpp: "#.Fill(#)", ...raises: [], tags: [], forbids: [].}
- Fill entire display with on (true) or off (false) Source Edit
proc getBounds(this: OneBitGraphicsDisplay): Rectangle {. importcpp: "#.GetBounds()", ...raises: [], tags: [], forbids: [].}
- Get display bounds as Rectangle Source Edit
proc getCenterX(this: Rectangle): int16 {.importcpp: "#.GetCenterX()", ...raises: [], tags: [], forbids: [].}
- Get center X coordinate Source Edit
proc getCenterY(this: Rectangle): int16 {.importcpp: "#.GetCenterY()", ...raises: [], tags: [], forbids: [].}
- Get center Y coordinate Source Edit
proc height(this: OneBitGraphicsDisplay): uint16 {.importcpp: "#.Height()", ...raises: [], tags: [], forbids: [].}
- Get display height in pixels Source Edit
proc initRectangle(): Rectangle {.importcpp: "daisy::Rectangle()", ...raises: [], tags: [], forbids: [].}
- Create empty rectangle at (0, 0) with size (0, 0) Source Edit
proc initRectangle(width, height: int16): Rectangle {. importcpp: "daisy::Rectangle(@)", ...raises: [], tags: [], forbids: [].}
- Create rectangle at (0, 0) with given size Source Edit
proc initRectangle(x, y, width, height: int16): Rectangle {. importcpp: "daisy::Rectangle(@)", ...raises: [], tags: [], forbids: [].}
- Create rectangle at (x, y) with given size Source Edit
proc removeFromBottom(this: var Rectangle; pxToRemove: int16): Rectangle {. importcpp: "#.RemoveFromBottom(#)", ...raises: [], tags: [], forbids: [].}
- Remove pixels from bottom side, return removed Rectangle Source Edit
proc removeFromLeft(this: var Rectangle; pxToRemove: int16): Rectangle {. importcpp: "#.RemoveFromLeft(#)", ...raises: [], tags: [], forbids: [].}
- Remove pixels from left side, return removed Rectangle Source Edit
proc removeFromRight(this: var Rectangle; pxToRemove: int16): Rectangle {. importcpp: "#.RemoveFromRight(#)", ...raises: [], tags: [], forbids: [].}
- Remove pixels from right side, return removed Rectangle Source Edit
proc removeFromTop(this: var Rectangle; pxToRemove: int16): Rectangle {. importcpp: "#.RemoveFromTop(#)", ...raises: [], tags: [], forbids: [].}
- Remove pixels from top side, return removed Rectangle Source Edit
proc setCursor(this: var OneBitGraphicsDisplay; x, y: uint8) {. importcpp: "#.SetCursor(#, #)", ...raises: [], tags: [], forbids: [].}
- Set text cursor position Source Edit
proc translated(this: Rectangle; x, y: int16): Rectangle {. importcpp: "#.Translated(#, #)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle moved by given offset Source Edit
proc update(this: var OneBitGraphicsDisplay) {.importcpp: "#.Update()", ...raises: [], tags: [], forbids: [].}
- Update display (flush framebuffer to hardware) Source Edit
proc width(this: OneBitGraphicsDisplay): uint16 {.importcpp: "#.Width()", ...raises: [], tags: [], forbids: [].}
- Get display width in pixels Source Edit
proc withBottom(this: Rectangle; bottom: int16): Rectangle {. importcpp: "#.WithBottom(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with different bottom edge Source Edit
proc withCenter(this: Rectangle; centerX, centerY: int16): Rectangle {. importcpp: "#.WithCenter(#, #)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle centered at given point Source Edit
proc withCenterX(this: Rectangle; centerX: int16): Rectangle {. importcpp: "#.WithCenterX(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with different center X Source Edit
proc withCenterY(this: Rectangle; centerY: int16): Rectangle {. importcpp: "#.WithCenterY(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with different center Y Source Edit
proc withHeight(this: Rectangle; height: int16): Rectangle {. importcpp: "#.WithHeight(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with different height Source Edit
proc withHeightKeepingCenter(this: Rectangle; height: int16): Rectangle {. importcpp: "#.WithHeightKeepingCenter(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with different height, keeping center position Source Edit
proc withSizeKeepingCenter(this: Rectangle; width, height: int16): Rectangle {. importcpp: "#.WithSizeKeepingCenter(#, #)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with different size, keeping center position Source Edit
proc withTrimmedBottom(this: Rectangle; pxToTrim: int16): Rectangle {. importcpp: "#.WithTrimmedBottom(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with bottom edge moved upward Source Edit
proc withTrimmedLeft(this: Rectangle; pxToTrim: int16): Rectangle {. importcpp: "#.WithTrimmedLeft(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with left edge moved inward Source Edit
proc withTrimmedRight(this: Rectangle; pxToTrim: int16): Rectangle {. importcpp: "#.WithTrimmedRight(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with right edge moved inward Source Edit
proc withTrimmedTop(this: Rectangle; pxToTrim: int16): Rectangle {. importcpp: "#.WithTrimmedTop(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with top edge moved downward Source Edit
proc withWidthKeepingCenter(this: Rectangle; width: int16): Rectangle {. importcpp: "#.WithWidthKeepingCenter(#)", ...raises: [], tags: [], forbids: [].}
- Return new rectangle with different width, keeping center position Source Edit
proc writeChar(this: var OneBitGraphicsDisplay; ch: char; font: Font; on: bool): uint16 {. importcpp: "#.WriteChar(#, #, #)", ...raises: [], tags: [], forbids: [].}
- Write single character at cursor position, advance cursor Source Edit
proc writeString(this: var OneBitGraphicsDisplay; str: cstring; font: Font; on: bool): uint16 {.importcpp: "#.WriteString(#, #, #)", ...raises: [], tags: [], forbids: [].}
- Write string at cursor position, advance cursor Source Edit
proc writeStringAligned(this: var OneBitGraphicsDisplay; str: cstring; font: Font; bounds: Rectangle; alignment: Alignment; on: bool): uint16 {. importcpp: "#.WriteStringAligned(#, #, #, #, #)", ...raises: [], tags: [], forbids: [].}
- Write string aligned within bounds rectangle Source Edit