mirror of
https://gitlab.com/cleanflash/installer.git
synced 2026-08-13 10:51:37 +08:00
Implement HiDPI scaling
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::renderer::Renderer;
|
||||
pub struct GradientButton {
|
||||
pub rect: Rect,
|
||||
pub text: String,
|
||||
pub font_size: f32,
|
||||
pub color1: u32,
|
||||
pub color2: u32,
|
||||
pub back_color: u32,
|
||||
@@ -23,6 +24,7 @@ impl GradientButton {
|
||||
Self {
|
||||
rect: Rect::new(x, y, w, h),
|
||||
text: text.to_string(),
|
||||
font_size: 13.0,
|
||||
color1: Renderer::rgb(118, 118, 118),
|
||||
color2: Renderer::rgb(81, 81, 81),
|
||||
back_color: Renderer::rgb(0, 0, 0),
|
||||
@@ -77,7 +79,7 @@ impl GradientButton {
|
||||
renderer.draw_rect(r.x, r.y, r.w, r.h, bg);
|
||||
|
||||
// Measure text to centre it.
|
||||
let font_size = 13.0;
|
||||
let font_size = self.font_size;
|
||||
let (tw, th) = fonts.measure_text(&self.text, font_size);
|
||||
let tx = r.x + ((r.w as f32 - tw) / 2.0) as i32;
|
||||
let ty = r.y + ((r.h as f32 - th) / 2.0) as i32;
|
||||
|
||||
@@ -11,8 +11,12 @@ pub struct ImageCheckBox {
|
||||
|
||||
impl ImageCheckBox {
|
||||
pub fn new(x: i32, y: i32) -> Self {
|
||||
Self::with_size(x, y, 21)
|
||||
}
|
||||
|
||||
pub fn with_size(x: i32, y: i32, size: i32) -> Self {
|
||||
Self {
|
||||
rect: Rect::new(x, y, 21, 21),
|
||||
rect: Rect::new(x, y, size, size),
|
||||
checked: true,
|
||||
enabled: true,
|
||||
visible: true,
|
||||
@@ -43,7 +47,7 @@ impl ImageCheckBox {
|
||||
unchecked_img
|
||||
};
|
||||
if img.width > 0 && img.height > 0 {
|
||||
renderer.draw_image(self.rect.x, self.rect.y, img);
|
||||
renderer.draw_image_scaled(self.rect.x, self.rect.y, self.rect.w, self.rect.h, img);
|
||||
} else {
|
||||
// Fallback: draw a simple square.
|
||||
let bg = if self.checked {
|
||||
|
||||
@@ -8,6 +8,7 @@ pub struct Label {
|
||||
pub text: String,
|
||||
pub color: u32,
|
||||
pub font_size: f32,
|
||||
pub line_spacing: f32,
|
||||
pub visible: bool,
|
||||
}
|
||||
|
||||
@@ -18,6 +19,7 @@ impl Label {
|
||||
text: text.to_string(),
|
||||
color: Renderer::rgb(245, 245, 245),
|
||||
font_size,
|
||||
line_spacing: 2.0,
|
||||
visible: true,
|
||||
}
|
||||
}
|
||||
@@ -33,7 +35,7 @@ impl Label {
|
||||
&self.text,
|
||||
self.font_size,
|
||||
self.color,
|
||||
2.0,
|
||||
self.line_spacing,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user