fix split bug on single windows and elide titles
This commit is contained in:
parent
7f71a6556b
commit
c555593ae2
8 changed files with 207 additions and 145 deletions
87
src/text.rs
87
src/text.rs
|
|
@ -92,6 +92,23 @@ impl<'a> Config<'a> {
|
|||
markup,
|
||||
scale,
|
||||
},
|
||||
Config::RenderFittingOrEllipsized {
|
||||
height,
|
||||
max_width,
|
||||
font,
|
||||
text,
|
||||
color,
|
||||
markup,
|
||||
scale,
|
||||
} => Config::RenderFittingOrEllipsized {
|
||||
height,
|
||||
max_width,
|
||||
font,
|
||||
text: text.into_owned().into(),
|
||||
color,
|
||||
markup,
|
||||
scale,
|
||||
},
|
||||
Config::Render {
|
||||
x,
|
||||
y,
|
||||
|
|
@ -262,6 +279,26 @@ fn render_fitting(
|
|||
)
|
||||
}
|
||||
|
||||
fn render_fitting_or_ellipsized(
|
||||
memfd: &Memfd,
|
||||
height: Option<i32>,
|
||||
max_width: i32,
|
||||
font: &str,
|
||||
text: &str,
|
||||
color: Color,
|
||||
markup: bool,
|
||||
scale: Option<f64>,
|
||||
) -> Result<RenderedText, TextError> {
|
||||
let measurement = measure(memfd, font, text, markup, scale)?;
|
||||
if measurement.ink_rect.width() <= max_width {
|
||||
return render_fitting(memfd, height, font, text, color, markup, scale);
|
||||
}
|
||||
let height = height.unwrap_or(measurement.ink_rect.height());
|
||||
render(
|
||||
memfd, 0, None, max_width, height, 0, font, text, color, true, markup, scale,
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Default)]
|
||||
pub struct TextMeasurement {
|
||||
pub ink_rect: Rect,
|
||||
|
|
@ -303,6 +340,24 @@ impl RenderWork {
|
|||
markup,
|
||||
scale,
|
||||
} => render_fitting(&self.memfd, height, font, text, color, markup, scale),
|
||||
Config::RenderFittingOrEllipsized {
|
||||
height,
|
||||
max_width,
|
||||
ref font,
|
||||
ref text,
|
||||
color,
|
||||
markup,
|
||||
scale,
|
||||
} => render_fitting_or_ellipsized(
|
||||
&self.memfd,
|
||||
height,
|
||||
max_width,
|
||||
font,
|
||||
text,
|
||||
color,
|
||||
markup,
|
||||
scale,
|
||||
),
|
||||
Config::Render {
|
||||
x,
|
||||
y,
|
||||
|
|
@ -428,6 +483,15 @@ enum Config<'a> {
|
|||
markup: bool,
|
||||
scale: Option<f64>,
|
||||
},
|
||||
RenderFittingOrEllipsized {
|
||||
height: Option<i32>,
|
||||
max_width: i32,
|
||||
font: Arc<String>,
|
||||
text: Cow<'a, str>,
|
||||
color: Color,
|
||||
markup: bool,
|
||||
scale: Option<f64>,
|
||||
},
|
||||
Render {
|
||||
x: i32,
|
||||
y: Option<i32>,
|
||||
|
|
@ -573,6 +637,29 @@ impl TextTexture {
|
|||
self.apply_config(on_completed, config)
|
||||
}
|
||||
|
||||
pub fn schedule_render_fitting_or_ellipsized(
|
||||
&self,
|
||||
on_completed: Rc<dyn OnCompleted>,
|
||||
height: Option<i32>,
|
||||
max_width: i32,
|
||||
font: &Arc<String>,
|
||||
text: &str,
|
||||
color: Color,
|
||||
markup: bool,
|
||||
scale: Option<f64>,
|
||||
) {
|
||||
let config = Config::RenderFittingOrEllipsized {
|
||||
height,
|
||||
max_width,
|
||||
font: font.clone(),
|
||||
text: text.into(),
|
||||
color,
|
||||
markup,
|
||||
scale,
|
||||
};
|
||||
self.apply_config(on_completed, config)
|
||||
}
|
||||
|
||||
pub fn flip(&self) -> Result<(), TextError> {
|
||||
let res = self
|
||||
.data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue