Refactor TextEdit control height calculations

This commit is contained in:
Paulb23 2019-08-25 14:49:13 +01:00
parent c5b5c6b49b
commit 32d5427f55
2 changed files with 16 additions and 36 deletions

View file

@ -596,14 +596,8 @@ void TextEdit::_update_minimap_drag() {
return;
}
int control_height = get_size().height;
control_height -= cache.style_normal->get_minimum_size().height;
if (h_scroll->is_visible_in_tree()) {
control_height -= h_scroll->get_size().height;
}
Point2 mp = get_local_mouse_position();
double diff = (mp.y - minimap_scroll_click_pos) / control_height;
double diff = (mp.y - minimap_scroll_click_pos) / _get_control_height();
v_scroll->set_as_ratio(minimap_scroll_ratio + diff);
}
@ -923,12 +917,7 @@ void TextEdit::_notification(int p_what) {
// calculate viewport size and y offset
int viewport_height = (draw_amount - 1) * minimap_line_height;
int control_height = size.height;
control_height -= cache.style_normal->get_minimum_size().height;
if (h_scroll->is_visible_in_tree()) {
control_height -= h_scroll->get_size().height;
}
control_height -= viewport_height;
int control_height = _get_control_height() - viewport_height;
int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount));
// calculate the first line.
@ -2094,12 +2083,7 @@ void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const
// calculate viewport size and y offset
int viewport_height = (draw_amount - 1) * minimap_line_height;
int control_height = get_size().height;
control_height -= cache.style_normal->get_minimum_size().height;
if (h_scroll->is_visible_in_tree()) {
control_height -= h_scroll->get_size().height;
}
control_height -= viewport_height;
int control_height = _get_control_height() - viewport_height;
int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount));
// calculate the first line.
@ -4043,23 +4027,21 @@ Size2 TextEdit::get_minimum_size() const {
return cache.style_normal->get_minimum_size();
}
int TextEdit::get_visible_rows() const {
int TextEdit::_get_control_height() const {
int control_height = get_size().height;
control_height -= cache.style_normal->get_minimum_size().height;
if (h_scroll->is_visible_in_tree()) {
control_height -= h_scroll->get_size().height;
}
return control_height;
}
int total = get_size().height;
total -= cache.style_normal->get_minimum_size().height;
if (h_scroll->is_visible_in_tree())
total -= h_scroll->get_size().height;
total /= get_row_height();
return total;
int TextEdit::get_visible_rows() const {
return _get_control_height() / get_row_height();
}
int TextEdit::_get_minimap_visible_rows() const {
int total = get_size().height;
total -= cache.style_normal->get_minimum_size().height;
if (h_scroll->is_visible_in_tree())
total -= h_scroll->get_size().height;
total /= (minimap_char_size.y + minimap_line_spacing);
return total;
return _get_control_height() / (minimap_char_size.y + minimap_line_spacing);
}
int TextEdit::get_total_visible_rows() const {
@ -6150,10 +6132,7 @@ int TextEdit::get_last_visible_line_wrap_index() const {
double TextEdit::get_visible_rows_offset() const {
double total = get_size().height;
total -= cache.style_normal->get_minimum_size().height;
if (h_scroll->is_visible_in_tree())
total -= h_scroll->get_size().height;
double total = _get_control_height();
total /= (double)get_row_height();
total = total - floor(total);
total = -CLAMP(total, 0.001, 1) + 1;

View file

@ -422,6 +422,7 @@ private:
//void mouse_motion(const Point& p_pos, const Point& p_rel, int p_button_mask);
Size2 get_minimum_size() const;
int _get_control_height() const;
int get_row_height() const;