Skip to content

Commit

Permalink
chore: update glyphon to 0.3 (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin271 committed Jan 20, 2024
1 parent db8cd76 commit 46caaa3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 107 deletions.
124 changes: 48 additions & 76 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ human-panic = "1.2.2"
notify-debouncer-full = { version = "0.3.1", default-features = false }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }

[dependencies.glyphon]
version = "0.2"
git = "https://github.com/trimental/glyphon"
rev = "5bf8b6b6aa4a181824798836e1436809e78102e7"
glyphon = "0.3"

[profile.release]
strip = true
Expand Down
34 changes: 14 additions & 20 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::text::{CachedTextArea, TextCache, TextSystem};
use crate::utils::{Point, Rect, Selection, Size};
use crate::Element;

use anyhow::{anyhow, Context, Ok};
use anyhow::{Context, Ok};
use bytemuck::{Pod, Zeroable};
use glyphon::{PrepareError, Resolution, SwashCache, TextArea, TextAtlas, TextRenderer};
use glyphon::{Resolution, SwashCache, TextArea, TextAtlas, TextRenderer};
use lyon::geom::euclid::Point2D;
use lyon::geom::Box2D;
use lyon::path::Polygon;
Expand Down Expand Up @@ -757,24 +757,18 @@ impl Renderer {
.map(|c| c.text_area(&text_cache))
.collect();

while let Result::Err(PrepareError::AtlasFull(content_type)) =
self.text_system.text_renderer.prepare(
&self.device,
&self.queue,
&mut self.text_system.font_system.lock().unwrap(),
&mut self.text_system.text_atlas,
Resolution {
width: self.config.width,
height: self.config.height,
},
&text_areas,
&mut self.text_system.swash_cache,
)
{
if !self.text_system.text_atlas.grow(&self.device, content_type) {
return Err(anyhow!("Could not grow text atlas"));
}
}
self.text_system.text_renderer.prepare(
&self.device,
&self.queue,
&mut self.text_system.font_system.lock().unwrap(),
&mut self.text_system.text_atlas,
Resolution {
width: self.config.width,
height: self.config.height,
},
text_areas,
&mut self.text_system.swash_cache,
)?;
text_cache.trim();
}

Expand Down
13 changes: 7 additions & 6 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::utils::{Align, Line, Point, Rect, Selection, Size};

use fxhash::{FxHashMap, FxHashSet};
use glyphon::{
Affinity, Attrs, AttrsList, BufferLine, Color, Cursor, FamilyOwned, FontSystem, Style,
Affinity, Attrs, AttrsList, BufferLine, Color, Cursor, FamilyOwned, FontSystem, Shaping, Style,
SwashCache, TextArea, TextBounds, Weight,
};
use smart_debug::SmartDebug;
Expand Down Expand Up @@ -93,8 +93,8 @@ impl Default for TextBox {

pub struct CachedTextArea {
key: KeyHash,
left: i32,
top: i32,
left: f32,
top: f32,
bounds: TextBounds,
default_color: Color,
}
Expand All @@ -107,6 +107,7 @@ impl CachedTextArea {
top: self.top,
bounds: self.bounds,
default_color: self.default_color,
scale: 1.,
}
}
}
Expand Down Expand Up @@ -282,8 +283,8 @@ impl TextBox {

CachedTextArea {
key,
left: left as i32,
top: (screen_position.1 - scroll_y) as i32,
left,
top: (screen_position.1 - scroll_y),
bounds: TextBounds::default(),
default_color: Color::rgb(255, 255, 255),
}
Expand Down Expand Up @@ -651,7 +652,7 @@ impl TextCache {
.metadata(section.index),
)
}
let buffer_line = BufferLine::new(line_str, attrs_list);
let buffer_line = BufferLine::new(line_str, attrs_list, Shaping::Advanced);
buffer.lines.push(buffer_line);
}

Expand Down

0 comments on commit 46caaa3

Please sign in to comment.