diff --git a/README.md b/README.md index 87f7c23..b9f79e8 100644 --- a/README.md +++ b/README.md @@ -36,18 +36,6 @@ fn main() { } ``` -## API - -### `Screen` - -The `Screen` struct represents a screen capturer and provides the following methods: - -- `Screen::new(display_info)`: Get a screen from the [display info](https://docs.rs/display-info/latest/display_info/struct.DisplayInfo.html), returns a `Screen`. -- `Screen::all()`: Get all screens, returns `Result>`. -- `Screen::from_point(x, y)`: Get a screen from a point, returns `Result`. -- `screen.capture()`: Capture a screenshot of the screen, returns a [image](https://docs.rs/image/latest/image/type.RgbaImage.html) as `Result`. -- `screen.capture_area(x, y, width, height)`: Capture a screenshot of the designated area of the screen, returns the same as `capture()`. - ## Linux Requirements On Linux, you need to install `libxcb`, `libxrandr`, and `dbus`. diff --git a/src/lib.rs b/src/lib.rs index bcc01ca..2eda6f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,36 +22,40 @@ mod linux; #[cfg(target_os = "linux")] use linux::*; +/// This struct represents a screen capturer. #[derive(Debug, Clone, Copy)] pub struct Screen { pub display_info: DisplayInfo, } impl Screen { + /// Get a screen from the [display_info]. + /// + /// [display_info]: https://docs.rs/display-info/latest/display_info/struct.DisplayInfo.html pub fn new(display_info: &DisplayInfo) -> Self { Screen { display_info: *display_info, } } + /// Return all available screens. pub fn all() -> Result> { let screens = DisplayInfo::all()?.iter().map(Screen::new).collect(); Ok(screens) } + /// Get a screen which includes the point with the given coordinates. pub fn from_point(x: i32, y: i32) -> Result { let display_info = DisplayInfo::from_point(x, y)?; Ok(Screen::new(&display_info)) } + /// Capture a screenshot of the screen. pub fn capture(&self) -> Result { capture_screen(&self.display_info) } - /** - * 截取指定区域 - * 区域x,y为相对于当前屏幕的x,y坐标 - */ + /// Captures a screenshot of the designated area of the screen. pub fn capture_area(&self, x: i32, y: i32, width: u32, height: u32) -> Result { let display_info = self.display_info; let screen_x2 = display_info.x + display_info.width as i32;