Merge branch 'master' into feature/performance-metrics
This commit is contained in:
commit
b68ac3aa47
12 changed files with 453 additions and 118 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{Primitive, Renderer};
|
||||
use iced_native::{
|
||||
scrollable, Background, Color, Layout, MouseCursor, Point, Rectangle,
|
||||
Scrollable, Widget,
|
||||
Scrollable, Vector, Widget,
|
||||
};
|
||||
|
||||
const SCROLLBAR_WIDTH: u16 = 10;
|
||||
|
|
@ -58,7 +58,7 @@ impl scrollable::Renderer for Renderer {
|
|||
|
||||
let clip = Primitive::Clip {
|
||||
bounds,
|
||||
offset,
|
||||
offset: Vector::new(0, offset),
|
||||
content: Box::new(content),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::{Primitive, Renderer};
|
|||
|
||||
use iced_native::{
|
||||
text::HorizontalAlignment, text::VerticalAlignment, text_input, Background,
|
||||
Color, MouseCursor, Point, Rectangle, TextInput,
|
||||
Color, MouseCursor, Point, Rectangle, TextInput, Vector,
|
||||
};
|
||||
use std::f32;
|
||||
|
||||
|
|
@ -87,70 +87,79 @@ impl text_input::Renderer for Renderer {
|
|||
vertical_alignment: VerticalAlignment::Center,
|
||||
};
|
||||
|
||||
let content = Primitive::Clip {
|
||||
bounds: text_bounds,
|
||||
offset: 0,
|
||||
content: Box::new(if text_input.state.is_focused {
|
||||
use wgpu_glyph::{GlyphCruncher, Scale, Section};
|
||||
let (contents_primitive, offset) = if text_input.state.is_focused {
|
||||
use wgpu_glyph::{GlyphCruncher, Scale, Section};
|
||||
|
||||
let text_before_cursor = &text_input
|
||||
.value
|
||||
.until(text_input.state.cursor_position(&text_input.value))
|
||||
.to_string();
|
||||
let text_before_cursor = &text_input
|
||||
.value
|
||||
.until(text_input.state.cursor_position(&text_input.value))
|
||||
.to_string();
|
||||
|
||||
let mut text_value_width = self
|
||||
.glyph_brush
|
||||
.borrow_mut()
|
||||
.glyph_bounds(Section {
|
||||
text: text_before_cursor,
|
||||
bounds: (f32::INFINITY, text_bounds.height),
|
||||
scale: Scale { x: size, y: size },
|
||||
..Default::default()
|
||||
})
|
||||
.map(|bounds| bounds.width().round())
|
||||
.unwrap_or(0.0);
|
||||
let mut text_value_width = self
|
||||
.glyph_brush
|
||||
.borrow_mut()
|
||||
.glyph_bounds(Section {
|
||||
text: text_before_cursor,
|
||||
bounds: (f32::INFINITY, text_bounds.height),
|
||||
scale: Scale { x: size, y: size },
|
||||
..Default::default()
|
||||
})
|
||||
.map(|bounds| bounds.width().round())
|
||||
.unwrap_or(0.0);
|
||||
|
||||
let spaces_at_the_end = text_before_cursor.len()
|
||||
- text_before_cursor.trim_end().len();
|
||||
let spaces_at_the_end =
|
||||
text_before_cursor.len() - text_before_cursor.trim_end().len();
|
||||
|
||||
if spaces_at_the_end > 0 {
|
||||
let space_width = {
|
||||
let glyph_brush = self.glyph_brush.borrow();
|
||||
if spaces_at_the_end > 0 {
|
||||
let space_width = {
|
||||
let glyph_brush = self.glyph_brush.borrow();
|
||||
|
||||
// TODO: Select appropriate font
|
||||
let font = &glyph_brush.fonts()[0];
|
||||
// TODO: Select appropriate font
|
||||
let font = &glyph_brush.fonts()[0];
|
||||
|
||||
font.glyph(' ')
|
||||
.scaled(Scale { x: size, y: size })
|
||||
.h_metrics()
|
||||
.advance_width
|
||||
};
|
||||
|
||||
text_value_width += spaces_at_the_end as f32 * space_width;
|
||||
}
|
||||
|
||||
let cursor = Primitive::Quad {
|
||||
bounds: Rectangle {
|
||||
x: text_bounds.x + text_value_width,
|
||||
y: text_bounds.y,
|
||||
width: 1.0,
|
||||
height: text_bounds.height,
|
||||
},
|
||||
background: Background::Color(Color::BLACK),
|
||||
border_radius: 0,
|
||||
font.glyph(' ')
|
||||
.scaled(Scale { x: size, y: size })
|
||||
.h_metrics()
|
||||
.advance_width
|
||||
};
|
||||
|
||||
text_value_width += spaces_at_the_end as f32 * space_width;
|
||||
}
|
||||
|
||||
let cursor = Primitive::Quad {
|
||||
bounds: Rectangle {
|
||||
x: text_bounds.x + text_value_width,
|
||||
y: text_bounds.y,
|
||||
width: 1.0,
|
||||
height: text_bounds.height,
|
||||
},
|
||||
background: Background::Color(Color::BLACK),
|
||||
border_radius: 0,
|
||||
};
|
||||
|
||||
(
|
||||
Primitive::Group {
|
||||
primitives: vec![value, cursor],
|
||||
}
|
||||
} else {
|
||||
value
|
||||
}),
|
||||
},
|
||||
Vector::new(
|
||||
((text_value_width + 5.0) - text_bounds.width).max(0.0)
|
||||
as u32,
|
||||
0,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
(value, Vector::new(0, 0))
|
||||
};
|
||||
|
||||
let contents = Primitive::Clip {
|
||||
bounds: text_bounds,
|
||||
offset,
|
||||
content: Box::new(contents_primitive),
|
||||
};
|
||||
|
||||
(
|
||||
Primitive::Group {
|
||||
primitives: vec![border, input, content],
|
||||
primitives: vec![border, input, contents],
|
||||
},
|
||||
if is_mouse_over {
|
||||
MouseCursor::Text
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue