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
33
src/main.rs
33
src/main.rs
@ -17,13 +17,10 @@ use log::info;
|
|||||||
use simplelog::{SimpleLogger, Config};
|
use simplelog::{SimpleLogger, Config};
|
||||||
use iced::{
|
use iced::{
|
||||||
alignment,
|
alignment,
|
||||||
executor,
|
|
||||||
Alignment,
|
Alignment,
|
||||||
Application,
|
|
||||||
Command,
|
Command,
|
||||||
Element,
|
Element,
|
||||||
Length,
|
Length,
|
||||||
Settings,
|
|
||||||
widget::{
|
widget::{
|
||||||
Column,
|
Column,
|
||||||
Row,
|
Row,
|
||||||
@ -46,10 +43,6 @@ import_tracepoints!(
|
|||||||
tracepoints
|
tracepoints
|
||||||
);
|
);
|
||||||
|
|
||||||
struct CalendarFlags {
|
|
||||||
calendar_paths: std::vec::Vec<path::PathBuf>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about)]
|
#[command(version, about)]
|
||||||
struct CliArgs {
|
struct CliArgs {
|
||||||
@ -60,12 +53,13 @@ pub fn main() -> iced::Result {
|
|||||||
set_up_logger();
|
set_up_logger();
|
||||||
|
|
||||||
let args = CliArgs::parse();
|
let args = CliArgs::parse();
|
||||||
let calendar_files = args.files.iter().map(|arg| {
|
let calendar_files: Vec<_> = args.files.iter().map(|arg| {
|
||||||
info!("CalFile: {}", arg);
|
info!("CalFile: {}", arg);
|
||||||
path::PathBuf::from(arg)
|
path::PathBuf::from(arg)
|
||||||
}).collect();
|
}).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() {
|
fn set_up_logger() {
|
||||||
@ -180,24 +174,19 @@ impl Controls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for CalendarApp {
|
impl CalendarApp {
|
||||||
type Executor = executor::Default;
|
fn with_files(calendar_paths: std::vec::Vec<path::PathBuf>) -> Self {
|
||||||
type Message = Message;
|
|
||||||
type Theme = iced::Theme;
|
|
||||||
type Flags = CalendarFlags;
|
|
||||||
|
|
||||||
fn new(flags: Self::Flags) -> (Self, Command<Message>) {
|
|
||||||
let month = Utc::now().date_naive();
|
let month = Utc::now().date_naive();
|
||||||
let mut ret = (CalendarApp {
|
let mut app = CalendarApp {
|
||||||
month,
|
month,
|
||||||
events: EventsCollection::new(),
|
events: EventsCollection::new(),
|
||||||
..CalendarApp::default()
|
..CalendarApp::default()
|
||||||
}, Command::none());
|
};
|
||||||
for calendar_path in flags.calendar_paths {
|
for calendar_path in calendar_paths {
|
||||||
load_calendar(&calendar_path, &mut ret.0.events);
|
load_calendar(&calendar_path, &mut app.events);
|
||||||
}
|
}
|
||||||
ret
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
fn title(&self) -> String {
|
fn title(&self) -> String {
|
||||||
String::from("Calendar")
|
String::from("Calendar")
|
||||||
|
@ -223,7 +223,7 @@ fn render_events_in_row<Renderer>(
|
|||||||
};
|
};
|
||||||
renderer.fill_text(
|
renderer.fill_text(
|
||||||
Text {
|
Text {
|
||||||
content: ev_bar.ev.text.as_str(),
|
content: ev_bar.ev.text.as_str().into(),
|
||||||
bounds: ev_text_size,
|
bounds: ev_text_size,
|
||||||
size: params.ev_fontsize.into(),
|
size: params.ev_fontsize.into(),
|
||||||
line_height: LineHeight::default(),
|
line_height: LineHeight::default(),
|
||||||
@ -453,7 +453,7 @@ impl<'a> CalendarView<'a> {
|
|||||||
let y = bounds.center_y();
|
let y = bounds.center_y();
|
||||||
renderer.fill_text(
|
renderer.fill_text(
|
||||||
Text {
|
Text {
|
||||||
content: t,
|
content: t.to_string(),
|
||||||
bounds: bounds.size(),
|
bounds: bounds.size(),
|
||||||
size: font_size,
|
size: font_size,
|
||||||
line_height: LineHeight::default(),
|
line_height: LineHeight::default(),
|
||||||
@ -486,7 +486,7 @@ impl<'a> CalendarView<'a> {
|
|||||||
// render row name
|
// render row name
|
||||||
renderer.fill_text(
|
renderer.fill_text(
|
||||||
Text {
|
Text {
|
||||||
content: &self.get_row_label(cal_row),
|
content: self.get_row_label(cal_row),
|
||||||
bounds: row_name_bounds.size(),
|
bounds: row_name_bounds.size(),
|
||||||
size: self.row_name_font_size.into(),
|
size: self.row_name_font_size.into(),
|
||||||
line_height: LineHeight::default(),
|
line_height: LineHeight::default(),
|
||||||
@ -586,7 +586,7 @@ impl<'a> CalendarView<'a> {
|
|||||||
// render day cell text
|
// render day cell text
|
||||||
renderer.fill_text(
|
renderer.fill_text(
|
||||||
Text {
|
Text {
|
||||||
content,
|
content: content.to_string(),
|
||||||
bounds: day_bounds.size(),
|
bounds: day_bounds.size(),
|
||||||
size: font_size,
|
size: font_size,
|
||||||
line_height: LineHeight::default(),
|
line_height: LineHeight::default(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user