Fix broken text vis layout (#7532)

This commit is contained in:
Michael Mauderer 2023-08-14 16:31:42 +01:00 committed by GitHub
parent f1c8c0b42b
commit 1272486a00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View File

@ -215,8 +215,6 @@ impl<T: TextProvider + 'static> TextGrid<T> {
let frp = visualization::instance::Frp::new(&network);
let model = Rc::new(Model::new(app));
let fonts_loaded_notifier = FontLoadedNotifier::new(&network);
Self { model, frp, network, fonts_loaded_notifier }
}
@ -235,13 +233,14 @@ impl<T: TextProvider + 'static> TextGrid<T> {
self.init_text_grid_api(&init, &on_data_update);
self.init_scrolling(&init, text_provider, &on_data_update);
self.init_style(&init);
self.init_style(&init, &on_data_update);
init.emit(());
}
fn init_style(&self, init: &frp::Source) {
fn init_style(&self, init: &frp::Source, on_data_update: &frp::Stream) {
let init = init.clone_ref();
let on_data_update = on_data_update.clone_ref();
let scene = &self.model.app.display.default_scene;
let style_watch = StyleWatchFrp::new(&scene.style_sheet);
@ -267,9 +266,16 @@ impl<T: TextProvider + 'static> TextGrid<T> {
grid_view_entry::Params { parent }
})
);
item_width_update <- all(init, fonts_loaded, font_name, font_size);
item_width <- item_width_update.map(f!([]((_, _, font_name, font_size)) {
// In order for the layout to be correct, we need to ensure that we know the correct
// width of a rendered chunk. That means we have to update our measurement, when the
// font family or size change, but also when we update the text. While it seems that
// the font properties alone should be enough to ensure the chunk width does not
// change, that is incorrect. The text might be rendered differently because of
// external changes (e.g., which fonts are loaded). Tracking these is difficult
// and thus we need to just measure before we set new text.
item_width_update <- all5(&init, &on_data_update, &fonts_loaded, &font_name,
&font_size);
item_width <- item_width_update.map(f!([]((_, _, _, font_name, font_size)) {
let font_size = *font_size;
let char_width = measure_character_width(font_name, font_size);
CHARS_PER_CHUNK as f32 * char_width
@ -291,7 +297,6 @@ impl<T: TextProvider + 'static> TextGrid<T> {
frp::extend! { network
text_grid.request_model_for_visible_entries <+ any(on_data_update,init);
requested_entry <- text_grid.model_for_entry_needed.map2(&text_grid.grid_size,
f!([model]((row, col), _grid_size) {
let text = model.get_string_for_cell(*row,*col);

View File

@ -78,10 +78,6 @@ impl Entry {
let mut style = "position: absolute; white-space: pre; pointer-events: auto;".to_string();
write!(style, "left: {left}px; top: {top}px;").ok();
write!(style, "width: {width}px; height: {height}px;").ok();
// This prevents a fallback font from being used. Using any other font than the one
// specified will break the layout mechanism because the calculated width of the chunks no
// longer matches the rendered width of the chunks.
write!(style, "font-display: block;").ok();
// The default line height in browsers is 1.2, which is great for multi-line text and
// elements whose height is greater than the line height. In this case, however, where the
// height and the font size are set to the same value, the default setting of 1.2 pushes