v1.2.2: text measuring improvements, minor code clean

fixed some clippy warnings, ignored many that I do not care about. also, added demo video and updated koxinga image
This commit is contained in:
stjet
2025-09-28 04:39:41 +00:00
parent 10daa9982b
commit 40f6795163
24 changed files with 173 additions and 119 deletions

View File

@@ -53,7 +53,7 @@ impl WindowLike for DesktopBackground {
}
} else if line.len() > 1 {
//first character of line is either r or any other character, but is not part of the path
return vec![DrawInstructions::Bmp([0, 0], line[1..].to_string(), line.chars().next().unwrap() == 'r')];
return vec![DrawInstructions::Bmp([0, 0], line[1..].to_string(), line.starts_with('r'))];
}
}
}

View File

@@ -6,7 +6,7 @@ use ming_wm_lib::window_manager_types::{ DrawInstructions, WindowLike, WindowLik
use ming_wm_lib::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest, ShortcutType, InfoType, WindowsVec };
use ming_wm_lib::framebuffer_types::Dimensions;
use ming_wm_lib::themes::ThemeInfo;
use ming_wm_lib::fonts::measure_text;
use ming_wm_lib::utils::trunc_words;
use ming_wm_lib::components::Component;
use ming_wm_lib::components::toggle_button::ToggleButton;
@@ -80,24 +80,7 @@ impl WindowLike for Taskbar {
}
let info = &self.windows_in_workspace[wi];
let max_text_width = META_WIDTH - PADDING * 2;
//horiz_spacing is by default 1 per char, which measure_text doesn't take into account
let to_measure = info.1.clone();
let to_measure_len = to_measure.chars().count();
let name = if measure_text(&["nimbus-roman".to_string()], to_measure).width + to_measure_len > max_text_width {
let mut current = String::new();
for c in info.1.chars() {
//horiz_spacing is 1 by default
let to_measure = current.clone() + &c.to_string() + "...";
let to_measure_len = to_measure.chars().count();
if measure_text(&["nimbus-roman".to_string()], to_measure).width + to_measure_len > max_text_width {
break;
}
current += &c.to_string();
}
current + "..."
} else {
info.1.clone()
};
let name = trunc_words(&["nimbus-roman".to_string()], info.1.clone(), None, max_text_width);
let mut b = ToggleButton::new(name.to_string() + "-window", [PADDING * 2 + 44 + (META_WIDTH + PADDING) * wi, PADDING], [META_WIDTH, self.dimensions[1] - (PADDING * 2)], name.to_string(), TaskbarMessage::Nothing, TaskbarMessage::Nothing);
b.inverted = info.0 == self.focused_id;
instructions.extend(b.draw(theme_info));

View File

@@ -133,10 +133,8 @@ impl FramebufferWriter {
for row in 0..char_info.height {
start_pos = ((top_left[1] + row + char_info.top_offset as usize) * self.info.stride + top_left[0]) * self.info.bytes_per_pixel;
for col in &char_info.data[row] {
if col > &0 {
if start_pos + 3 < self.info.byte_len {
self._draw_pixel(start_pos, color_with_alpha(color, bg_color, *col));
}
if col > &0 && start_pos + 3 < self.info.byte_len {
self._draw_pixel(start_pos, color_with_alpha(color, bg_color, *col));
}
start_pos += self.info.bytes_per_pixel;
}

View File

@@ -88,7 +88,7 @@ impl ProxyWindowLike {
if let Some(buffer) = buffer.stdout.as_mut() {
let mut output = String::new();
let mut reader = BufReader::new(buffer);
if let Ok(_) = reader.read_line(&mut output) {
if reader.read_line(&mut output).is_ok() {
output
} else {
String::new()

View File

@@ -6,11 +6,12 @@ use std::boxed::Box;
use std::cell::RefCell;
use std::fs::File;
use std::io::Read;
use std::str::FromStr;
use linux::fb::Framebuffer;
use ming_wm_lib::framebuffer_types::{ Point, Dimensions };
use ming_wm_lib::themes::{ Themes, get_theme_info };
use ming_wm_lib::utils::{ min, point_inside };
use ming_wm_lib::utils::{ min, point_inside, trunc_words };
use ming_wm_lib::messages::*;
use ming_wm_lib::dirs::config_dir;
use ming_wm_lib::window_manager_types::*;
@@ -168,8 +169,9 @@ impl WindowManager {
//if off_only is true, also handle request
//written confusingly but it works I promise
fn toggle_start_menu(&mut self, off_only: bool) -> WindowMessageResponse {
let start_menu_exists = self.window_infos.iter().find(|w| w.window_like.subtype() == WindowLikeType::StartMenu).is_some();
if (start_menu_exists && off_only) || !off_only {
let start_menu_exists = self.window_infos.iter().any(|w| w.window_like.subtype() == WindowLikeType::StartMenu);
//if (start_menu_exists && off_only) || !off_only {
if start_menu_exists || !off_only {
let taskbar_index = self.window_infos.iter().position(|w| w.window_like.subtype() == WindowLikeType::Taskbar).unwrap();
self.focused_id = self.window_infos[taskbar_index].id;
if off_only {
@@ -710,13 +712,15 @@ impl WindowManager {
//draw window background
instructions.push_front(DrawInstructions::Rect([0, 0], window_dimensions, theme_info.background));
//draw window top decorations and what not
let title = trunc_words(&["nimbus-roman".to_string()], window_info.window_like.title(), None, window_dimensions[0]);
instructions.extend(vec![
//left top border
DrawInstructions::Rect([0, 0], [window_dimensions[0], 1], theme_info.border_left_top),
DrawInstructions::Rect([0, 0], [1, window_dimensions[1]], theme_info.border_left_top),
//top
DrawInstructions::Rect([1, 1], [window_dimensions[0] - 2, WINDOW_TOP_HEIGHT - 3], theme_info.top),
DrawInstructions::Text([4, 4], vec!["nimbus-roman".to_string()], window_info.window_like.title().to_string(), theme_info.top_text, theme_info.top, None, None),
//window title
DrawInstructions::Text([4, 4], vec!["nimbus-roman".to_string()], title, theme_info.top_text, theme_info.top, None, None),
//top bottom border
DrawInstructions::Rect([1, WINDOW_TOP_HEIGHT - 2], [window_dimensions[0] - 2, 2], theme_info.border_left_top),
//right bottom border