From dd776d9a8183f52ecdb3775d7e969201c65b0ecc Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Thu, 24 Oct 2024 10:21:49 +0200 Subject: [PATCH] text: Remove line parameter from EditText::layout_metrics After implementing line_metrics, there's no need for a line parameter in layout_metrics. --- core/src/avm1/globals/text_format.rs | 2 +- core/src/display_object/edit_text.rs | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/core/src/avm1/globals/text_format.rs b/core/src/avm1/globals/text_format.rs index 48c1f7d9c3b7..ea8aa53c6a4f 100644 --- a/core/src/avm1/globals/text_format.rs +++ b/core/src/avm1/globals/text_format.rs @@ -497,7 +497,7 @@ fn get_text_extent<'gc>( let result = ScriptObject::new(activation.gc(), None); let metrics = temp_edittext - .layout_metrics(None) + .layout_metrics() .expect("All text boxes should have at least one line at all times"); result.set_data( diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index cc9340be9104..b00cd096e34c 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -31,7 +31,6 @@ use crate::vminterface::{AvmObject, Instantiator}; use chrono::DateTime; use chrono::Utc; use core::fmt; -use either::Either; use gc_arena::{Collect, Gc, GcCell, Mutation}; use ruffle_render::commands::CommandHandler; use ruffle_render::quality::StageQuality; @@ -1912,19 +1911,15 @@ impl<'gc> EditText<'gc> { self.0.read().layout.lines().len() } - /// Calculate the layout metrics for a given line. + /// Calculate the layout metrics. /// - /// Returns `None` if the line does not exist or there is not enough data - /// about the line to calculate metrics with. - pub fn layout_metrics(self, line: Option) -> Option { + /// Returns `None` if there is not enough data + /// about the layout to calculate metrics with. + pub fn layout_metrics(self) -> Option { let layout = &self.0.read().layout; - let line = line.and_then(|line| layout.lines().get(line)); - let (boxes, union_bounds) = if let Some(line) = line { - (Either::Left(line.boxes_iter()), line.interior_bounds()) - } else { - (Either::Right(layout.boxes_iter()), layout.bounds()) - }; + let boxes = layout.boxes_iter(); + let union_bounds = layout.bounds(); let mut first_font = None; let mut first_format = None;