#![cfg(target_os = "linux")]
#![warn(missing_docs)]
use std::error::Error;
use std::fmt;
use whisker::{Element, ElementModuleDefinition};
pub use gtk4;
pub use module::{LinuxEventEmitter, LinuxModuleDefinition, LinuxView, LinuxViewDefinition};
mod app;
mod color;
mod cursor;
mod module;
mod node;
mod paint;
mod scene;
mod text;
#[cfg(all(test, feature = "host-conformance"))]
#[path = "../tests/host_conformance/mod.rs"]
mod host_conformance_tests;
#[derive(Clone, Debug)]
pub struct LinuxAppConfig {
title: String,
width: i32,
height: i32,
background_rgb: [u8; 3],
modules: Vec<LinuxModuleDefinition>,
}
impl LinuxAppConfig {
pub fn new(title: impl Into<String>) -> Self {
Self {
title: title.into(),
width: 1024,
height: 720,
background_rgb: [255, 255, 255],
modules: Vec::new(),
}
}
pub fn with_background_rgb(mut self, red: u8, green: u8, blue: u8) -> Self {
self.background_rgb = [red, green, blue];
self
}
pub fn with_module(
mut self,
_elements: ElementModuleDefinition,
host: impl Into<LinuxModuleDefinition>,
) -> Self {
self.modules.push(host.into());
self
}
}
#[derive(Debug)]
pub struct LinuxError(pub(crate) String);
impl fmt::Display for LinuxError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.0)
}
}
impl Error for LinuxError {}
pub fn run(config: LinuxAppConfig, application: fn() -> Element) -> Result<(), LinuxError> {
run_with_application_hash(config, application, || 0)
}
pub fn run_with_application_hash(
config: LinuxAppConfig,
application: fn() -> Element,
_application_hash: fn() -> u64,
) -> Result<(), LinuxError> {
app::run_application(config, application)
}