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 // 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}; TextAction, TextBuffer, TextBufferLine, TextMetrics, Weight};
use orbclient::{EventOption, Renderer, Window, WindowFlag}; use orbclient::{EventOption, Renderer, Window, WindowFlag};
use std::{env, fs, process, thread, time::{Duration, Instant}}; use std::{process, thread, time::{Duration, Instant}};
fn main() { fn main() {
env_logger::init(); env_logger::init();
let font_system = FontSystem::new(); 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( let mut window = Window::new_flags(
-1, -1,
-1, -1,
1024, 1024 * display_scale as u32,
768, 768 * display_scale as u32,
&format!("COSMIC TEXT - {}", font_system.locale), &format!("COSMIC TEXT - {}", font_system.locale),
&[WindowFlag::Resizable], &[WindowFlag::Resizable],
) )
@ -24,7 +35,7 @@ fn main() {
let mut buffer = TextBuffer::new( let mut buffer = TextBuffer::new(
&font_system, &font_system,
attrs, attrs,
TextMetrics::new(32, 44) TextMetrics::new(32, 44).scale(display_scale)
); );
buffer.set_size( buffer.set_size(

View file

@ -16,11 +16,22 @@ fn main() {
String::new() 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( let mut window = Window::new_flags(
-1, -1,
-1, -1,
1024, 1024 * display_scale as u32,
768, 768 * display_scale as u32,
&format!("COSMIC TEXT - {}", font_system.locale), &format!("COSMIC TEXT - {}", font_system.locale),
&[WindowFlag::Resizable], &[WindowFlag::Resizable],
) )
@ -32,7 +43,7 @@ fn main() {
let mut buffer = TextBuffer::new( let mut buffer = TextBuffer::new(
&font_system, &font_system,
attrs, attrs,
TextMetrics::new(14, 20) TextMetrics::new(14, 20).scale(display_scale)
); );
buffer.set_size( buffer.set_size(