[Fix] condition render for mac window bar component (#54)

pull/55/head
Mist 2024-03-31 17:48:14 +08:00 committed by GitHub
parent 70f1ff882c
commit 6c753177e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View File

@ -9,6 +9,7 @@ use crate::components::interface::{
pub struct MacTitleBar {
radius: f32,
children: Vec<Box<dyn Component>>,
render_condition: bool,
}
impl Component for MacTitleBar {
@ -22,6 +23,10 @@ impl Component for MacTitleBar {
Style::default().size(Size::Num(demeter + 2. * 25.), Size::Num(demeter))
}
fn render_condition(&self) -> bool {
return self.render_condition;
}
fn draw_self(
&self,
pixmap: &mut tiny_skia::Pixmap,
@ -50,10 +55,11 @@ impl Component for MacTitleBar {
}
impl MacTitleBar {
pub fn from_radius(radius: f32) -> MacTitleBar {
pub fn from_radius(radius: f32, render_condition: bool) -> MacTitleBar {
MacTitleBar {
radius,
children: vec![],
render_condition,
}
}

View File

@ -63,6 +63,10 @@ pub trait Component {
render_params.clone()
}
fn render_condition(&self) -> bool {
true
}
fn draw_self(
&self,
_pixmap: &mut Pixmap,
@ -128,6 +132,10 @@ pub trait Component {
let mut sibling_style = ComponentStyle::default();
for child in children {
if !child.render_condition() {
continue;
}
sibling_render_params = child.draw(
pixmap,
context,

View File

@ -26,7 +26,7 @@ pub fn take_snapshot(params: TakeSnapshotParams) -> render_error::Result<Pixmap>
Box::new(Rect::new(
16.,
vec![
Box::new(MacTitleBar::from_radius(8.)),
Box::new(MacTitleBar::from_radius(8., params.mac_window_bar)),
Box::new(Breadcrumbs::from_path(
params.file_path,
15.,