use std::time::Duration;
use inherit_methods_macro::inherit_methods;
use winio_elm::{Component, ComponentSender};
use winio_handle::BorrowedContainer;
use winio_primitive::{Enable, Failable, Layoutable, Point, Size, ToolTip, Visible};
use crate::{
sys,
sys::{Error, Result},
};
#[derive(Debug)]
pub struct Media {
widget: sys::Media,
}
impl Failable for Media {
type Error = Error;
}
#[inherit_methods(from = "self.widget")]
impl ToolTip for Media {
fn tooltip(&self) -> Result<String>;
fn set_tooltip(&mut self, s: impl AsRef<str>) -> Result<()>;
}
#[inherit_methods(from = "self.widget")]
impl Media {
pub fn url(&self) -> Result<String>;
pub async fn load(&mut self, url: impl AsRef<str>) -> Result<()> {
self.widget.load(url).await
}
pub fn play(&mut self) -> Result<()>;
pub fn pause(&mut self) -> Result<()>;
pub fn full_time(&self) -> Result<Option<Duration>>;
pub fn current_time(&self) -> Result<Duration>;
pub fn set_current_time(&mut self, t: Duration) -> Result<()>;
pub fn seek(&mut self, t: Duration) -> Result<()> {
self.set_current_time(t)
}
pub fn volume(&self) -> Result<f64>;
pub fn set_volume(&mut self, v: f64) -> Result<()>;
pub fn is_muted(&self) -> Result<bool>;
pub fn set_muted(&mut self, v: bool) -> Result<()>;
pub fn is_looped(&self) -> Result<bool>;
pub fn set_looped(&mut self, v: bool) -> Result<()>;
pub fn playback_rate(&self) -> Result<f64>;
pub fn set_playback_rate(&mut self, v: f64) -> Result<()>;
}
#[inherit_methods(from = "self.widget")]
impl Visible for Media {
fn is_visible(&self) -> Result<bool>;
fn set_visible(&mut self, v: bool) -> Result<()>;
}
#[inherit_methods(from = "self.widget")]
impl Enable for Media {
fn is_enabled(&self) -> Result<bool>;
fn set_enabled(&mut self, v: bool) -> Result<()>;
}
#[inherit_methods(from = "self.widget")]
impl Layoutable for Media {
fn loc(&self) -> Result<Point>;
fn set_loc(&mut self, p: Point) -> Result<()>;
fn size(&self) -> Result<Size>;
fn set_size(&mut self, v: Size) -> Result<()>;
}
#[derive(Debug)]
#[non_exhaustive]
pub enum MediaEvent {}
#[derive(Debug)]
#[non_exhaustive]
pub enum MediaMessage {}
impl Component for Media {
type Error = Error;
type Event = MediaEvent;
type Init<'a> = BorrowedContainer<'a>;
type Message = MediaMessage;
async fn init(init: Self::Init<'_>, _sender: &ComponentSender<Self>) -> Result<Self> {
let widget = sys::Media::new(init)?;
Ok(Self { widget })
}
}
winio_handle::impl_as_widget!(Media, widget);