date: Fix dimension calculations
This commit is contained in:
+5
-2
@@ -119,11 +119,14 @@ impl Widget {
|
|||||||
Ok(w) => Some(w),
|
Ok(w) => Some(w),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
},
|
},
|
||||||
Widget::Date { font, font_size } => Some(widgets::date::Date::new(
|
Widget::Date { font, font_size } => match widgets::date::Date::new(
|
||||||
time,
|
time,
|
||||||
get_font(&font.or_else(|| Some("sans".to_string())).unwrap(), &fonts),
|
get_font(&font.or_else(|| Some("sans".to_string())).unwrap(), &fonts),
|
||||||
font_size,
|
font_size,
|
||||||
)),
|
) {
|
||||||
|
Ok(w) => Some(w),
|
||||||
|
Err(_) => None,
|
||||||
|
},
|
||||||
Widget::Calendar {
|
Widget::Calendar {
|
||||||
font_primary,
|
font_primary,
|
||||||
font_secondary,
|
font_secondary,
|
||||||
|
|||||||
+23
-6
@@ -11,19 +11,33 @@ pub struct Date<'a> {
|
|||||||
cur_time: NaiveDateTime,
|
cur_time: NaiveDateTime,
|
||||||
date_cache: Font<'a>,
|
date_cache: Font<'a>,
|
||||||
size: f32,
|
size: f32,
|
||||||
|
ch_width: u32,
|
||||||
|
digit_width: u32,
|
||||||
|
spacing_width: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Date<'a> {
|
impl<'a> Date<'a> {
|
||||||
pub fn new(time: NaiveDateTime, font: FontRef, size: f32) -> Box<Date> {
|
pub fn new(time: NaiveDateTime, font: FontRef, size: f32) -> ::std::io::Result<Box<Date>> {
|
||||||
let mut date_cache = Font::new(font, size);
|
let mut date_cache = Font::new(font, size);
|
||||||
date_cache
|
let chs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
.add_str_to_cache("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,/ ");
|
let digits = "0123456789,/ ";
|
||||||
|
let spacings = ",/ ";
|
||||||
|
|
||||||
Box::new(Date {
|
date_cache.add_str_to_cache(chs);
|
||||||
|
date_cache.add_str_to_cache(digits);
|
||||||
|
date_cache.add_str_to_cache(spacings);
|
||||||
|
let ch_width = date_cache.auto_widest(chs)?;
|
||||||
|
let digit_width = date_cache.auto_widest(digits)?;
|
||||||
|
let spacing_width = date_cache.auto_widest(spacings)?;
|
||||||
|
|
||||||
|
Ok(Box::new(Date {
|
||||||
cur_time: time,
|
cur_time: time,
|
||||||
date_cache,
|
date_cache,
|
||||||
size,
|
size,
|
||||||
})
|
ch_width,
|
||||||
|
digit_width,
|
||||||
|
spacing_width,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +46,10 @@ impl<'a> Widget for Date<'a> {
|
|||||||
fn enter(&mut self) {}
|
fn enter(&mut self) {}
|
||||||
fn leave(&mut self) {}
|
fn leave(&mut self) {}
|
||||||
fn size(&self) -> (u32, u32) {
|
fn size(&self) -> (u32, u32) {
|
||||||
((6.5 * self.size).ceil() as u32, self.size.ceil() as u32)
|
(
|
||||||
|
(3 * self.ch_width + 8 * self.digit_width + 4 * self.spacing_width) as u32,
|
||||||
|
self.size.ceil() as u32,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(
|
fn draw(
|
||||||
|
|||||||
Reference in New Issue
Block a user