Scale rich-text and syntax examples

This commit is contained in:
Jeremy Soller 2022-10-26 18:05:38 -06:00
parent 39b7bef5cc
commit 99ae0d1bee
No known key found for this signature in database
GPG key ID: E988B49EE78A7FB1
2 changed files with 30 additions and 8 deletions

View file

@ -1,20 +1,31 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
use cosmic_text::{Attrs, Color, Family, FontSystem, Style, SwashCache,
use cosmic_text::{Color, Family, FontSystem, Style, SwashCache,
TextAction, TextBuffer, TextBufferLine, TextMetrics, Weight};
use orbclient::{EventOption, Renderer, Window, WindowFlag};
use std::{env, fs, process, thread, time::{Duration, Instant}};
use std::{process, thread, time::{Duration, Instant}};
fn main() {
env_logger::init();
let font_system = FontSystem::new();
let display_scale = match orbclient::get_display_size() {
Ok((w, h)) => {
log::info!("Display size: {}, {}", w, h);
(h as i32 / 1600) + 1
}
Err(err) => {
log::warn!("Failed to get display size: {}", err);
1
}
};
let mut window = Window::new_flags(
-1,
-1,
1024,
768,
1024 * display_scale as u32,
768 * display_scale as u32,
&format!("COSMIC TEXT - {}", font_system.locale),
&[WindowFlag::Resizable],
)
@ -24,7 +35,7 @@ fn main() {
let mut buffer = TextBuffer::new(
&font_system,
attrs,
TextMetrics::new(32, 44)
TextMetrics::new(32, 44).scale(display_scale)
);
buffer.set_size(

View file

@ -16,11 +16,22 @@ fn main() {
String::new()
};
let display_scale = match orbclient::get_display_size() {
Ok((w, h)) => {
log::info!("Display size: {}, {}", w, h);
(h as i32 / 1600) + 1
}
Err(err) => {
log::warn!("Failed to get display size: {}", err);
1
}
};
let mut window = Window::new_flags(
-1,
-1,
1024,
768,
1024 * display_scale as u32,
768 * display_scale as u32,
&format!("COSMIC TEXT - {}", font_system.locale),
&[WindowFlag::Resizable],
)
@ -32,7 +43,7 @@ fn main() {
let mut buffer = TextBuffer::new(
&font_system,
attrs,
TextMetrics::new(14, 20)
TextMetrics::new(14, 20).scale(display_scale)
);
buffer.set_size(