fix: video placeholder

This commit is contained in:
kieran 2024-11-05 13:35:31 +00:00
parent e718b8e322
commit 10cd15d942
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
6 changed files with 36 additions and 34 deletions

View File

@ -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));
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| {
ui.allocate_ui(vec2(video_width, video_height), |ui| {
if let Some(player) = &mut self.player {
ui.allocate_ui(vec2(video_width, video_height), |ui| player.ui(ui));
player.ui(ui)
} else {
ui.add(PlaceholderRect)
}
});
ui.add_space(10.);
StreamTitle::new(&event).render(ui, services);
});

View File

@ -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;

View File

@ -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
}
}

View File

@ -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)
}
}
}

View File

@ -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.);

View File

@ -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
}
}