Skip to content

Commit

Permalink
[Fix] condition render for mac window bar component (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistricky authored Mar 31, 2024
1 parent 70f1ff8 commit 6c75317
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion generator/src/components/editor/mac_title_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
}
}

Expand Down
8 changes: 8 additions & 0 deletions generator/src/components/interface/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub trait Component {
render_params.clone()
}

fn render_condition(&self) -> bool {
true
}

fn draw_self(
&self,
_pixmap: &mut Pixmap,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion generator/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.,
Expand Down

0 comments on commit 6c75317

Please sign in to comment.