window_draw_list: Use generic to add_text

This change allows to use `add_text` with any type that implements
`AsRef<str>`. This includes `String`, `&str`, `ImString` and `&ImStr`.
This commit is contained in:
Malik Olivier Boussejra 2018-05-30 14:20:28 +09:00
parent 429073a29c
commit 485c8a230e

View File

@ -210,11 +210,13 @@ impl<'ui> WindowDrawList<'ui> {
}
/// Draw a text whose upper-left corner is at point `pos`.
pub fn add_text<P, C>(&self, pos: P, col: C, text: &str)
pub fn add_text<P, C, T>(&self, pos: P, col: C, text: T)
where
P: Into<ImVec2>,
C: Into<ImColor>,
T: AsRef<str>,
{
let text = text.as_ref();
unsafe {
let start = text.as_ptr() as *const i8;
let end = (start as usize + text.len()) as *const i8;