mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
More scrolling work. Now the scrollbar parameters are normalized against the screen geometry and coordinates. This simplifies the logic and the code significantly.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22614 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3352fe5fc8
commit
ae0667c112
@ -417,6 +417,11 @@ void BufferView::updateScrollbar()
|
|||||||
if (height_ == 0)
|
if (height_ == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// We prefer fixed size line scrolling.
|
||||||
|
d->scrollbarParameters_.single_step = defaultRowHeight();
|
||||||
|
// We prefer full screen page scrolling.
|
||||||
|
d->scrollbarParameters_.page_step = height_;
|
||||||
|
|
||||||
Text & t = buffer_.text();
|
Text & t = buffer_.text();
|
||||||
TextMetrics & tm = d->text_metrics_[&t];
|
TextMetrics & tm = d->text_metrics_[&t];
|
||||||
|
|
||||||
@ -433,9 +438,6 @@ void BufferView::updateScrollbar()
|
|||||||
d->par_height_.resize(parsize, defaultRowHeight() * 2);
|
d->par_height_.resize(parsize, defaultRowHeight() * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// It would be better to fix the scrollbar to understand
|
|
||||||
// values in [0..1] and divide everything by wh
|
|
||||||
|
|
||||||
// Look at paragraph heights on-screen
|
// Look at paragraph heights on-screen
|
||||||
pair<pit_type, ParagraphMetrics const *> first = tm.first();
|
pair<pit_type, ParagraphMetrics const *> first = tm.first();
|
||||||
pair<pit_type, ParagraphMetrics const *> last = tm.last();
|
pair<pit_type, ParagraphMetrics const *> last = tm.last();
|
||||||
@ -445,31 +447,26 @@ void BufferView::updateScrollbar()
|
|||||||
<< d->par_height_[pit]);
|
<< d->par_height_[pit]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int top_pos = first.second->position() - first.second->ascent();
|
||||||
// Build temporary cursor.
|
int bottom_pos = last.second->position() + last.second->descent();
|
||||||
Cursor cur(*this);
|
bool first_visible = first.first == 0 && top_pos >= 0;
|
||||||
cur.push(buffer_.inset());
|
bool last_visible = last.first == parsize - 1 && bottom_pos <= height_;
|
||||||
/*Inset * inset =*/ tm.editXY(cur, 0, 10);
|
if (first_visible && last_visible) {
|
||||||
pit_type const first_visible_pit = cur.bottom().pit();
|
d->scrollbarParameters_.min = 0;
|
||||||
d->scrollbarParameters_.position = coordOffset(cur, cur.boundary()).y_;
|
d->scrollbarParameters_.max = 0;
|
||||||
ParagraphMetrics const & visible_pm = tm.parMetrics(first_visible_pit);
|
return;
|
||||||
d->scrollbarParameters_.position -= visible_pm.position();
|
|
||||||
d->scrollbarParameters_.position += visible_pm.ascent();
|
|
||||||
// FIXME: The screen position (0, 10) works reasonably well for most texts
|
|
||||||
// but the bottom position is still not correct.
|
|
||||||
LYXERR(Debug::SCROLLING, "first visible pit : " << first_visible_pit);
|
|
||||||
LYXERR(Debug::SCROLLING, "offset from top : "
|
|
||||||
<< d->scrollbarParameters_.position);
|
|
||||||
|
|
||||||
d->scrollbarParameters_.height = 0;
|
|
||||||
for (size_t i = 0; i != d->par_height_.size(); ++i) {
|
|
||||||
if (i == first_visible_pit)
|
|
||||||
d->scrollbarParameters_.position += d->scrollbarParameters_.height;
|
|
||||||
d->scrollbarParameters_.height += d->par_height_[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We prefer fixed size line scrolling.
|
d->scrollbarParameters_.min = top_pos;
|
||||||
d->scrollbarParameters_.lineScrollHeight = defaultRowHeight();
|
for (size_t i = 0; i != first.first; ++i)
|
||||||
|
d->scrollbarParameters_.min -= d->par_height_[i];
|
||||||
|
d->scrollbarParameters_.max = bottom_pos;
|
||||||
|
for (size_t i = last.first + 1; i != parsize; ++i)
|
||||||
|
d->scrollbarParameters_.max += d->par_height_[i];
|
||||||
|
|
||||||
|
d->scrollbarParameters_.position = 0;
|
||||||
|
// The reference is the top position so we remove one page.
|
||||||
|
d->scrollbarParameters_.max -= d->scrollbarParameters_.page_step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1427,8 +1424,8 @@ void BufferView::lfunScroll(FuncRequest const & cmd)
|
|||||||
{
|
{
|
||||||
string const scroll_type = cmd.getArg(0);
|
string const scroll_type = cmd.getArg(0);
|
||||||
int const scroll_step =
|
int const scroll_step =
|
||||||
(scroll_type == "line")? d->scrollbarParameters_.lineScrollHeight
|
(scroll_type == "line")? d->scrollbarParameters_.single_step
|
||||||
: (scroll_type == "page")? height_ : 0;
|
: (scroll_type == "page")? d->scrollbarParameters_.page_step : 0;
|
||||||
if (scroll_step == 0)
|
if (scroll_step == 0)
|
||||||
return;
|
return;
|
||||||
string const scroll_quantity = cmd.getArg(1);
|
string const scroll_quantity = cmd.getArg(1);
|
||||||
|
@ -52,19 +52,16 @@ enum CursorStatus {
|
|||||||
/// Scrollbar Parameters.
|
/// Scrollbar Parameters.
|
||||||
struct ScrollbarParameters
|
struct ScrollbarParameters
|
||||||
{
|
{
|
||||||
void reset(int h = 0, int p = 0, int l = 0)
|
/// Minimum scrollbar position in pixels.
|
||||||
{
|
int min;
|
||||||
height = h;
|
/// Maximum scrollbar position in pixels.
|
||||||
position = p;
|
int max;
|
||||||
lineScrollHeight = l;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Total document height in pixels.
|
|
||||||
int height;
|
|
||||||
/// Current position in the document in pixels.
|
/// Current position in the document in pixels.
|
||||||
int position;
|
int position;
|
||||||
/// Line-scroll amount in pixels.
|
/// Line-scroll amount in pixels.
|
||||||
int lineScrollHeight;
|
int single_step;
|
||||||
|
/// Page-scroll amount in pixels.
|
||||||
|
int page_step;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Screen view of a Buffer.
|
/// Screen view of a Buffer.
|
||||||
|
@ -463,10 +463,11 @@ void GuiWorkArea::updateScrollbar()
|
|||||||
verticalScrollBar()->setTracking(false);
|
verticalScrollBar()->setTracking(false);
|
||||||
|
|
||||||
ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
|
ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
|
||||||
verticalScrollBar()->setRange(0, scroll_.height);
|
verticalScrollBar()->setRange(scroll_.min, scroll_.max);
|
||||||
verticalScrollBar()->setSliderPosition(scroll_.position);
|
verticalScrollBar()->setPageStep(scroll_.page_step);
|
||||||
verticalScrollBar()->setSingleStep(scroll_.lineScrollHeight);
|
verticalScrollBar()->setSingleStep(scroll_.single_step);
|
||||||
verticalScrollBar()->setValue(scroll_.position);
|
verticalScrollBar()->setValue(scroll_.position);
|
||||||
|
// verticalScrollBar()->setSliderPosition(scroll_.position);
|
||||||
|
|
||||||
verticalScrollBar()->setTracking(true);
|
verticalScrollBar()->setTracking(true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user