adapt to latest iced ("program" paradigm)
* CalendarApp does not derive from Application * use Program::run_with to run the calendar with state (from list of calndar files as cli args) Signed-off-by: Fabrizio Iannetti <fabrizio.iannetti@gmail.com>
This commit is contained in:
parent
7c624ff6ca
commit
d2a1092a7c
774
Cargo.lock
generated
774
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
31
src/main.rs
31
src/main.rs
@ -17,13 +17,10 @@ use log::info;
|
||||
use simplelog::{SimpleLogger, Config};
|
||||
use iced::{
|
||||
alignment,
|
||||
executor,
|
||||
Alignment,
|
||||
Application,
|
||||
Command,
|
||||
Element,
|
||||
Length,
|
||||
Settings,
|
||||
widget::{
|
||||
Column,
|
||||
Row,
|
||||
@ -46,10 +43,6 @@ import_tracepoints!(
|
||||
tracepoints
|
||||
);
|
||||
|
||||
struct CalendarFlags {
|
||||
calendar_paths: std::vec::Vec<path::PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about)]
|
||||
struct CliArgs {
|
||||
@ -60,12 +53,13 @@ pub fn main() -> iced::Result {
|
||||
set_up_logger();
|
||||
|
||||
let args = CliArgs::parse();
|
||||
let calendar_files = args.files.iter().map(|arg| {
|
||||
let calendar_files: Vec<_> = args.files.iter().map(|arg| {
|
||||
info!("CalFile: {}", arg);
|
||||
path::PathBuf::from(arg)
|
||||
}).collect();
|
||||
|
||||
CalendarApp::run(Settings::with_flags(CalendarFlags {calendar_paths: calendar_files}))
|
||||
let app_factory = move || { CalendarApp::with_files(calendar_files.clone())};
|
||||
iced::program("Calendar", CalendarApp::update, CalendarApp::view).run_with(app_factory)
|
||||
}
|
||||
|
||||
fn set_up_logger() {
|
||||
@ -180,23 +174,18 @@ impl Controls {
|
||||
}
|
||||
}
|
||||
|
||||
impl Application for CalendarApp {
|
||||
type Executor = executor::Default;
|
||||
type Message = Message;
|
||||
type Theme = iced::Theme;
|
||||
type Flags = CalendarFlags;
|
||||
|
||||
fn new(flags: Self::Flags) -> (Self, Command<Message>) {
|
||||
impl CalendarApp {
|
||||
fn with_files(calendar_paths: std::vec::Vec<path::PathBuf>) -> Self {
|
||||
let month = Utc::now().date_naive();
|
||||
let mut ret = (CalendarApp {
|
||||
let mut app = CalendarApp {
|
||||
month,
|
||||
events: EventsCollection::new(),
|
||||
..CalendarApp::default()
|
||||
}, Command::none());
|
||||
for calendar_path in flags.calendar_paths {
|
||||
load_calendar(&calendar_path, &mut ret.0.events);
|
||||
};
|
||||
for calendar_path in calendar_paths {
|
||||
load_calendar(&calendar_path, &mut app.events);
|
||||
}
|
||||
ret
|
||||
app
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
|
@ -223,7 +223,7 @@ fn render_events_in_row<Renderer>(
|
||||
};
|
||||
renderer.fill_text(
|
||||
Text {
|
||||
content: ev_bar.ev.text.as_str(),
|
||||
content: ev_bar.ev.text.as_str().into(),
|
||||
bounds: ev_text_size,
|
||||
size: params.ev_fontsize.into(),
|
||||
line_height: LineHeight::default(),
|
||||
@ -453,7 +453,7 @@ impl<'a> CalendarView<'a> {
|
||||
let y = bounds.center_y();
|
||||
renderer.fill_text(
|
||||
Text {
|
||||
content: t,
|
||||
content: t.to_string(),
|
||||
bounds: bounds.size(),
|
||||
size: font_size,
|
||||
line_height: LineHeight::default(),
|
||||
@ -486,7 +486,7 @@ impl<'a> CalendarView<'a> {
|
||||
// render row name
|
||||
renderer.fill_text(
|
||||
Text {
|
||||
content: &self.get_row_label(cal_row),
|
||||
content: self.get_row_label(cal_row),
|
||||
bounds: row_name_bounds.size(),
|
||||
size: self.row_name_font_size.into(),
|
||||
line_height: LineHeight::default(),
|
||||
@ -586,7 +586,7 @@ impl<'a> CalendarView<'a> {
|
||||
// render day cell text
|
||||
renderer.fill_text(
|
||||
Text {
|
||||
content,
|
||||
content: content.to_string(),
|
||||
bounds: day_bounds.size(),
|
||||
size: font_size,
|
||||
line_height: LineHeight::default(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user