mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-31 15:47:26 +00:00
Update to FemtoVG 4.0
Not big changes, just API and Cargo feature cleanups
This commit is contained in:
parent
fb09dc5c1d
commit
04ceb63433
4 changed files with 39 additions and 40 deletions
|
@ -50,7 +50,7 @@ raw-window-handle = { version = "0.5", features = ["alloc"] }
|
|||
scopeguard = { version = "1.1.0", default-features = false }
|
||||
|
||||
# For the FemtoVG renderer
|
||||
femtovg = { version = "0.3.7", optional = true, default-features = false, features = ["image-loading"] }
|
||||
femtovg = { version = "0.4.0", optional = true }
|
||||
fontdb = { version = "0.10.0", optional = true, default-features = false }
|
||||
ttf-parser = { version = "0.17.0", optional = true } # Use the same version was femtovg's rustybuzz, to avoid duplicate crates
|
||||
unicode-script = { version = "0.5.4", optional = true } # Use the same version was femtovg's rustybuzz, to avoid duplicate crates
|
||||
|
|
|
@ -70,9 +70,8 @@ impl super::WinitCompatibleRenderer for FemtoVGRenderer {
|
|||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let gl_renderer = unsafe {
|
||||
// TODO: use new_from_function_cstr with new FemtoVG release
|
||||
femtovg::renderer::OpenGl::new_from_function(|s| {
|
||||
opengl_context.get_proc_address(&std::ffi::CString::new(s).unwrap()) as *const _
|
||||
femtovg::renderer::OpenGl::new_from_function_cstr(|s| {
|
||||
opengl_context.get_proc_address(s) as *const _
|
||||
})
|
||||
.unwrap()
|
||||
};
|
||||
|
@ -308,7 +307,7 @@ impl Renderer for FemtoVGRenderer {
|
|||
let paint = font.init_paint(text_input.letter_spacing() * scale_factor, Default::default());
|
||||
let text_context = crate::renderer::femtovg::fonts::FONT_CACHE
|
||||
.with(|cache| cache.borrow().text_context.clone());
|
||||
let font_height = text_context.measure_font(paint).unwrap().height();
|
||||
let font_height = text_context.measure_font(&paint).unwrap().height();
|
||||
crate::renderer::femtovg::fonts::layout_text_lines(
|
||||
actual_text,
|
||||
&font,
|
||||
|
@ -317,7 +316,7 @@ impl Renderer for FemtoVGRenderer {
|
|||
text_input.wrap(),
|
||||
i_slint_core::items::TextOverflow::Clip,
|
||||
text_input.single_line(),
|
||||
paint,
|
||||
&paint,
|
||||
|line_text, line_pos, start, metrics| {
|
||||
if (line_pos.y..(line_pos.y + font_height)).contains(&pos.y) {
|
||||
let mut current_x = 0.;
|
||||
|
@ -388,7 +387,7 @@ impl Renderer for FemtoVGRenderer {
|
|||
text_input.wrap(),
|
||||
i_slint_core::items::TextOverflow::Clip,
|
||||
text_input.single_line(),
|
||||
paint,
|
||||
&paint,
|
||||
|line_text, line_pos, start, metrics| {
|
||||
if (start..=(start + line_text.len())).contains(&byte_offset) {
|
||||
for glyph in &metrics.glyphs {
|
||||
|
|
|
@ -99,27 +99,27 @@ impl Font {
|
|||
max_width: Option<PhysicalLength>,
|
||||
) -> PhysicalSize {
|
||||
let paint = self.init_paint(letter_spacing, femtovg::Paint::default());
|
||||
let font_metrics = self.text_context.measure_font(paint).unwrap();
|
||||
let font_metrics = self.text_context.measure_font(&paint).unwrap();
|
||||
let mut lines = 0;
|
||||
let mut width = 0.;
|
||||
let mut start = 0;
|
||||
if let Some(max_width) = max_width {
|
||||
while start < text.len() {
|
||||
let index =
|
||||
self.text_context.break_text(max_width.get(), &text[start..], paint).unwrap();
|
||||
self.text_context.break_text(max_width.get(), &text[start..], &paint).unwrap();
|
||||
if index == 0 {
|
||||
break;
|
||||
}
|
||||
let index = start + index;
|
||||
let measure =
|
||||
self.text_context.measure_text(0., 0., &text[start..index], paint).unwrap();
|
||||
self.text_context.measure_text(0., 0., &text[start..index], &paint).unwrap();
|
||||
start = index;
|
||||
lines += 1;
|
||||
width = measure.width().max(width);
|
||||
}
|
||||
} else {
|
||||
for line in text.lines() {
|
||||
let measure = self.text_context.measure_text(0., 0., line, paint).unwrap();
|
||||
let measure = self.text_context.measure_text(0., 0., line, &paint).unwrap();
|
||||
lines += 1;
|
||||
width = measure.width().max(width);
|
||||
}
|
||||
|
@ -627,7 +627,7 @@ pub(crate) fn layout_text_lines(
|
|||
wrap: TextWrap,
|
||||
overflow: TextOverflow,
|
||||
single_line: bool,
|
||||
paint: femtovg::Paint,
|
||||
paint: &femtovg::Paint,
|
||||
mut layout_line: impl FnMut(&str, PhysicalPoint, usize, &femtovg::TextMetrics),
|
||||
) -> PhysicalLength {
|
||||
let wrap = wrap == TextWrap::WordWrap;
|
||||
|
|
|
@ -176,7 +176,7 @@ impl<'a> GLItemRenderer<'a> {
|
|||
// Since we're filling a straight rectangle with either color or gradient, save
|
||||
// the extra stroke triangle strip around the edges
|
||||
.with_anti_alias(false);
|
||||
self.canvas.borrow_mut().fill_path(&mut path, paint);
|
||||
self.canvas.borrow_mut().fill_path(&mut path, &paint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,12 +250,12 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
|
||||
let mut canvas = self.canvas.borrow_mut();
|
||||
if let Some(paint) = fill_paint {
|
||||
canvas.fill_path(&mut background_path, paint);
|
||||
canvas.fill_path(&mut background_path, &paint);
|
||||
}
|
||||
if let Some(border_paint) = border_paint {
|
||||
canvas.stroke_path(
|
||||
maybe_border_path.as_mut().unwrap_or(&mut background_path),
|
||||
border_paint,
|
||||
&border_paint,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -325,9 +325,9 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
text.wrap(),
|
||||
text.overflow(),
|
||||
false,
|
||||
paint,
|
||||
&paint,
|
||||
|to_draw, pos, _, _| {
|
||||
canvas.fill_text(pos.x, pos.y, to_draw.trim_end(), paint).unwrap();
|
||||
canvas.fill_text(pos.x, pos.y, to_draw.trim_end(), &paint).unwrap();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
};
|
||||
|
||||
let mut canvas = self.canvas.borrow_mut();
|
||||
let font_height = PhysicalLength::new(canvas.measure_font(paint).unwrap().height());
|
||||
let font_height = PhysicalLength::new(canvas.measure_font(&paint).unwrap().height());
|
||||
let mut text: SharedString = visual_representation.text.into();
|
||||
|
||||
if let InputType::Password = text_input.input_type() {
|
||||
|
@ -391,7 +391,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
text_input.wrap(),
|
||||
items::TextOverflow::Clip,
|
||||
text_input.single_line(),
|
||||
paint,
|
||||
&paint,
|
||||
|to_draw, pos, start, metrics| {
|
||||
let range = start..(start + to_draw.len());
|
||||
if min_select != max_select
|
||||
|
@ -436,11 +436,11 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
);
|
||||
canvas.fill_path(
|
||||
&mut rect_to_path(selection_rect),
|
||||
femtovg::Paint::color(to_femtovg_color(
|
||||
&femtovg::Paint::color(to_femtovg_color(
|
||||
&text_input.selection_background_color(),
|
||||
)),
|
||||
);
|
||||
let mut selected_paint = paint;
|
||||
let mut selected_paint = paint.clone();
|
||||
selected_paint
|
||||
.set_color(to_femtovg_color(&text_input.selection_foreground_color()));
|
||||
canvas
|
||||
|
@ -448,7 +448,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
pos.x,
|
||||
pos.y,
|
||||
&to_draw[..min_select.saturating_sub(start)].trim_end(),
|
||||
paint,
|
||||
&paint,
|
||||
)
|
||||
.unwrap();
|
||||
canvas
|
||||
|
@ -458,7 +458,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
&to_draw[min_select.saturating_sub(start)
|
||||
..(max_select - start).min(to_draw.len())]
|
||||
.trim_end(),
|
||||
selected_paint,
|
||||
&selected_paint,
|
||||
)
|
||||
.unwrap();
|
||||
canvas
|
||||
|
@ -466,12 +466,12 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
pos.x + after_selection_x.get(),
|
||||
pos.y,
|
||||
&to_draw[(max_select - start).min(to_draw.len())..].trim_end(),
|
||||
paint,
|
||||
&paint,
|
||||
)
|
||||
.unwrap();
|
||||
} else {
|
||||
// no selection on this line
|
||||
canvas.fill_text(pos.x, pos.y, to_draw.trim_end(), paint).unwrap();
|
||||
canvas.fill_text(pos.x, pos.y, to_draw.trim_end(), &paint).unwrap();
|
||||
};
|
||||
if cursor_visible
|
||||
&& (range.contains(&cursor_pos)
|
||||
|
@ -510,7 +510,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
(text_input.text_cursor_width() * self.scale_factor).get(),
|
||||
font_height.get(),
|
||||
);
|
||||
canvas.fill_path(&mut cursor_rect, paint);
|
||||
canvas.fill_path(&mut cursor_rect, &paint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -611,11 +611,11 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
|
||||
self.canvas.borrow_mut().save_with(|canvas| {
|
||||
canvas.translate(offset.x, offset.y);
|
||||
if let Some(fill_paint) = fill_paint {
|
||||
canvas.fill_path(&mut femtovg_path, fill_paint);
|
||||
if let Some(fill_paint) = &fill_paint {
|
||||
canvas.fill_path(&mut femtovg_path, &fill_paint);
|
||||
}
|
||||
if let Some(border_paint) = border_paint {
|
||||
canvas.stroke_path(&mut femtovg_path, border_paint);
|
||||
if let Some(border_paint) = &border_paint {
|
||||
canvas.stroke_path(&mut femtovg_path, &border_paint);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -689,7 +689,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
);
|
||||
canvas.fill_path(
|
||||
&mut shadow_path,
|
||||
femtovg::Paint::color(femtovg::Color::rgb(255, 255, 255)),
|
||||
&femtovg::Paint::color(femtovg::Color::rgb(255, 255, 255)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -715,7 +715,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
shadow_image_rect.rect(0., 0., shadow_rect.width(), shadow_rect.height());
|
||||
canvas.fill_path(
|
||||
&mut shadow_image_rect,
|
||||
femtovg::Paint::color(to_femtovg_color(&box_shadow.color())),
|
||||
&femtovg::Paint::color(to_femtovg_color(&box_shadow.color())),
|
||||
);
|
||||
|
||||
canvas.restore();
|
||||
|
@ -754,7 +754,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
let offset = LogicalPoint::from_lengths(box_shadow.offset_x(), box_shadow.offset_y())
|
||||
* self.scale_factor;
|
||||
canvas.translate(offset.x - blur.get(), offset.y - blur.get());
|
||||
canvas.fill_path(&mut shadow_image_rect, shadow_image_paint);
|
||||
canvas.fill_path(&mut shadow_image_rect, &shadow_image_paint);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -807,7 +807,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
self.scale_factor,
|
||||
);
|
||||
|
||||
self.canvas.borrow_mut().fill_path(&mut layer_path, layer_image_paint);
|
||||
self.canvas.borrow_mut().fill_path(&mut layer_path, &layer_image_paint);
|
||||
}
|
||||
|
||||
RenderingResult::ContinueRenderingWithoutChildren
|
||||
|
@ -911,7 +911,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
let fill_paint = femtovg::Paint::image(image_id, 0., 0., width, height, 0.0, 1.0);
|
||||
let mut path = femtovg::Path::new();
|
||||
path.rect(0., 0., width, height);
|
||||
canvas.fill_path(&mut path, fill_paint);
|
||||
canvas.fill_path(&mut path, &fill_paint);
|
||||
}
|
||||
|
||||
fn draw_string(&mut self, string: &str, color: Color) {
|
||||
|
@ -920,7 +920,7 @@ impl<'a> ItemRenderer for GLItemRenderer<'a> {
|
|||
let paint = font
|
||||
.init_paint(PhysicalLength::default(), femtovg::Paint::color(to_femtovg_color(&color)));
|
||||
let mut canvas = self.canvas.borrow_mut();
|
||||
canvas.fill_text(0., 0., string, paint).unwrap();
|
||||
canvas.fill_text(0., 0., string, &paint).unwrap();
|
||||
}
|
||||
|
||||
fn window(&self) -> &i_slint_core::api::Window {
|
||||
|
@ -1111,7 +1111,7 @@ impl<'a> GLItemRenderer<'a> {
|
|||
layer_image.as_paint_with_alpha(alpha_tint).with_anti_alias(false);
|
||||
|
||||
layer_path.rect(0., 0., layer_size.width as _, layer_size.height as _);
|
||||
self.canvas.borrow_mut().fill_path(&mut layer_path, layer_image_paint);
|
||||
self.canvas.borrow_mut().fill_path(&mut layer_path, &layer_image_paint);
|
||||
}
|
||||
RenderingResult::ContinueRenderingWithoutChildren
|
||||
}
|
||||
|
@ -1169,7 +1169,7 @@ impl<'a> GLItemRenderer<'a> {
|
|||
canvas.global_composite_operation(femtovg::CompositeOperation::Copy);
|
||||
canvas.fill_path(
|
||||
&mut image_rect,
|
||||
femtovg::Paint::image(
|
||||
&femtovg::Paint::image(
|
||||
image_id,
|
||||
0.,
|
||||
0.,
|
||||
|
@ -1181,7 +1181,7 @@ impl<'a> GLItemRenderer<'a> {
|
|||
);
|
||||
|
||||
canvas.global_composite_operation(femtovg::CompositeOperation::SourceIn);
|
||||
canvas.fill_path(&mut image_rect, brush_paint);
|
||||
canvas.fill_path(&mut image_rect, &brush_paint);
|
||||
|
||||
canvas.set_render_target(self.current_render_target());
|
||||
});
|
||||
|
@ -1342,7 +1342,7 @@ impl<'a> GLItemRenderer<'a> {
|
|||
|
||||
canvas.scale(source_to_target_scale_x, source_to_target_scale_y);
|
||||
|
||||
canvas.fill_path(&mut path, fill_paint);
|
||||
canvas.fill_path(&mut path, &fill_paint);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue