Skip to content

Commit

Permalink
fix image rendering issue when playback position is bottom (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
aome510 authored Jan 3, 2024
1 parent 3683f41 commit b622b2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
12 changes: 0 additions & 12 deletions spotify_player/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@ pub fn run(state: SharedState) -> Result<()> {
}

if let Err(err) = terminal.draw(|frame| {
#[cfg(feature = "image")]
{
for x in 1..state.configs.app_config.cover_img_length + 1 {
for y in 1..state.configs.app_config.cover_img_width + 1 {
frame
.buffer_mut()
.get_mut(x as u16, y as u16)
.set_skip(true);
}
}
}

// set the background and foreground colors for the application
let rect = frame.size();
let block = Block::default().style(ui.theme.app_style());
Expand Down
28 changes: 16 additions & 12 deletions spotify_player/src/ui/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ pub fn render_playback_window(
(hor_chunks[2], ver_chunks[0])
};

// set the `skip` state of cells in the cover image area
// to prevent buffer from overwriting image cells
for x in cover_img_rect.left()..cover_img_rect.right() {
for y in cover_img_rect.top()..cover_img_rect.bottom() {
frame.buffer_mut().get_mut(x, y).set_skip(true);
}
}

let url = crate::utils::get_track_album_image_url(track).map(String::from);
if let Some(url) = url {
let needs_render = match &ui.last_cover_image_render_info {
Expand Down Expand Up @@ -105,20 +113,16 @@ pub fn render_playback_window(
// clear the previous widget's area before rendering the text.
#[cfg(feature = "image")]
{
if ui.last_cover_image_render_info.is_some() {
if let Some((_, rect)) = ui.last_cover_image_render_info {
frame.render_widget(Clear, rect);
ui.last_cover_image_render_info = None;
}

// reset the `skip` state of cells in cover image area
// to render the "No playback found" message
for x in 1..state.configs.app_config.cover_img_length + 1 {
for y in 1..state.configs.app_config.cover_img_width + 1 {
frame
.buffer_mut()
.get_mut(x as u16, y as u16)
.set_skip(false);
// reset the `skip` state of cells in the cover image area
// in order to render the "No playback found" message
for x in rect.left()..rect.right() {
for y in rect.top()..rect.bottom() {
frame.buffer_mut().get_mut(x, y).set_skip(false);
}
}
ui.last_cover_image_render_info = None;
}
}

Expand Down

0 comments on commit b622b2c

Please sign in to comment.