diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b159f2..e0e2a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,18 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 _Changes in the next release_ +### Fixed +- Misplaced text sensors in custom panels (#11). + ### Added -- Simple sensor panel with a file-based data source (#6) -- Initial support for fan-, progress-, & pointer-sensors (#8) -- Use [mdBook](https://rust-lang.github.io/mdBook/) for documentation and publish user guide to GitHub pages (#10) +- Simple sensor panel with a file-based data source (#6). +- Initial support for fan-, progress-, & pointer-sensors (#8). +- Use [mdBook](https://rust-lang.github.io/mdBook/) for documentation and publish user guide to GitHub pages (#10). ### Changed -- Project structure using a Cargo workspace +- Project structure using a Cargo workspace. --- ## v0.1.0 - 2025-08-02 ### Added -- Initial `asterctl` tool release for controlling the LCD: on, off, display an image +- Initial `asterctl` tool release for controlling the LCD: on, off, display an image. - systemd service file to switch off LCD on system start. -- Demo mode +- Demo mode. diff --git a/crates/asterctl/src/render.rs b/crates/asterctl/src/render.rs index 86c310a..4c29bfb 100644 --- a/crates/asterctl/src/render.rs +++ b/crates/asterctl/src/render.rs @@ -212,8 +212,10 @@ impl PanelRenderer { }; let font_size = sensor.font_size.unwrap_or(14) as f32; // TODO verify pixel scaling! Is font_size point size or pixel size? - // This is still a bit off compared to the original AOOSTAR-X. Only tested with HarmonyOS_Sans_SC_Bold! - let adjustment_hack = 0.7; + // TODO some font size calculation is missing, dpi scaling? internal padding? + // The adjustment hack is required to get the correct size of the rendered text. + // However, the y-position requires the regular value (see multiplication by 1.33 below) + let adjustment_hack = 0.75; let scale = font.pt_to_px_scale(font_size * adjustment_hack).unwrap(); let text = format_value( @@ -223,14 +225,19 @@ impl PanelRenderer { unit, ); let size = text_size(scale, &font, &text); - // TODO verify x & y-coordinate handling + let width = sensor.width.unwrap_or_default() as i32; + let height = sensor.height.unwrap_or_default() as i32; let x = match sensor.text_align.unwrap_or_default() { TextAlign::Left => sensor.x, - TextAlign::Center => sensor.x - (size.0 / 2) as i32, - TextAlign::Right => sensor.x - size.0 as i32, + TextAlign::Center => sensor.x + width / 2 - (size.0 / 2) as i32, + TextAlign::Right => sensor.x + width - size.0 as i32, }; - let y = (sensor.y as f32 - scale.y / 2f32) as i32; - // let y = sensor.y as i32 - (size.1 / 2) as i32; + // FIXME figure out font scaling factor / padding / dpi etc. See above for y-adjustment hack. + // This work quite ok for most panels, but not all! + // Some work better with `sensor.y + height / 2 - size.1 as i32;` + // The y parameter in `draw_text_mut` is still a mystery: drawing text at position (0,0) + // renders a huge gap at the top, about the size of half the font-height!? + let y = sensor.y + height / 2 - (size.1 as f32 * 1.3333 / 2f32) as i32; debug!( "Sensor({:03},{:03}), pixel({x:03},{y:03}), size{size:?}: {text}",