diff --git a/src/route/stream.rs b/src/route/stream.rs index 113d8f7..b42a2b0 100644 --- a/src/route/stream.rs +++ b/src/route/stream.rs @@ -4,7 +4,7 @@ use crate::route::RouteServices; use crate::services::ndb_wrapper::{NDBWrapper, SubWrapper}; use crate::stream_info::StreamInfo; use crate::theme::{MARGIN_DEFAULT, NEUTRAL_800, ROUNDING_DEFAULT}; -use crate::widgets::{Chat, NostrWidget, StreamPlayer, StreamTitle, WriteChat}; +use crate::widgets::{Chat, NostrWidget, PlaceholderRect, StreamPlayer, StreamTitle, WriteChat}; use egui::{vec2, Align, Frame, Layout, Response, Stroke, Ui, Vec2, Widget}; use nostrdb::{Filter, Note, NoteKey, Transaction}; use std::borrow::Borrow; @@ -47,11 +47,15 @@ impl StreamPage { Vec2::new(w, h), Layout::top_down_justified(Align::Min), |ui| { - if let Some(player) = &mut self.player { - let video_h = - ((ui.available_width() / 16.0) * 9.0).min(ui.available_height() * 0.33); - ui.allocate_ui(vec2(ui.available_width(), video_h), |ui| player.ui(ui)); - } + let video_h = + ((ui.available_width() / 16.0) * 9.0).min(ui.available_height() * 0.33); + ui.allocate_ui(vec2(ui.available_width(), video_h), |ui| { + if let Some(player) = &mut self.player { + player.ui(ui) + } else { + ui.add(PlaceholderRect) + } + }); StreamTitle::new(&event).render(ui, services); if let Some(c) = self.chat.as_mut() { @@ -87,9 +91,13 @@ impl StreamPage { Layout::left_to_right(Align::TOP).with_main_justify(true), |ui| { ui.vertical(|ui| { - if let Some(player) = &mut self.player { - ui.allocate_ui(vec2(video_width, video_height), |ui| player.ui(ui)); - } + ui.allocate_ui(vec2(video_width, video_height), |ui| { + if let Some(player) = &mut self.player { + player.ui(ui) + } else { + ui.add(PlaceholderRect) + } + }); ui.add_space(10.); StreamTitle::new(&event).render(ui, services); }); diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 776af10..2488579 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -3,6 +3,7 @@ mod button; mod chat; mod chat_message; mod header; +mod placeholder_rect; mod profile; mod stream_list; mod stream_player; @@ -10,7 +11,6 @@ mod stream_tile; mod stream_title; mod text_input; mod username; -mod video_placeholder; mod write_chat; use crate::route::RouteServices; @@ -24,11 +24,11 @@ pub use self::avatar::Avatar; pub use self::button::Button; pub use self::chat::Chat; pub use self::header::Header; +pub use self::placeholder_rect::PlaceholderRect; pub use self::profile::Profile; pub use self::stream_list::StreamList; pub use self::stream_player::StreamPlayer; pub use self::stream_title::StreamTitle; pub use self::text_input::NativeTextInput; pub use self::username::Username; -pub use self::video_placeholder::VideoPlaceholder; pub use self::write_chat::WriteChat; diff --git a/src/widgets/placeholder_rect.rs b/src/widgets/placeholder_rect.rs new file mode 100644 index 0000000..15d8e3f --- /dev/null +++ b/src/widgets/placeholder_rect.rs @@ -0,0 +1,13 @@ +use crate::theme::{NEUTRAL_800, ROUNDING_DEFAULT}; +use egui::{Response, Sense, Ui, Widget}; + +pub struct PlaceholderRect; + +impl Widget for PlaceholderRect { + fn ui(self, ui: &mut Ui) -> Response { + let img_size = ui.available_size(); + let (response, painter) = ui.allocate_painter(img_size, Sense::click()); + painter.rect_filled(response.rect, ROUNDING_DEFAULT, NEUTRAL_800); + response + } +} diff --git a/src/widgets/stream_player.rs b/src/widgets/stream_player.rs index 777ad68..dd376e5 100644 --- a/src/widgets/stream_player.rs +++ b/src/widgets/stream_player.rs @@ -1,4 +1,4 @@ -use crate::widgets::VideoPlaceholder; +use crate::widgets::PlaceholderRect; use egui::{Context, Response, Ui, Vec2, Widget}; use egui_video::{Player, PlayerControls}; @@ -22,7 +22,7 @@ impl Widget for &mut StreamPlayer { if let Some(p) = self.player.as_mut() { ui.add_sized(size, p) } else { - VideoPlaceholder.ui(ui) + PlaceholderRect.ui(ui) } } } diff --git a/src/widgets/stream_tile.rs b/src/widgets/stream_tile.rs index 5e77f55..439f037 100644 --- a/src/widgets/stream_tile.rs +++ b/src/widgets/stream_tile.rs @@ -53,11 +53,11 @@ impl Widget for StreamEvent<'_> { }); } _ => { - painter.rect_filled(response.rect, 12., NEUTRAL_800); + painter.rect_filled(response.rect, ROUNDING_DEFAULT, NEUTRAL_800); } } } else { - painter.rect_filled(response.rect, 12., NEUTRAL_800); + painter.rect_filled(response.rect, ROUNDING_DEFAULT, NEUTRAL_800); } let overlay_label_pad = Vec2::new(5., 5.); diff --git a/src/widgets/video_placeholder.rs b/src/widgets/video_placeholder.rs deleted file mode 100644 index c511dfa..0000000 --- a/src/widgets/video_placeholder.rs +++ /dev/null @@ -1,19 +0,0 @@ -use egui::{Color32, Response, Rounding, Sense, Ui, Vec2, Widget}; - -pub struct VideoPlaceholder; - -impl Widget for VideoPlaceholder { - fn ui(self, ui: &mut Ui) -> Response { - let w = ui.available_width(); - let h = (w / 16.0) * 9.0; - let img_size = Vec2::new(w, h); - - let (response, painter) = ui.allocate_painter(img_size, Sense::click()); - painter.rect_filled( - response.rect, - Rounding::same(12.), - Color32::from_rgb(200, 200, 200), - ); - response - } -}