Make BorrowedWithFontSystem borrow FontSystem mutably

This commit is contained in:
Edgar Geier 2023-03-12 10:30:09 +01:00
parent 057b5b6fa9
commit 46e9ef0246
No known key found for this signature in database
GPG key ID: DE2B55319457EB56
11 changed files with 37 additions and 31 deletions

View file

@ -1,21 +1,20 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
use cosmic_text::{Action, Buffer, Color, Edit, Editor, FontSystem, Metrics, SwashCache};
use cosmic_text::{
Action, BorrowedWithFontSystem, Buffer, Color, Edit, Editor, FontSystem, Metrics, SwashCache,
};
use orbclient::{EventOption, Renderer, Window, WindowFlag};
use std::{env, fs, process, time::Instant};
use unicode_segmentation::UnicodeSegmentation;
fn redraw(
window: &mut Window,
editor: &mut Editor,
font_system: &FontSystem,
editor: &mut BorrowedWithFontSystem<Editor>,
swash_cache: &mut SwashCache,
) {
let bg_color = orbclient::Color::rgb(0x34, 0x34, 0x34);
let font_color = Color::rgb(0xFF, 0xFF, 0xFF);
let mut editor = editor.borrow_with(font_system);
editor.shape_as_needed();
if editor.buffer().redraw() {
let instant = Instant::now();
@ -39,7 +38,7 @@ fn main() {
env_logger::init();
let display_scale = 1.0;
let font_system = FontSystem::new();
let mut font_system = FontSystem::new();
let mut window = Window::new_flags(
-1,
@ -63,12 +62,12 @@ fn main() {
let mut buffer = Buffer::new(&font_system, font_sizes[font_size_default]);
buffer
.borrow_with(&font_system)
.borrow_with(&mut font_system)
.set_size(window.width() as f32, window.height() as f32);
let mut editor = Editor::new(buffer);
let mut editor = editor.borrow_with(&font_system);
let mut editor = editor.borrow_with(&mut font_system);
let mut swash_cache = SwashCache::new();
@ -139,7 +138,7 @@ fn main() {
// Finally, normal enter
editor.action(Action::Enter);
redraw(&mut window, &mut editor, &font_system, &mut swash_cache);
redraw(&mut window, &mut editor, &mut swash_cache);
for event in window.events() {
if let EventOption::Quit(_) = event.to_option() {