Merge pull request #5183 from Beep6581/centeredthumb

Center selected thumb in Filmstrip #5174
This commit is contained in:
Beep6581
2019-03-11 19:49:10 +01:00
committed by GitHub
3 changed files with 65 additions and 64 deletions

View File

@@ -1732,62 +1732,60 @@ void FileBrowser::buttonPressed (LWButton* button, int actionCode, void* actionD
}
}
void FileBrowser::openNextImage ()
void FileBrowser::openNextImage()
{
MYWRITERLOCK(l, entryRW);
if (!fd.empty() && selected.size() > 0 && !options.tabbedUI) {
for (size_t i = 0; i < fd.size() - 1; i++) {
if (selected[0]->thumbnail->getFileName() == fd[i]->filename) { // located 1-st image in current selection
if (i < fd.size() && tbl) {
// find the first not-filtered-out (next) image
for (size_t k = i + 1; k < fd.size(); k++) {
if (!fd[k]->filtered/*checkFilter (fd[k])*/) {
// clear current selection
for (size_t j = 0; j < selected.size(); j++) {
selected[j]->selected = false;
}
selected.clear ();
selected.clear();
// set new selection
fd[k]->selected = true;
selected.push_back (fd[k]);
//queue_draw ();
selected.push_back(fd[k]);
//queue_draw();
MYWRITERLOCK_RELEASE(l);
// this will require a read access
notifySelectionListener ();
notifySelectionListener();
MYWRITERLOCK_ACQUIRE(l);
// scroll to the selected position
double h1, v1;
getScrollPosition(h1, v1);
// scroll to the selected position, centered horizontally in the container
double x1, y1;
getScrollPosition(x1, y1);
double h2 = selected[0]->getStartX();
double v2 = selected[0]->getStartY();
double x2 = selected[0]->getStartX();
double y2 = selected[0]->getStartY();
Thumbnail* thumb = (static_cast<FileBrowserEntry*>(fd[k]))->thumbnail;
int minWidth = get_width() - fd[k]->getMinimalWidth();
int tw = fd[k]->getMinimalWidth(); // thumb width
int ww = get_width(); // window width
MYWRITERLOCK_RELEASE(l);
// scroll only when selected[0] is outside of the displayed bounds
if (h2 + minWidth - h1 > get_width()) {
setScrollPosition(h2 - minWidth, v2);
}
if (h1 > h2) {
setScrollPosition(h2, v2);
// or less than a thumbnail's width from either edge.
if ((x2 > x1 + ww - 2 * tw) || (x2 - tw < x1)) {
setScrollPosition(x2 - (ww - tw) / 2, y2);
}
// open the selected image
std::vector<Thumbnail*> entries;
entries.push_back (thumb);
tbl->openRequested (entries);
tbl->openRequested({thumb});
return;
}
}
@@ -1797,62 +1795,60 @@ void FileBrowser::openNextImage ()
}
}
void FileBrowser::openPrevImage ()
void FileBrowser::openPrevImage()
{
MYWRITERLOCK(l, entryRW);
if (!fd.empty() && selected.size() > 0 && !options.tabbedUI) {
for (size_t i = 1; i < fd.size(); i++) {
if (selected[0]->thumbnail->getFileName() == fd[i]->filename) { // located 1-st image in current selection
if (i > 0 && tbl) {
// find the first not-filtered-out (previous) image
for (ssize_t k = (ssize_t)i - 1; k >= 0; k--) {
if (!fd[k]->filtered/*checkFilter (fd[k])*/) {
// clear current selection
for (size_t j = 0; j < selected.size(); j++) {
selected[j]->selected = false;
}
selected.clear ();
selected.clear();
// set new selection
fd[k]->selected = true;
selected.push_back (fd[k]);
//queue_draw ();
selected.push_back(fd[k]);
//queue_draw();
MYWRITERLOCK_RELEASE(l);
// this will require a read access
notifySelectionListener ();
notifySelectionListener();
MYWRITERLOCK_ACQUIRE(l);
// scroll to the selected position
double h1, v1;
getScrollPosition(h1, v1);
// scroll to the selected position, centered horizontally in the container
double x1, y1;
getScrollPosition(x1, y1);
double h2 = selected[0]->getStartX();
double v2 = selected[0]->getStartY();
double x2 = selected[0]->getStartX();
double y2 = selected[0]->getStartY();
Thumbnail* thumb = (static_cast<FileBrowserEntry*>(fd[k]))->thumbnail;
int minWidth = get_width() - fd[k]->getMinimalWidth();
int tw = fd[k]->getMinimalWidth(); // thumb width
int ww = get_width(); // window width
MYWRITERLOCK_RELEASE(l);
// scroll only when selected[0] is outside of the displayed bounds
if (h2 + minWidth - h1 > get_width()) {
setScrollPosition(h2 - minWidth, v2);
}
if (h1 > h2) {
setScrollPosition(h2, v2);
// or less than a thumbnail's width from either edge.
if ((x2 > x1 + ww - 2 * tw) || (x2 - tw < x1)) {
setScrollPosition(x2 - (ww - tw) / 2, y2);
}
// open the selected image
std::vector<Thumbnail*> entries;
entries.push_back (thumb);
tbl->openRequested (entries);
tbl->openRequested({thumb});
return;
}
}
@@ -1862,11 +1858,8 @@ void FileBrowser::openPrevImage ()
}
}
void FileBrowser::selectImage (Glib::ustring fname)
void FileBrowser::selectImage(const Glib::ustring& fname, bool doScroll)
{
// need to clear the filter in filecatalog
MYWRITERLOCK(l, entryRW);
if (!fd.empty() && !options.tabbedUI) {
@@ -1879,27 +1872,34 @@ void FileBrowser::selectImage (Glib::ustring fname)
selected[j]->selected = false;
}
selected.clear ();
selected.clear();
// set new selection
fd[i]->selected = true;
selected.push_back (fd[i]);
queue_draw ();
selected.push_back(fd[i]);
queue_draw();
MYWRITERLOCK_RELEASE(l);
// this will require a read access
notifySelectionListener ();
notifySelectionListener();
MYWRITERLOCK_ACQUIRE(l);
// scroll to the selected position
double h = selected[0]->getStartX();
double v = selected[0]->getStartY();
// scroll to the selected position, centered horizontally in the container
double x = selected[0]->getStartX();
double y = selected[0]->getStartY();
int tw = fd[i]->getMinimalWidth(); // thumb width
int ww = get_width(); // window width
MYWRITERLOCK_RELEASE(l);
setScrollPosition(h, v);
if (doScroll) {
// Center thumb
setScrollPosition(x - (ww - tw) / 2, y);
}
return;
}
@@ -1907,11 +1907,11 @@ void FileBrowser::selectImage (Glib::ustring fname)
}
}
void FileBrowser::openNextPreviousEditorImage (Glib::ustring fname, eRTNav nextPrevious)
void FileBrowser::openNextPreviousEditorImage (const Glib::ustring& fname, eRTNav nextPrevious)
{
// let FileBrowser acquire Editor's perspective
selectImage (fname);
selectImage (fname, false);
// now switch to the requested image
if (nextPrevious == NAV_NEXT) {