fixing text issues and window issues
This commit is contained in:
parent
04b7ba6382
commit
d7c69bf9e0
78
src/main.rs
78
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
use clap::{command, Parser};
|
use clap::{command, Parser};
|
||||||
use cosmic::app::{Core, Settings, Task};
|
use cosmic::app::{Core, Settings, Task};
|
||||||
use cosmic::iced::keyboard::Key;
|
use cosmic::iced::keyboard::Key;
|
||||||
use cosmic::iced::window::Position;
|
use cosmic::iced::window::{Mode, Position};
|
||||||
use cosmic::iced::{self, event, window, Font, Length, Point};
|
use cosmic::iced::{self, event, window, Font, Length, Point};
|
||||||
use cosmic::iced_core::SmolStr;
|
use cosmic::iced_core::SmolStr;
|
||||||
use cosmic::iced_widget::{column, row, stack};
|
use cosmic::iced_widget::{column, row, stack};
|
||||||
|
@ -18,8 +18,8 @@ use lisp::parse_lisp;
|
||||||
use miette::{miette, Result};
|
use miette::{miette, Result};
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tracing::warn;
|
|
||||||
use tracing::{debug, level_filters::LevelFilter};
|
use tracing::{debug, level_filters::LevelFilter};
|
||||||
|
use tracing::{error, warn};
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
pub mod core;
|
pub mod core;
|
||||||
|
@ -83,6 +83,7 @@ struct App {
|
||||||
windows: Vec<window::Id>,
|
windows: Vec<window::Id>,
|
||||||
slides: Vec<Slide>,
|
slides: Vec<Slide>,
|
||||||
current_slide: Slide,
|
current_slide: Slide,
|
||||||
|
presentation_open: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -90,7 +91,7 @@ enum Message {
|
||||||
Present(presenter::Message),
|
Present(presenter::Message),
|
||||||
File(PathBuf),
|
File(PathBuf),
|
||||||
OpenWindow,
|
OpenWindow,
|
||||||
CloseWindow(window::Id),
|
CloseWindow(Option<window::Id>),
|
||||||
WindowOpened(window::Id, Option<Point>),
|
WindowOpened(window::Id, Option<Point>),
|
||||||
WindowClosed(window::Id),
|
WindowClosed(window::Id),
|
||||||
}
|
}
|
||||||
|
@ -113,9 +114,6 @@ impl cosmic::Application for App {
|
||||||
debug!("init");
|
debug!("init");
|
||||||
let mut nav_model = nav_bar::Model::default();
|
let mut nav_model = nav_bar::Model::default();
|
||||||
|
|
||||||
nav_model.insert().text("Preview").data("Preview");
|
|
||||||
|
|
||||||
nav_model.activate_position(0);
|
|
||||||
let mut windows = vec![];
|
let mut windows = vec![];
|
||||||
|
|
||||||
if input.ui {
|
if input.ui {
|
||||||
|
@ -145,14 +143,22 @@ impl cosmic::Application for App {
|
||||||
|
|
||||||
let current_slide = slides[0].clone();
|
let current_slide = slides[0].clone();
|
||||||
let presenter = Presenter::with_slides(slides.clone());
|
let presenter = Presenter::with_slides(slides.clone());
|
||||||
|
|
||||||
|
for slide in slides.clone() {
|
||||||
|
nav_model.insert().text(slide.text()).data(slide);
|
||||||
|
}
|
||||||
|
|
||||||
|
nav_model.activate_position(0);
|
||||||
|
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
presenter,
|
presenter,
|
||||||
core,
|
core,
|
||||||
nav_model: nav_bar::Model::default(),
|
nav_model,
|
||||||
file: PathBuf::default(),
|
file: PathBuf::default(),
|
||||||
windows: vec![],
|
windows,
|
||||||
slides,
|
slides,
|
||||||
current_slide,
|
current_slide,
|
||||||
|
presentation_open: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let command;
|
let command;
|
||||||
|
@ -188,13 +194,17 @@ impl cosmic::Application for App {
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
fn header_end(&self) -> Vec<Element<Self::Message>> {
|
fn header_end(&self) -> Vec<Element<Self::Message>> {
|
||||||
let window_open = self.windows.len() > 1;
|
|
||||||
let presenter_window = self.windows.get(1);
|
let presenter_window = self.windows.get(1);
|
||||||
|
let text = if self.presentation_open {
|
||||||
|
text::body("Close Presentation")
|
||||||
|
} else {
|
||||||
|
text::body("Open Presentation")
|
||||||
|
};
|
||||||
vec![tooltip(
|
vec![tooltip(
|
||||||
button::custom(
|
button::custom(
|
||||||
row!(
|
row!(
|
||||||
Container::new(
|
Container::new(
|
||||||
icon::from_name(if window_open {
|
icon::from_name(if self.presentation_open {
|
||||||
"dialog-close"
|
"dialog-close"
|
||||||
} else {
|
} else {
|
||||||
"view-presentation-symbolic"
|
"view-presentation-symbolic"
|
||||||
|
@ -202,32 +212,29 @@ impl cosmic::Application for App {
|
||||||
.scale(3)
|
.scale(3)
|
||||||
)
|
)
|
||||||
.center_y(Length::Fill),
|
.center_y(Length::Fill),
|
||||||
text::body(if window_open {
|
text
|
||||||
"Close Presentation"
|
|
||||||
} else {
|
|
||||||
"Open Presentation"
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
.padding(5)
|
.padding(5)
|
||||||
.spacing(5),
|
.spacing(5),
|
||||||
)
|
)
|
||||||
.class(cosmic::theme::style::Button::HeaderBar)
|
.class(cosmic::theme::style::Button::HeaderBar)
|
||||||
.on_press({
|
.on_press({
|
||||||
debug!(window_open);
|
if self.presentation_open {
|
||||||
if window_open {
|
Message::CloseWindow(
|
||||||
Message::CloseWindow(*presenter_window.unwrap())
|
presenter_window.map(|id| *id),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
Message::OpenWindow
|
Message::OpenWindow
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
"Open Window",
|
"Start Presentation",
|
||||||
TPosition::Bottom,
|
TPosition::Bottom,
|
||||||
)
|
)
|
||||||
.into()]
|
.into()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn footer(&self) -> Option<Element<Self::Message>> {
|
fn footer(&self) -> Option<Element<Self::Message>> {
|
||||||
Some(text::body("Sux").line_height(1.0).into())
|
Some(text::body("Sux").into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subscription(
|
fn subscription(
|
||||||
|
@ -238,7 +245,7 @@ impl cosmic::Application for App {
|
||||||
match window_event {
|
match window_event {
|
||||||
window::Event::CloseRequested => {
|
window::Event::CloseRequested => {
|
||||||
debug!("Closing window");
|
debug!("Closing window");
|
||||||
Some(Message::CloseWindow(id))
|
Some(Message::CloseWindow(Some(id)))
|
||||||
}
|
}
|
||||||
window::Event::Opened { position, .. } => {
|
window::Event::Opened { position, .. } => {
|
||||||
debug!(?window_event, ?id);
|
debug!(?window_event, ?id);
|
||||||
|
@ -338,22 +345,37 @@ impl cosmic::Application for App {
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Message::CloseWindow(id) => window::close(id),
|
Message::CloseWindow(id) => {
|
||||||
|
if let Some(id) = id {
|
||||||
|
window::close(id)
|
||||||
|
} else {
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::WindowOpened(id, _) => {
|
Message::WindowOpened(id, _) => {
|
||||||
debug!(?id, "Window opened");
|
debug!(?id, "Window opened");
|
||||||
Task::none()
|
if id > self.core.main_window_id().unwrap() {
|
||||||
|
self.presentation_open = true;
|
||||||
|
warn!(self.presentation_open);
|
||||||
|
window::change_mode(id, Mode::Fullscreen)
|
||||||
|
} else {
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Message::WindowClosed(id) => {
|
Message::WindowClosed(id) => {
|
||||||
let window = self
|
warn!("Closing window: {id}");
|
||||||
.windows
|
let Some(window) =
|
||||||
.iter()
|
self.windows.iter().position(|w| *w == id)
|
||||||
.position(|w| *w == id)
|
else {
|
||||||
.unwrap();
|
error!("Nothing matches this window id: {id}");
|
||||||
|
return Task::none();
|
||||||
|
};
|
||||||
self.windows.remove(window);
|
self.windows.remove(window);
|
||||||
// This closes the app if using the cli example
|
// This closes the app if using the cli example
|
||||||
if self.windows.len() == 0 {
|
if self.windows.len() == 0 {
|
||||||
cosmic::iced::exit()
|
cosmic::iced::exit()
|
||||||
} else {
|
} else {
|
||||||
|
self.presentation_open = false;
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,9 +151,7 @@ impl Presenter {
|
||||||
} else {
|
} else {
|
||||||
50
|
50
|
||||||
};
|
};
|
||||||
let text = text(self.current_slide.text())
|
let text = text(self.current_slide.text()).size(font_size);
|
||||||
.size(font_size)
|
|
||||||
.line_height(20.0);
|
|
||||||
let text = Container::new(text).center(Length::Fill);
|
let text = Container::new(text).center(Length::Fill);
|
||||||
let black = Container::new(Space::new(0, 0))
|
let black = Container::new(Space::new(0, 0))
|
||||||
.style(|_| {
|
.style(|_| {
|
||||||
|
@ -201,9 +199,12 @@ impl Presenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn slide_delegate(slide: &Slide) -> Element<Message> {
|
fn slide_delegate(slide: &Slide) -> Element<Message> {
|
||||||
let text = text!("{}", slide.text())
|
let font_size = if slide.font_size() > 0 {
|
||||||
.size(slide.font_size() as u16)
|
slide.font_size() as u16
|
||||||
.line_height(1.0);
|
} else {
|
||||||
|
50
|
||||||
|
};
|
||||||
|
let text = text(slide.text()).size(font_size);
|
||||||
let text = Container::new(text).center(Length::Fill);
|
let text = Container::new(text).center(Length::Fill);
|
||||||
let container = match slide.background().kind {
|
let container = match slide.background().kind {
|
||||||
crate::BackgroundKind::Image => Container::new(
|
crate::BackgroundKind::Image => Container::new(
|
||||||
|
|
Loading…
Reference in a new issue