2024-03-16 17:07:12 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use tiny_skia::Pixmap;
|
|
|
|
|
|
|
|
use crate::components::background::Background;
|
|
|
|
use crate::components::container::Container;
|
|
|
|
use crate::components::editor::code::Code;
|
|
|
|
use crate::components::editor::mac_title_bar::MacTitleBar;
|
2024-03-16 15:10:35 +00:00
|
|
|
use crate::components::interface::component::ComponentContext;
|
2024-03-16 17:07:12 +00:00
|
|
|
use crate::components::interface::render_error;
|
|
|
|
use crate::components::rect::Rect;
|
|
|
|
use crate::components::watermark::Watermark;
|
|
|
|
use crate::config::TakeSnapshotParams;
|
|
|
|
|
|
|
|
// Scale the screenshot to 3 times its size
|
|
|
|
const SCALE_FACTOR: f32 = 3.;
|
|
|
|
|
|
|
|
// The params is come from neovim instance
|
|
|
|
pub fn take_snapshot(params: TakeSnapshotParams) -> render_error::Result<Pixmap> {
|
|
|
|
let context = ComponentContext {
|
|
|
|
scale_factor: SCALE_FACTOR,
|
|
|
|
take_snapshot_params: Arc::new(params.clone()),
|
|
|
|
};
|
|
|
|
let pixmap = Container::from_children(vec![Box::new(Background::from_children(vec![
|
|
|
|
Box::new(Rect::new(
|
|
|
|
16.,
|
|
|
|
vec![
|
|
|
|
Box::new(MacTitleBar::from_radius(8.)),
|
|
|
|
Box::new(Code::new(params.code, 20., 15.)),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
Box::new(Watermark::new(params.watermark)),
|
|
|
|
]))])
|
|
|
|
.draw_root(&context)?;
|
|
|
|
|
|
|
|
Ok(pixmap)
|
|
|
|
}
|