LibGUI: Add and use TextEditor::fixed_elements_width()

We were manually adding together the gutter and ruler widths in several
places. Soon we'll have a third section that needs to be included in
this width, so let's abstract it now.
This commit is contained in:
Sam Atkins 2023-02-19 16:17:18 +00:00 committed by Andreas Kling
parent 1a5159df73
commit 54d45d4ac6
Notes: sideshowbarker 2024-07-16 23:58:27 +09:00
2 changed files with 6 additions and 5 deletions

View File

@ -138,7 +138,7 @@ void TextEditor::update_content_size()
content_width = max(frame_inner_rect().width(), content_width);
set_content_size({ content_width, content_height });
set_size_occupied_by_fixed_elements({ gutter_width() + ruler_width(), 0 });
set_size_occupied_by_fixed_elements({ fixed_elements_width(), 0 });
}
TextPosition TextEditor::text_position_at_content_position(Gfx::IntPoint content_position) const
@ -202,7 +202,7 @@ TextPosition TextEditor::text_position_at(Gfx::IntPoint widget_position) const
{
auto content_position = widget_position;
content_position.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
content_position.translate_by(-(m_horizontal_content_padding + gutter_width() + ruler_width()), 0);
content_position.translate_by(-(m_horizontal_content_padding + fixed_elements_width()), 0);
content_position.translate_by(-frame_thickness(), -frame_thickness());
content_position.translate_by(0, -height_occupied_by_banner_widget());
return text_position_at_content_position(content_position);
@ -396,9 +396,9 @@ Gfx::IntRect TextEditor::ruler_rect_in_inner_coordinates() const
Gfx::IntRect TextEditor::visible_text_rect_in_inner_coordinates() const
{
return {
m_horizontal_content_padding + gutter_width() + ruler_width(),
m_horizontal_content_padding + fixed_elements_width(),
0,
frame_inner_rect().width() - (m_horizontal_content_padding * 2) - width_occupied_by_vertical_scrollbar() - gutter_width() + ruler_width(),
frame_inner_rect().width() - (m_horizontal_content_padding * 2) - width_occupied_by_vertical_scrollbar() - fixed_elements_width(),
frame_inner_rect().height() - height_occupied_by_horizontal_scrollbar()
};
}
@ -493,7 +493,7 @@ void TextEditor::paint_event(PaintEvent& event)
if (m_icon && horizontal_scrollbar_value > 0)
painter.translate(min(icon_size() + icon_padding(), horizontal_scrollbar_value), 0);
auto gutter_ruler_width = gutter_width() + ruler_width();
auto gutter_ruler_width = fixed_elements_width();
painter.translate(gutter_ruler_width, 0);
Gfx::IntRect text_clip_rect { 0, 0, widget_inner_rect().width() - gutter_ruler_width, widget_inner_rect().height() };
text_clip_rect.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());

View File

@ -274,6 +274,7 @@ protected:
Gfx::IntRect content_rect_for_position(TextPosition const&) const;
int gutter_width() const;
int ruler_width() const;
int fixed_elements_width() const { return gutter_width() + ruler_width(); }
virtual void highlighter_did_set_spans(Vector<TextDocumentSpan> spans) final { document().set_spans(Syntax::HighlighterClient::span_collection_index, move(spans)); }