Wrap native text within occurrence constraints and preserve paint bounds
Verify Tessera GUI / verify (push) Failing after 7m33s
Verify Tessera GUI / verify (push) Failing after 7m33s
This commit is contained in:
+29
-11
@@ -18,7 +18,7 @@ pub struct Size {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
enum Shape {
|
||||
Text(String, u32),
|
||||
Text(String, u32, f32),
|
||||
Rect(f32, f32),
|
||||
Container(bool, f32, f32, Vec<Size>),
|
||||
}
|
||||
@@ -103,11 +103,13 @@ fn container(node: &UiNode) -> Option<(bool, f32, f32)> {
|
||||
|
||||
fn measure_shape(shape: &Shape) -> Result<Size> {
|
||||
let size = match shape {
|
||||
Shape::Text(value, size) => {
|
||||
let result = text::measure(value, TextStyle::ui(*size));
|
||||
Shape::Text(value, size, width) => {
|
||||
let style = TextStyle::ui(*size);
|
||||
let intrinsic = text::measure(value, style);
|
||||
let wrapped = text::measure_wrapped(value, style, *width);
|
||||
Size {
|
||||
width: result.width,
|
||||
height: result.height,
|
||||
width: intrinsic.width.min(*width),
|
||||
height: wrapped.height,
|
||||
}
|
||||
}
|
||||
Shape::Rect(width, height) => Size {
|
||||
@@ -144,9 +146,9 @@ fn measure_shape(shape: &Shape) -> Result<Size> {
|
||||
Ok(size)
|
||||
}
|
||||
|
||||
fn shape(node: &UiNode, children: Vec<Size>) -> Result<Shape> {
|
||||
fn shape(node: &UiNode, children: Vec<Size>, constraints: [f32; 4]) -> Result<Shape> {
|
||||
Ok(match &node.kind {
|
||||
UiKind::Text { value, size, .. } => Shape::Text(value.clone(), *size),
|
||||
UiKind::Text { value, size, .. } => Shape::Text(value.clone(), *size, constraints[2]),
|
||||
UiKind::Rect { width, height, .. } => Shape::Rect(*width, *height),
|
||||
UiKind::Spacer(size) => Shape::Rect(*size, *size),
|
||||
UiKind::Scroll { width, height, .. } => Shape::Rect(*width, *height),
|
||||
@@ -157,8 +159,8 @@ fn shape(node: &UiNode, children: Vec<Size>) -> Result<Shape> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn measure_native(node: &UiNode, children: Vec<Size>) -> Result<Size> {
|
||||
measure_shape(&shape(node, children)?)
|
||||
pub fn measure_native(node: &UiNode, children: Vec<Size>, constraints: [f32; 4]) -> Result<Size> {
|
||||
measure_shape(&shape(node, children, constraints)?)
|
||||
}
|
||||
|
||||
/// Private derived scratch space for one occurrence during layout. Contains no
|
||||
@@ -171,6 +173,7 @@ pub struct Context {
|
||||
}
|
||||
|
||||
pub fn paint_native(node: &UiNode, x: f32, y: f32, size: Size) -> Option<RenderCommand> {
|
||||
let size_for_text = size;
|
||||
match &node.kind {
|
||||
UiKind::Text { value, size, color } => Some(RenderCommand::Text {
|
||||
x,
|
||||
@@ -178,6 +181,7 @@ pub fn paint_native(node: &UiNode, x: f32, y: f32, size: Size) -> Option<RenderC
|
||||
value: value.clone(),
|
||||
size: *size,
|
||||
color: color.clone(),
|
||||
wrap_bounds: Some([size_for_text.width, size_for_text.height]),
|
||||
}),
|
||||
UiKind::Rect { radius, color, .. } => Some(RenderCommand::RoundedRect {
|
||||
x,
|
||||
@@ -253,8 +257,13 @@ impl LayoutRuntime {
|
||||
Ok(frame)
|
||||
}
|
||||
|
||||
pub fn measure_node(&mut self, node: &UiNode, children: Vec<Size>) -> Result<Size> {
|
||||
let shape = shape(node, children)?;
|
||||
pub fn measure_node(
|
||||
&mut self,
|
||||
node: &UiNode,
|
||||
children: Vec<Size>,
|
||||
constraints: [f32; 4],
|
||||
) -> Result<Size> {
|
||||
let shape = shape(node, children, constraints)?;
|
||||
if let Some((_, size)) = self
|
||||
.sizes
|
||||
.get(&node.block_id)
|
||||
@@ -326,6 +335,7 @@ impl LayoutRuntime {
|
||||
self.measure_node(
|
||||
item.node,
|
||||
item.children.iter().map(|i| sizes[*i]).collect(),
|
||||
item.constraints,
|
||||
)?,
|
||||
item.constraints,
|
||||
);
|
||||
@@ -400,3 +410,11 @@ impl LayoutRuntime {
|
||||
pub fn frame(root: &UiNode) -> Result<Frame> {
|
||||
LayoutRuntime::default().frame(root)
|
||||
}
|
||||
|
||||
pub fn frame_with_viewport(root: &UiNode, viewport: Size) -> Result<Frame> {
|
||||
LayoutRuntime {
|
||||
viewport: Some(viewport),
|
||||
..Default::default()
|
||||
}
|
||||
.frame(root)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user