pub fn manager() -> &'static Mutex<KittyManager>
Examples found in repository?
src/app/app.rs (line 222)
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
fn display_panels(
&mut self,
w: &mut W,
skin: &AppSkin,
app_state: &AppState,
con: &AppContext,
) -> Result<(), ProgramError> {
self.drawing_count += 1;
for (idx, panel) in self.panels.as_mut_slice().iter_mut().enumerate() {
let active = idx == self.active_panel_idx;
let panel_skin = if active { &skin.focused } else { &skin.unfocused };
let disc = DisplayContext {
count: self.drawing_count,
active,
screen: self.screen,
panel_skin,
state_area: panel.areas.state.clone(),
app_state,
con,
};
time!(
"display panel",
panel.display(w, &disc)?,
);
}
kitty::manager().lock().unwrap().erase_images_before(w, self.drawing_count)?;
w.flush()?;
Ok(())
}
More examples
src/image/image_view.rs (line 109)
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
pub fn display(
&mut self,
w: &mut W,
disc: &DisplayContext,
area: &Area,
) -> Result<(), ProgramError> {
let styles = &disc.panel_skin.styles;
let bg = styles.preview.get_bg()
.or_else(|| styles.default.get_bg())
.unwrap_or(Color::AnsiValue(238));
// we avoid drawing when we were just displayed
// on the last drawing_count and the area is the same.
let drawing_info = DrawingInfo {
drawing_count: disc.count,
area: area.clone(),
};
let must_draw = self.last_drawing
.as_ref()
.map_or(true, |previous| !drawing_info.follows_in_place(previous));
if must_draw {
debug!("image_view must be cleared");
} else {
debug!("no need to clear image_view");
}
self.last_drawing = Some(drawing_info);
let mut kitty_manager = kitty::manager().lock().unwrap();
if !must_draw {
if let Some(kitty_image_id) = self.kitty_image_id {
// we tell the manager the images must be kept, otherwise
// they would be erased at end of drawing, as obsolete
kitty_manager.keep(kitty_image_id, disc.count);
}
return Ok(());
}
self.kitty_image_id = kitty_manager
.try_print_image(w, &self.source_img, area, bg, disc.count)?;
if self.kitty_image_id.is_some() {
return Ok(());
}
let target_width = area.width as u32;
let target_height = (area.height * 2) as u32;
let cached = self
.display_img
.as_ref()
.filter(|ci| ci.target_width == target_width && ci.target_height == target_height);
let img = match cached {
Some(ci) => &ci.img,
None => {
let img = time!(
"resize image",
self.source_img.resize(target_width, target_height, FilterType::Triangle),
);
self.display_img = Some(CachedImage {
img,
target_width,
target_height,
});
&self.display_img.as_ref().unwrap().img
}
};
let (width, height) = img.dimensions();
debug!("resized image dimensions: {},{}", width, height);
debug_assert!(width <= area.width as u32);
let mut double_line = DoubleLine::new(width as usize, disc.con.true_colors);
let mut y = area.top;
let img_top_offset = (area.height - (height / 2) as u16) / 2;
for _ in 0..img_top_offset {
w.queue(cursor::MoveTo(area.left, y))?;
fill_bg(w, area.width as usize, bg)?;
y += 1;
}
let margin = area.width as usize - width as usize;
let left_margin = margin / 2;
let right_margin = margin - left_margin;
w.queue(cursor::MoveTo(area.left, y))?;
for pixel in img.pixels() {
double_line.push(pixel.2);
if double_line.is_full() {
double_line.write(w, left_margin, right_margin, bg)?;
y += 1;
w.queue(cursor::MoveTo(area.left, y))?;
}
}
if !double_line.is_empty() {
double_line.write(w, left_margin, right_margin, bg)?;
y += 1;
}
w.queue(SetBackgroundColor(bg))?;
for y in y..area.top + area.height {
w.queue(cursor::MoveTo(area.left, y))?;
fill_bg(w, area.width as usize, bg)?;
}
Ok(())
}