From 99ae0d1beecfd824b62a3735a3c5c30ed78c75b0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 26 Oct 2022 18:05:38 -0600 Subject: [PATCH] Scale rich-text and syntax examples --- examples/rich-text/src/main.rs | 21 ++++++++++++++++----- examples/syntax/src/main.rs | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/examples/rich-text/src/main.rs b/examples/rich-text/src/main.rs index b8bb5af..26a4ddf 100644 --- a/examples/rich-text/src/main.rs +++ b/examples/rich-text/src/main.rs @@ -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( diff --git a/examples/syntax/src/main.rs b/examples/syntax/src/main.rs index 4eb4be9..0956268 100644 --- a/examples/syntax/src/main.rs +++ b/examples/syntax/src/main.rs @@ -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(