setting fonts in update
This commit is contained in:
parent
53443c8fd4
commit
f8e7eead5f
|
@ -46,6 +46,7 @@
|
||||||
gst_all_1.gst-plugins-rs
|
gst_all_1.gst-plugins-rs
|
||||||
gst_all_1.gst-vaapi
|
gst_all_1.gst-vaapi
|
||||||
gst_all_1.gstreamer
|
gst_all_1.gstreamer
|
||||||
|
gst_all_1.gstreamermm
|
||||||
];
|
];
|
||||||
|
|
||||||
bi = with pkgs; [
|
bi = with pkgs; [
|
||||||
|
|
168
src/main.rs
168
src/main.rs
|
@ -2,21 +2,20 @@ use clap::{command, Parser};
|
||||||
use core::service_items::{ServiceItem, ServiceItemModel};
|
use core::service_items::{ServiceItem, ServiceItemModel};
|
||||||
use cosmic::app::context_drawer::ContextDrawer;
|
use cosmic::app::context_drawer::ContextDrawer;
|
||||||
use cosmic::app::{Core, Settings, Task};
|
use cosmic::app::{Core, Settings, Task};
|
||||||
use cosmic::iced::alignment::Horizontal;
|
use cosmic::iced::keyboard::{Key, Modifiers};
|
||||||
use cosmic::iced::keyboard::Key;
|
|
||||||
use cosmic::iced::window::{Mode, Position};
|
use cosmic::iced::window::{Mode, Position};
|
||||||
use cosmic::iced::{
|
use cosmic::iced::{
|
||||||
self, event, window, Font, Length, Padding, Point,
|
self, event, window, Font, Length, Padding, Point,
|
||||||
};
|
};
|
||||||
use cosmic::iced_core::SmolStr;
|
use cosmic::iced_core::SmolStr;
|
||||||
|
use cosmic::iced_futures::Subscription;
|
||||||
use cosmic::iced_widget::{column, row, stack};
|
use cosmic::iced_widget::{column, row, stack};
|
||||||
use cosmic::prelude::ElementExt;
|
use cosmic::prelude::ElementExt;
|
||||||
use cosmic::prelude::*;
|
use cosmic::prelude::*;
|
||||||
use cosmic::widget::aspect_ratio::aspect_ratio_container;
|
|
||||||
use cosmic::widget::nav_bar::nav_bar_style;
|
use cosmic::widget::nav_bar::nav_bar_style;
|
||||||
use cosmic::widget::tooltip::Position as TPosition;
|
use cosmic::widget::tooltip::Position as TPosition;
|
||||||
use cosmic::widget::{
|
use cosmic::widget::{
|
||||||
button, context_drawer, image, nav_bar, text, tooltip,
|
button, context_drawer, image, nav_bar, text, tooltip, MouseArea,
|
||||||
Responsive, Space,
|
Responsive, Space,
|
||||||
};
|
};
|
||||||
use cosmic::widget::{icon, slider};
|
use cosmic::widget::{icon, slider};
|
||||||
|
@ -94,6 +93,8 @@ struct App {
|
||||||
current_slide: Slide,
|
current_slide: Slide,
|
||||||
presentation_open: bool,
|
presentation_open: bool,
|
||||||
cli_mode: bool,
|
cli_mode: bool,
|
||||||
|
library_open: bool,
|
||||||
|
library_width: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -107,6 +108,7 @@ enum Message {
|
||||||
WindowOpened(window::Id, Option<Point>),
|
WindowOpened(window::Id, Option<Point>),
|
||||||
WindowClosed(window::Id),
|
WindowClosed(window::Id),
|
||||||
Quit,
|
Quit,
|
||||||
|
Key(Key, Modifiers),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +182,8 @@ impl cosmic::Application for App {
|
||||||
current_slide,
|
current_slide,
|
||||||
presentation_open: false,
|
presentation_open: false,
|
||||||
cli_mode: !input.ui,
|
cli_mode: !input.ui,
|
||||||
|
library_open: true,
|
||||||
|
library_width: 60.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let command;
|
let command;
|
||||||
|
@ -300,75 +304,44 @@ impl cosmic::Application for App {
|
||||||
Some(text::body("Sux").into())
|
Some(text::body("Sux").into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subscription(
|
fn subscription(&self) -> Subscription<Self::Message> {
|
||||||
&self,
|
|
||||||
) -> cosmic::iced_futures::Subscription<Self::Message> {
|
|
||||||
event::listen_with(|event, _, id| {
|
event::listen_with(|event, _, id| {
|
||||||
if let iced::Event::Window(window_event) = event {
|
// debug!(?event);
|
||||||
match window_event {
|
match event {
|
||||||
window::Event::CloseRequested => {
|
iced::Event::Keyboard(event) => match event {
|
||||||
debug!("Closing window");
|
iced::keyboard::Event::KeyPressed {
|
||||||
Some(Message::CloseWindow(Some(id)))
|
|
||||||
}
|
|
||||||
window::Event::Opened { position, .. } => {
|
|
||||||
debug!(?window_event, ?id);
|
|
||||||
Some(Message::WindowOpened(id, position))
|
|
||||||
}
|
|
||||||
window::Event::Closed => {
|
|
||||||
debug!("Closed window");
|
|
||||||
Some(Message::WindowClosed(id))
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
} else if let iced::Event::Keyboard(key) = event {
|
|
||||||
match key {
|
|
||||||
iced::keyboard::Event::KeyReleased {
|
|
||||||
key,
|
key,
|
||||||
modified_key: _,
|
modifiers,
|
||||||
physical_key: _,
|
..
|
||||||
location: _,
|
} => Some(Message::Key(key, modifiers)),
|
||||||
modifiers: _,
|
_ => None,
|
||||||
} => match key {
|
},
|
||||||
Key::Named(
|
iced::Event::Mouse(event) => None,
|
||||||
iced::keyboard::key::Named::ArrowRight,
|
iced::Event::Window(window_event) => {
|
||||||
) => Some(Message::Present(
|
match window_event {
|
||||||
ui::presenter::Message::NextSlide,
|
window::Event::CloseRequested => {
|
||||||
)),
|
debug!("Closing window");
|
||||||
Key::Named(
|
Some(Message::CloseWindow(Some(id)))
|
||||||
iced::keyboard::key::Named::ArrowLeft,
|
}
|
||||||
) => Some(Message::Present(
|
window::Event::Opened {
|
||||||
ui::presenter::Message::NextSlide,
|
position, ..
|
||||||
)),
|
} => {
|
||||||
Key::Named(
|
debug!(?window_event, ?id);
|
||||||
iced::keyboard::key::Named::Space,
|
Some(Message::WindowOpened(id, position))
|
||||||
) => Some(Message::Present(
|
}
|
||||||
ui::presenter::Message::NextSlide,
|
window::Event::Closed => {
|
||||||
)),
|
debug!("Closed window");
|
||||||
Key::Character(key) => {
|
Some(Message::WindowClosed(id))
|
||||||
if key == SmolStr::from("j")
|
|
||||||
|| key == SmolStr::from("l")
|
|
||||||
{
|
|
||||||
Some(Message::Present(
|
|
||||||
ui::presenter::Message::NextSlide,
|
|
||||||
))
|
|
||||||
} else if key == SmolStr::from("k")
|
|
||||||
|| key == SmolStr::from("h")
|
|
||||||
{
|
|
||||||
Some(Message::Present(
|
|
||||||
ui::presenter::Message::PrevSlide,
|
|
||||||
))
|
|
||||||
} else if key == SmolStr::from("q") {
|
|
||||||
Some(Message::Quit)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
}
|
||||||
_ => None,
|
}
|
||||||
|
iced::Event::Touch(event) => None,
|
||||||
|
iced::Event::A11y(id, action_request) => None,
|
||||||
|
iced::Event::Dnd(dnd_event) => None,
|
||||||
|
iced::Event::PlatformSpecific(platform_specific) => {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -391,8 +364,57 @@ impl cosmic::Application for App {
|
||||||
|
|
||||||
fn update(&mut self, message: Message) -> Task<Message> {
|
fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
|
Message::Key(key, modifiers) => {
|
||||||
|
debug!(?key, ?modifiers);
|
||||||
|
match (key, modifiers) {
|
||||||
|
(
|
||||||
|
Key::Named(
|
||||||
|
iced::keyboard::key::Named::ArrowRight,
|
||||||
|
),
|
||||||
|
_,
|
||||||
|
) => self.update(Message::Present(
|
||||||
|
presenter::Message::NextSlide,
|
||||||
|
)),
|
||||||
|
(
|
||||||
|
Key::Named(
|
||||||
|
iced::keyboard::key::Named::ArrowLeft,
|
||||||
|
),
|
||||||
|
_,
|
||||||
|
) => self.update(Message::Present(
|
||||||
|
presenter::Message::PrevSlide,
|
||||||
|
)),
|
||||||
|
(
|
||||||
|
Key::Named(iced::keyboard::key::Named::Space),
|
||||||
|
_,
|
||||||
|
) => self.update(Message::Present(
|
||||||
|
presenter::Message::NextSlide,
|
||||||
|
)),
|
||||||
|
(Key::Character(k), _)
|
||||||
|
if k == SmolStr::from("j")
|
||||||
|
|| k == SmolStr::from("l") =>
|
||||||
|
{
|
||||||
|
self.update(Message::Present(
|
||||||
|
presenter::Message::NextSlide,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
(Key::Character(k), _)
|
||||||
|
if k == SmolStr::from("k")
|
||||||
|
|| k == SmolStr::from("h") =>
|
||||||
|
{
|
||||||
|
self.update(Message::Present(
|
||||||
|
presenter::Message::PrevSlide,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
(Key::Character(k), _)
|
||||||
|
if k == SmolStr::from("q") =>
|
||||||
|
{
|
||||||
|
self.update(Message::Quit)
|
||||||
|
}
|
||||||
|
_ => Task::none(),
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::Present(message) => {
|
Message::Present(message) => {
|
||||||
debug!(?message);
|
// debug!(?message);
|
||||||
if self.presentation_open {
|
if self.presentation_open {
|
||||||
if let Some(video) = &mut self.presenter.video {
|
if let Some(video) = &mut self.presenter.video {
|
||||||
video.set_muted(false);
|
video.set_muted(false);
|
||||||
|
@ -550,6 +572,14 @@ impl cosmic::Application for App {
|
||||||
]
|
]
|
||||||
.spacing(3);
|
.spacing(3);
|
||||||
|
|
||||||
|
// let library = Container::new("library")
|
||||||
|
// .center(Length::Fill)
|
||||||
|
// .width(self.library_width);
|
||||||
|
// let drag_handle = Container::new(Space::new(1, Length::Fill))
|
||||||
|
// .style(|t| nav_bar_style(t));
|
||||||
|
// let dragger = MouseArea::new(drag_handle)
|
||||||
|
// .on_drag(Message::LibraryWidth);
|
||||||
|
|
||||||
let row = row![
|
let row = row![
|
||||||
Container::new(
|
Container::new(
|
||||||
button::icon(icon_left)
|
button::icon(icon_left)
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
use std::{
|
use std::{fs::File, io::BufReader, path::PathBuf, sync::Arc};
|
||||||
fs::File, io::BufReader, path::PathBuf, sync::Arc, thread,
|
|
||||||
};
|
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
dialog::ashpd::url::Url,
|
dialog::ashpd::url::Url,
|
||||||
|
@ -12,8 +10,7 @@ use cosmic::{
|
||||||
},
|
},
|
||||||
iced_widget::{
|
iced_widget::{
|
||||||
scrollable::{
|
scrollable::{
|
||||||
scroll_by, scroll_to, AbsoluteOffset, Direction,
|
scroll_to, AbsoluteOffset, Direction, Scrollbar,
|
||||||
Scrollbar,
|
|
||||||
},
|
},
|
||||||
stack,
|
stack,
|
||||||
},
|
},
|
||||||
|
@ -45,6 +42,7 @@ pub(crate) struct Presenter {
|
||||||
sink: (OutputStream, Arc<Sink>),
|
sink: (OutputStream, Arc<Sink>),
|
||||||
hovered_slide: i32,
|
hovered_slide: i32,
|
||||||
scroll_id: Id,
|
scroll_id: Id,
|
||||||
|
current_font: Font,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
@ -59,6 +57,7 @@ pub(crate) enum Message {
|
||||||
VideoPos(f32),
|
VideoPos(f32),
|
||||||
VideoFrame,
|
VideoFrame,
|
||||||
HoveredSlide(i32),
|
HoveredSlide(i32),
|
||||||
|
ChangeFont(String),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +108,7 @@ impl Presenter {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
scroll_id: Id::unique(),
|
scroll_id: Id::unique(),
|
||||||
|
current_font: cosmic::font::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,10 +138,11 @@ impl Presenter {
|
||||||
}
|
}
|
||||||
Message::SlideChange(id) => {
|
Message::SlideChange(id) => {
|
||||||
debug!(id, "slide changed");
|
debug!(id, "slide changed");
|
||||||
let right = self.current_slide_index < id;
|
|
||||||
self.current_slide_index = id;
|
self.current_slide_index = id;
|
||||||
if let Some(slide) = self.slides.get(id as usize) {
|
if let Some(slide) = self.slides.get(id as usize) {
|
||||||
self.current_slide = slide.clone();
|
self.current_slide = slide.clone();
|
||||||
|
let _ = self
|
||||||
|
.update(Message::ChangeFont(slide.font()));
|
||||||
}
|
}
|
||||||
if let Some(video) = &mut self.video {
|
if let Some(video) = &mut self.video {
|
||||||
let _ = video.restart_stream();
|
let _ = video.restart_stream();
|
||||||
|
@ -196,6 +197,21 @@ impl Presenter {
|
||||||
}
|
}
|
||||||
Task::batch(tasks)
|
Task::batch(tasks)
|
||||||
}
|
}
|
||||||
|
Message::ChangeFont(s) => {
|
||||||
|
let font_name = s.into_boxed_str();
|
||||||
|
let family = Family::Name(Box::leak(font_name));
|
||||||
|
let weight = Weight::Normal;
|
||||||
|
let stretch = Stretch::Normal;
|
||||||
|
let style = Style::Normal;
|
||||||
|
let font = Font {
|
||||||
|
family,
|
||||||
|
weight,
|
||||||
|
stretch,
|
||||||
|
style,
|
||||||
|
};
|
||||||
|
self.current_font = font;
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
Message::EndVideo => {
|
Message::EndVideo => {
|
||||||
// if self.current_slide.video_loop() {
|
// if self.current_slide.video_loop() {
|
||||||
// if let Some(video) = &mut self.video {
|
// if let Some(video) = &mut self.video {
|
||||||
|
@ -266,17 +282,7 @@ impl Presenter {
|
||||||
|
|
||||||
pub fn view(&self) -> Element<Message> {
|
pub fn view(&self) -> Element<Message> {
|
||||||
responsive(|size| {
|
responsive(|size| {
|
||||||
let font = self.current_slide.font().into_boxed_str();
|
let font = self.current_font;
|
||||||
let family = Family::Name(Box::leak(font));
|
|
||||||
let weight = Weight::Normal;
|
|
||||||
let stretch = Stretch::Normal;
|
|
||||||
let style = Style::Normal;
|
|
||||||
let font = Font {
|
|
||||||
family,
|
|
||||||
weight,
|
|
||||||
stretch,
|
|
||||||
style,
|
|
||||||
};
|
|
||||||
let font_size = if self.current_slide.font_size() > 0 {
|
let font_size = if self.current_slide.font_size() > 0 {
|
||||||
(size.width / self.current_slide.font_size() as f32)
|
(size.width / self.current_slide.font_size() as f32)
|
||||||
* 3.0
|
* 3.0
|
||||||
|
@ -341,6 +347,7 @@ impl Presenter {
|
||||||
if let Some(video) = &self.video {
|
if let Some(video) = &self.video {
|
||||||
Container::new(
|
Container::new(
|
||||||
VideoPlayer::new(video)
|
VideoPlayer::new(video)
|
||||||
|
.mouse_hidden(true)
|
||||||
.width(size.width)
|
.width(size.width)
|
||||||
.height(size.width * 9.0 / 16.0)
|
.height(size.width * 9.0 / 16.0)
|
||||||
.on_end_of_stream(Message::EndVideo)
|
.on_end_of_stream(Message::EndVideo)
|
||||||
|
@ -366,17 +373,7 @@ impl Presenter {
|
||||||
|
|
||||||
pub fn view_preview(&self) -> Element<Message> {
|
pub fn view_preview(&self) -> Element<Message> {
|
||||||
responsive(|size| {
|
responsive(|size| {
|
||||||
let font = self.current_slide.font().into_boxed_str();
|
let font = self.current_font;
|
||||||
let family = Family::Name(Box::leak(font));
|
|
||||||
let weight = Weight::Normal;
|
|
||||||
let stretch = Stretch::Normal;
|
|
||||||
let style = Style::Normal;
|
|
||||||
let font = Font {
|
|
||||||
family,
|
|
||||||
weight,
|
|
||||||
stretch,
|
|
||||||
style,
|
|
||||||
};
|
|
||||||
let font_size = if self.current_slide.font_size() > 0 {
|
let font_size = if self.current_slide.font_size() > 0 {
|
||||||
(size.width / self.current_slide.font_size() as f32)
|
(size.width / self.current_slide.font_size() as f32)
|
||||||
* 3.0
|
* 3.0
|
||||||
|
@ -448,7 +445,8 @@ impl Presenter {
|
||||||
&'a self,
|
&'a self,
|
||||||
slide: &'a Slide,
|
slide: &'a Slide,
|
||||||
) -> Element<'a, Message> {
|
) -> Element<'a, Message> {
|
||||||
let family = Family::Name("VictorMono Nerd Font");
|
let font_name = slide.font().into_boxed_str();
|
||||||
|
let family = Family::Name(Box::leak(font_name));
|
||||||
let weight = Weight::Normal;
|
let weight = Weight::Normal;
|
||||||
let stretch = Stretch::Normal;
|
let stretch = Stretch::Normal;
|
||||||
let style = Style::Normal;
|
let style = Style::Normal;
|
||||||
|
|
Loading…
Reference in a new issue