Add fullscreen toggle
This commit is contained in:
parent
52effa6efb
commit
6dee6b862f
1 changed files with 51 additions and 16 deletions
|
|
@ -9,7 +9,7 @@ use cosmic::{
|
||||||
event::{self, Event},
|
event::{self, Event},
|
||||||
keyboard::{Event as KeyEvent, Key, Modifiers},
|
keyboard::{Event as KeyEvent, Key, Modifiers},
|
||||||
subscription::{self, Subscription},
|
subscription::{self, Subscription},
|
||||||
Alignment, Length, Limits, Size,
|
window, Alignment, Color, Length, Limits, Size,
|
||||||
},
|
},
|
||||||
theme,
|
theme,
|
||||||
widget::{self, Column, Row, Slider},
|
widget::{self, Column, Row, Slider},
|
||||||
|
|
@ -97,6 +97,7 @@ pub struct Flags {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
Config(Config),
|
Config(Config),
|
||||||
|
Fullscreen,
|
||||||
Key(Modifiers, Key),
|
Key(Modifiers, Key),
|
||||||
AudioCode(usize),
|
AudioCode(usize),
|
||||||
TextCode(usize),
|
TextCode(usize),
|
||||||
|
|
@ -114,6 +115,7 @@ pub enum Message {
|
||||||
pub struct App {
|
pub struct App {
|
||||||
core: Core,
|
core: Core,
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
|
fullscreen: bool,
|
||||||
key_binds: HashMap<KeyBind, Action>,
|
key_binds: HashMap<KeyBind, Action>,
|
||||||
video: Video,
|
video: Video,
|
||||||
position: f64,
|
position: f64,
|
||||||
|
|
@ -204,6 +206,7 @@ impl Application for App {
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
core,
|
core,
|
||||||
flags,
|
flags,
|
||||||
|
fullscreen: false,
|
||||||
key_binds: key_binds(),
|
key_binds: key_binds(),
|
||||||
video,
|
video,
|
||||||
position: 0.0,
|
position: 0.0,
|
||||||
|
|
@ -218,6 +221,14 @@ impl Application for App {
|
||||||
(app, command)
|
(app, command)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_escape(&mut self) -> Command<Self::Message> {
|
||||||
|
if self.fullscreen {
|
||||||
|
return self.update(Message::Fullscreen);
|
||||||
|
} else {
|
||||||
|
Command::none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Handle application events here.
|
/// Handle application events here.
|
||||||
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
||||||
match message {
|
match message {
|
||||||
|
|
@ -228,6 +239,18 @@ impl Application for App {
|
||||||
return self.update_config();
|
return self.update_config();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::Fullscreen => {
|
||||||
|
self.fullscreen = !self.fullscreen;
|
||||||
|
self.core.window.show_headerbar = !self.fullscreen;
|
||||||
|
return window::change_mode(
|
||||||
|
window::Id::MAIN,
|
||||||
|
if self.fullscreen {
|
||||||
|
window::Mode::Fullscreen
|
||||||
|
} else {
|
||||||
|
window::Mode::Windowed
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
Message::Key(modifiers, key) => {
|
Message::Key(modifiers, key) => {
|
||||||
for (key_bind, action) in self.key_binds.iter() {
|
for (key_bind, action) in self.key_binds.iter() {
|
||||||
if key_bind.matches(modifiers, &key) {
|
if key_bind.matches(modifiers, &key) {
|
||||||
|
|
@ -311,6 +334,9 @@ impl Application for App {
|
||||||
Message::TextCode,
|
Message::TextCode,
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
widget::button::icon(widget::icon::from_name("view-fullscreen-symbolic").size(16))
|
||||||
|
.on_press(Message::Fullscreen)
|
||||||
|
.into(),
|
||||||
])
|
])
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.spacing(8)
|
.spacing(8)
|
||||||
|
|
@ -326,17 +352,20 @@ impl Application for App {
|
||||||
let hours = (time / 60) / 60;
|
let hours = (time / 60) / 60;
|
||||||
format!("{:02}:{:02}:{:02}", hours, minutes, seconds)
|
format!("{:02}:{:02}:{:02}", hours, minutes, seconds)
|
||||||
};
|
};
|
||||||
widget::container(
|
|
||||||
Column::new()
|
let mut column = widget::column::with_capacity(4)
|
||||||
.push(widget::vertical_space(Length::Fill))
|
.push(widget::vertical_space(Length::Fill))
|
||||||
.push(
|
.push(
|
||||||
VideoPlayer::new(&self.video)
|
VideoPlayer::new(&self.video)
|
||||||
.on_end_of_stream(Message::EndOfStream)
|
.on_end_of_stream(Message::EndOfStream)
|
||||||
.on_new_frame(Message::NewFrame)
|
.on_new_frame(Message::NewFrame)
|
||||||
.width(Length::Fill),
|
.width(Length::Fill),
|
||||||
)
|
)
|
||||||
.push(widget::vertical_space(Length::Fill))
|
.push(widget::vertical_space(Length::Fill));
|
||||||
.push(
|
|
||||||
|
if !self.fullscreen {
|
||||||
|
column = column.push(
|
||||||
|
widget::container(
|
||||||
Row::new()
|
Row::new()
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.spacing(8)
|
.spacing(8)
|
||||||
|
|
@ -359,10 +388,16 @@ impl Application for App {
|
||||||
widget::text(format_time(self.duration - self.position))
|
widget::text(format_time(self.duration - self.position))
|
||||||
.font(font::mono()),
|
.font(font::mono()),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
)
|
.style(theme::Container::WindowBackground),
|
||||||
.style(theme::Container::WindowBackground)
|
);
|
||||||
.into()
|
}
|
||||||
|
|
||||||
|
widget::container(column)
|
||||||
|
.style(theme::Container::Custom(Box::new(|_theme| {
|
||||||
|
widget::container::Appearance::default().with_background(Color::BLACK)
|
||||||
|
})))
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn subscription(&self) -> Subscription<Self::Message> {
|
fn subscription(&self) -> Subscription<Self::Message> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue