1
0
Fork 0

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

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

View File

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

View File

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