From 6c753177e3891acfc908de2a49da7fe408339da3 Mon Sep 17 00:00:00 2001 From: Mist Date: Sun, 31 Mar 2024 17:48:14 +0800 Subject: [PATCH] [Fix] condition render for mac window bar component (#54) --- generator/src/components/editor/mac_title_bar.rs | 8 +++++++- generator/src/components/interface/component.rs | 8 ++++++++ generator/src/snapshot.rs | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/generator/src/components/editor/mac_title_bar.rs b/generator/src/components/editor/mac_title_bar.rs index f09ce53..acf67c2 100644 --- a/generator/src/components/editor/mac_title_bar.rs +++ b/generator/src/components/editor/mac_title_bar.rs @@ -9,6 +9,7 @@ use crate::components::interface::{ pub struct MacTitleBar { radius: f32, children: Vec>, + 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, } } diff --git a/generator/src/components/interface/component.rs b/generator/src/components/interface/component.rs index 5461377..2bef71a 100644 --- a/generator/src/components/interface/component.rs +++ b/generator/src/components/interface/component.rs @@ -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, diff --git a/generator/src/snapshot.rs b/generator/src/snapshot.rs index 1344e48..daeb410 100644 --- a/generator/src/snapshot.rs +++ b/generator/src/snapshot.rs @@ -26,7 +26,7 @@ pub fn take_snapshot(params: TakeSnapshotParams) -> render_error::Result 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.,