if(multiline)
check_view_range();
-
- rebuild();
-}
-
-void Entry::set_edit_position(unsigned pos)
-{
- edit_pos = min(pos, text.size());
- selection_active = false;
-
- if(multiline)
- check_view_range();
-
rebuild();
}
if(!text_part || !graphic || !graphic->get_texture())
return;
- unsigned start = selection_pos;
- unsigned end = edit_pos;
- if(start>end)
- swap(start, end);
+ unsigned start, end;
+ get_selection(start, end);
unsigned row, col;
text.offset_to_coords(start, row, col);
if(selection_active)
erase_selection();
else if(edit_pos>0)
- {
- text.erase(--edit_pos, 1);
- check_view_range();
- rebuild();
- }
+ erase(edit_pos-1, 1);
}
else if(key==Input::KEY_DELETE)
{
if(selection_active)
erase_selection();
else
- text.erase(edit_pos, 1);
+ erase(edit_pos, 1);
}
else if(key==Input::KEY_ENTER && multiline)
- {
- text.insert(edit_pos++, "\n");
- check_view_range();
- rebuild();
- }
+ insert(edit_pos, "\n");
else if(key==Input::KEY_END)
{
unsigned row, col;
{
if(selection_active)
erase_selection();
- text.insert(edit_pos, StringCodec::encode<StringCodec::Utf8>(StringCodec::ustring(1, ch)));
- ++edit_pos;
- rebuild();
+ insert(edit_pos, StringCodec::encode<StringCodec::Utf8>(StringCodec::ustring(1, ch)));
return true;
}
selection_pos = edit_pos;
selection_active = select;
- edit_pos = ep;
- check_view_range();
+ edit_pos = min(ep, text.size());
+ if(multiline)
+ check_view_range();
rebuild();
}
void Entry::erase_selection()
{
- if(!selection_active)
+ unsigned start, end;
+ if(!get_selection(start, end))
return;
- unsigned start = selection_pos;
- unsigned end = edit_pos;
- if(start>end)
- swap(start, end);
-
text.erase(start, end-start);
set_edit_position(start, false);
}
if(!multiline || !text_part)
return;
- float font_size = style->get_font_size();
- unsigned line_spacing = static_cast<unsigned>(font_size*6/5);
-
- const Sides &margin = text_part->get_margin();
- visible_rows = max((geom.h-margin.top-margin.bottom)/line_spacing, 1U);
+ visible_rows = text.get_visible_lines(*text_part, geom, 0);
unsigned row, col;
text.offset_to_coords(edit_pos, row, col);