Module graphics

Source
Expand description

Graphic Device Operations

§Control an existing graphic device

TODO

§Implement a new graphic device

The following two things are needed to implement a graphic device.

  • DeviceDriver trait: the actual implementation of graphic device methods.
  • DeviceDescriptor struct: the parameters that might differ per device instance (e.g. sizes, and colors).

For example, the following code implements a simple graphic device that shows a message when it’s activated (and ignores everything else).

use extendr_api::{
    graphics::{DeviceDescriptor, DeviceDriver, DevDesc},
    prelude::*,
};

struct MyDevice<'a> {
    welcome_message: &'a str,
}

impl<'a> DeviceDriver for MyDevice<'a> {
    fn activate(&mut self, _dd: DevDesc) {
        let welcome_message = self.welcome_message;
        rprintln!("message from device: {welcome_message}");
    }
}

/// Create a new device.
///
/// @export
#[extendr]
fn my_device(welcome_message: String) {
    let device_driver = MyDevice {
        welcome_message: welcome_message.as_str(),
    };

    let device_descriptor = DeviceDescriptor::new();
    let device = device_driver.create_device::<MyDevice>(device_descriptor, "my device");
}

This can be called from R.

my_device("I'm so active!!!")
#> message from device: I'm so active!!!

Re-exports§

pub use device_descriptor::*;
pub use device_driver::*;

Modules§

color
device_descriptor
device_driver

Structs§

Context
Device
GESystemDesc
Pattern
R_GE_gcontext
Raster
A row-major array of pixels. One pixel is 32-bit, whose each byte represents alpha, blue, green, and red in the order.
TextMetric
_DevDesc
_GEDevDesc

Enums§

FontFace
GEUnit
GEevent
LineEnd
LineJoin
LineType
R_GE_lineend
R_GE_linejoin
Unit
cetype_t
cetype_t is an identifier reseved by POSIX, but it is well established as public. Could remap by a #define though

Constants§

LTY_BLANK
LTY_DASHED
LTY_DOTDASH
LTY_DOTTED
LTY_LONGDASH
LTY_SOLID
LTY_TWODASH
R_GE_definitions
R_GE_version

Statics§

R_NilValue
The nil object

Functions§

GECap
GECircle
GEExpressionHeight
GEExpressionMetric
GEExpressionWidth
GELine
GEMathText
GEMetricInfo
GEMode
GENewPage
GEPath
GEPolygon
GEPolyline
GERaster
GERect
GESetClip
GEStrHeight
GEStrMetric
GEStrWidth
GESymbol
GEText
GEaddDevice2
GEcreateDevDesc
GEcurrentDevice
GEdeviceNumber
GEfromDeviceHeight
GEfromDeviceWidth
GEfromDeviceX
GEfromDeviceY
GEgetDevice
GEinitDisplayList
GEtoDeviceHeight
GEtoDeviceWidth
GEtoDeviceX
GEtoDeviceY
R_CheckDeviceAvailable
R_GE_checkVersionOrDie
Rf_NoDevices
Rf_NumDevices
unit_to_ge 🔒

Type Aliases§

DevDesc
GEDevDesc
GEcallback
pDevDesc
pGEDevDesc
pGEcontext