Skip to content

Commit

Permalink
Fixes for last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Dec 19, 2023
1 parent f05f658 commit d074817
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ouroboros = "0.17"
palette = "0.7"
qrcode = { version = "0.12", default-features = false }
raw-window-handle = "0.5"
resvg = "0.36"
resvg = "0.37"
rustc-hash = "1.0"
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "2e9bf9f" }
smol = "1.0"
Expand Down
25 changes: 12 additions & 13 deletions graphics/src/text/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ impl Editor {
Self::default()
}

/// Runs a closure with the buffer of the [`Editor`].
pub fn with_buffer<F: FnOnce(&cosmic_text::Buffer) -> T, T>(
&self,
f: F,
) -> T {
self.internal().editor.with_buffer(f)
/// Returns the buffer of the [`Editor`].
pub fn buffer(&self) -> &cosmic_text::Buffer {
match self.internal().editor.buffer_ref() {
cosmic_text::BufferRef::Owned(buffer) => buffer,
cosmic_text::BufferRef::Borrowed(buffer) => buffer,
cosmic_text::BufferRef::Arc(buffer) => buffer,
}
}

/// Creates a [`Weak`] reference to the [`Editor`].
Expand Down Expand Up @@ -86,16 +87,14 @@ impl editor::Editor for Editor {
}

fn line(&self, index: usize) -> Option<&str> {
let buffer = match self.internal().editor.buffer_ref() {
cosmic_text::BufferRef::Owned(buffer) => buffer,
cosmic_text::BufferRef::Borrowed(buffer) => buffer,
cosmic_text::BufferRef::Arc(buffer) => buffer,
};
buffer.lines.get(index).map(cosmic_text::BufferLine::text)
self.buffer()
.lines
.get(index)
.map(cosmic_text::BufferLine::text)
}

fn line_count(&self) -> usize {
self.with_buffer(|buffer| buffer.lines.len())
self.buffer().lines.len()
}

fn selection(&self) -> Option<String> {
Expand Down
26 changes: 12 additions & 14 deletions tiny_skia/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,18 @@ impl Pipeline {

let mut font_system = font_system().write().expect("Write font system");

editor.with_buffer(|buffer| {
draw(
font_system.raw(),
&mut self.glyph_cache,
buffer,
Rectangle::new(position, editor.bounds()),
color,
alignment::Horizontal::Left,
alignment::Vertical::Top,
scale_factor,
pixels,
clip_mask,
);
});
draw(
font_system.raw(),
&mut self.glyph_cache,
editor.buffer(),
Rectangle::new(position, editor.bounds()),
color,
alignment::Horizontal::Left,
alignment::Vertical::Top,
scale_factor,
pixels,
clip_mask,
);
}

pub fn draw_cached(
Expand Down

0 comments on commit d074817

Please sign in to comment.