1#![cfg(target_os = "linux")]
7#![warn(missing_docs)]
8
9use std::error::Error;
10use std::fmt;
11
12use whisker::{Element, ElementModuleDefinition};
13
14pub use gtk4;
15pub use module::{LinuxEventEmitter, LinuxModuleDefinition, LinuxView, LinuxViewDefinition};
16
17mod app;
18mod color;
19mod cursor;
20mod module;
21mod node;
22mod paint;
23mod scene;
24mod text;
25
26#[cfg(all(test, feature = "host-conformance"))]
27#[path = "../tests/host_conformance/mod.rs"]
28mod host_conformance_tests;
29
30#[derive(Clone, Debug)]
32pub struct LinuxAppConfig {
33 title: String,
34 width: i32,
35 height: i32,
36 background_rgb: [u8; 3],
37 modules: Vec<LinuxModuleDefinition>,
38}
39
40impl LinuxAppConfig {
41 pub fn new(title: impl Into<String>) -> Self {
43 Self {
44 title: title.into(),
45 width: 1024,
46 height: 720,
47 background_rgb: [255, 255, 255],
48 modules: Vec::new(),
49 }
50 }
51
52 pub fn with_background_rgb(mut self, red: u8, green: u8, blue: u8) -> Self {
54 self.background_rgb = [red, green, blue];
55 self
56 }
57
58 pub fn with_module(
60 mut self,
61 _elements: ElementModuleDefinition,
62 host: impl Into<LinuxModuleDefinition>,
63 ) -> Self {
64 self.modules.push(host.into());
65 self
66 }
67}
68
69#[derive(Debug)]
71pub struct LinuxError(pub(crate) String);
72
73impl fmt::Display for LinuxError {
74 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
75 formatter.write_str(&self.0)
76 }
77}
78
79impl Error for LinuxError {}
80
81pub fn run(config: LinuxAppConfig, application: fn() -> Element) -> Result<(), LinuxError> {
83 run_with_application_hash(config, application, || 0)
84}
85
86pub fn run_with_application_hash(
88 config: LinuxAppConfig,
89 application: fn() -> Element,
90 application_hash: fn() -> u64,
91) -> Result<(), LinuxError> {
92 app::run_application(config, application, application_hash)
93}