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