calendar: Fixed cross year name and multi month linkage click issues (#1241)

<img width="864" height="298" alt="image"
src="https://github.com/user-attachments/assets/7f0a34d7-e000-4756-b1ae-0e6511679660"
/>
This commit is contained in:
Cookie 2025-09-12 10:29:07 +08:00 committed by GitHub
parent da85754b96
commit feabb748ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -474,6 +474,11 @@ impl CalendarState {
.into()
}
fn year_name(&self, offset_month: usize) -> SharedString {
let (year, _) = self.offset_year_month(offset_month);
year.to_string().into()
}
fn set_view_mode(&mut self, mode: ViewMode, _: &mut Window, cx: &mut Context<Self>) {
self.view_mode = mode;
cx.notify();
@ -534,7 +539,7 @@ impl Calendar {
let (_, month) = state.offset_year_month(offset_month);
let day = d.day();
let is_current_month = d.month() == month;
let is_active = state.date.is_active(d) && is_current_month;
let is_active = state.date.is_active(d);
let is_in_range = state.date.is_in_range(d);
let date = *d;
@ -544,8 +549,10 @@ impl Calendar {
.as_ref()
.map_or(false, |disabled| disabled.matched(&date));
let date_id: SharedString = format!("{}_{}", date.format("%Y-%m-%d"), offset_month).into();
self.item_button(
d.ordinal() as usize,
date_id,
day.to_string(),
is_active,
is_in_range,
@ -681,7 +688,7 @@ impl Calendar {
_ => this.gap_3(),
})
.child(state.month_name(n))
.child(current_year.to_string())
.child(state.year_name(n))
}),
))
})