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§
Structs§
- Context
- Device
- GESystem
Desc - 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.
- Text
Metric - _Dev
Desc - _GEDev
Desc
Enums§
- Font
Face - GEUnit
- GEevent
- LineEnd
- Line
Join - Line
Type - 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⚠
- GEExpression
Height ⚠ - GEExpression
Metric ⚠ - GEExpression
Width ⚠ - GELine⚠
- GEMath
Text ⚠ - GEMetric
Info ⚠ - GEMode⚠
- GENew
Page ⚠ - GEPath⚠
- GEPolygon⚠
- GEPolyline⚠
- GERaster⚠
- GERect⚠
- GESet
Clip ⚠ - GEStr
Height ⚠ - GEStr
Metric ⚠ - GEStr
Width ⚠ - GESymbol⚠
- GEText⚠
- GEadd
Device2 ⚠ - GEcreate
DevDesc ⚠ - GEcurrent
Device ⚠ - GEdevice
Number ⚠ - GEfrom
Device ⚠Height - GEfrom
Device ⚠Width - GEfrom
DeviceX ⚠ - GEfrom
DeviceY ⚠ - GEget
Device ⚠ - GEinit
Display ⚠List - GEto
Device ⚠Height - GEto
Device ⚠Width - GEto
DeviceX ⚠ - GEto
DeviceY ⚠ - R_
Check ⚠Device Available - R_
GE_ ⚠check Version OrDie - Rf_
NoDevices ⚠ - Rf_
NumDevices ⚠ - unit_
to_ 🔒ge