Skip to content

Commit

Permalink
gallery: Change start position if loading failed
Browse files Browse the repository at this point in the history
Relates to #177.

Signed-off-by: Artem Senichev <[email protected]>
  • Loading branch information
artemsen committed Aug 13, 2024
1 parent 8d2d474 commit edf57ab
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/gallery.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ static void draw_thumbnails(struct pixmap* window)
// get next thumbnail index
index = image_list_next_file(index);
if (index == IMGLIST_INVALID || index <= ctx.top) {
row = rows; // break parent loop
break;
goto done;
}
}
}

done:
// draw selected thumbnail
draw_thumbnail(window, select_x, select_y,
select_th ? select_th->image : NULL, true);
Expand Down Expand Up @@ -330,27 +330,33 @@ static void fixup_position(void)
}

/**
* Set current selection.
* @param index image index to set as selected one
* Update info text container for currently selected image.
*/
static void select_thumbnail(size_t index)
static void update_info(void)
{
const struct thumbnail* th;

ctx.selected = index;
const struct thumbnail* th = get_thumbnail(ctx.selected);

th = get_thumbnail(index);
if (th) {
info_reset(th->image);
info_update(info_image_size, "%zux%zu", th->width, th->height);
info_update(info_index, "%zu of %zu", th->image->index + 1,
image_list_size());
}

fixup_position();
app_redraw();
}

/**
* Set current selection.
* @param index image index to set as selected one
*/
static void select_thumbnail(size_t index)
{
ctx.selected = index;
fixup_position();
update_info();
}

/**
* Skip current image.
* @return true if next image was loaded
Expand Down Expand Up @@ -516,15 +522,21 @@ static void on_image_load(struct image* image, size_t index)
} else {
add_thumbnail(image);
if (index == ctx.selected) {
select_thumbnail(ctx.selected); // update meta info
update_info();
}
}
} else {
loader_queue_reset();
if (index == ctx.selected) {
skip_current();
} else {
image_list_skip(index);
const size_t next = image_list_skip(index);
if (index == ctx.top) {
ctx.top = image_list_prev_file(index);
if (ctx.top > index) {
ctx.top = next;
}
}
fixup_position();
}
}
Expand Down

0 comments on commit edf57ab

Please sign in to comment.