nitpicker_gfx: Text_painter::Font::index_at_xpos

This method is useful for finding the character under a mouse position.
This commit is contained in:
Norman Feske 2020-01-14 17:57:13 +01:00 committed by Christian Helmuth
parent 1273c573b6
commit 46c5a90ba1
1 changed files with 14 additions and 0 deletions

View File

@ -97,6 +97,20 @@ struct Text_painter
return result;
}
unsigned index_at_xpos(Genode::Utf8_ptr utf8, unsigned xpos) const
{
unsigned index = 0;
Fixpoint_number x { (int)0 };
for (; utf8.complete(); utf8 = utf8.next(), index++) {
x.value += advance_info(utf8.codepoint()).advance.value;
if (x.decimal() > (int)xpos)
break;
}
return index;
}
};