diff --git a/Cargo.lock b/Cargo.lock index d7d3cfb..48bf481 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,6 +6,18 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9fe5e32de01730eb1f6b7f5b51c17e03e2325bf40a74f754f04f130043affff" +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + [[package]] name = "alsa" version = "0.5.0" @@ -96,6 +108,12 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bed57e2090563b83ba8f83366628ce535a7584c9afa4c9fc0612a03925c6df58" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.0.1" @@ -165,9 +183,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54d78e30b388d4815220c8dd03fea5656b6c6d32adb59e89061552a102f8da1" +checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c" dependencies = [ "glob", "libc", @@ -221,6 +239,12 @@ dependencies = [ "objc", ] +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "combine" version = "4.5.2" @@ -363,6 +387,60 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "crc32fast" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "lazy_static", +] + [[package]] name = "cssparser" version = "0.27.2" @@ -425,6 +503,16 @@ dependencies = [ "syn", ] +[[package]] +name = "deflate" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" +dependencies = [ + "adler32", + "byteorder", +] + [[package]] name = "derivative" version = "2.2.0" @@ -481,15 +569,22 @@ dependencies = [ "dtoa", ] +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "femtovg" version = "0.1.2" -source = "git+https://github.com/femtovg/femtovg?branch=master#0a95404d13188c8c661dd75eecb04faad5b36ac2" +source = "git+https://github.com/femtovg/femtovg?branch=master#237553a66f68eb5b8b278b499a1b00a624cf8a94" dependencies = [ "bitflags", "fnv", "generational-arena", "glow", + "image", "imgref", "lru", "owned_ttf_parser", @@ -569,6 +664,16 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] +[[package]] +name = "gif" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a668f699973d0f573d15749b7002a9ac9e1f9c6b220e7b165601334c173d8de" +dependencies = [ + "color_quant", + "weezl", +] + [[package]] name = "gl_generator" version = "0.14.0" @@ -670,12 +775,40 @@ dependencies = [ "gl_generator", ] +[[package]] +name = "hermit-abi" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +dependencies = [ + "libc", +] + [[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "image" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "gif", + "jpeg-decoder", + "num-iter", + "num-rational", + "num-traits", + "png", + "scoped_threadpool", + "tiff", +] + [[package]] name = "imgref" version = "1.9.0" @@ -735,6 +868,15 @@ dependencies = [ "libc", ] +[[package]] +name = "jpeg-decoder" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" +dependencies = [ + "rayon", +] + [[package]] name = "js-sys" version = "0.3.50" @@ -783,9 +925,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" +checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" [[package]] name = "libloading" @@ -876,6 +1018,34 @@ dependencies = [ "libc", ] +[[package]] +name = "memoffset" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83fb6581e8ed1f85fd45c116db8405483899489e38406156c25eb743554361d" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miniz_oxide" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" +dependencies = [ + "adler32", +] + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + [[package]] name = "mio" version = "0.6.23" @@ -1056,6 +1226,38 @@ dependencies = [ "syn", ] +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.14" @@ -1065,6 +1267,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "num_enum" version = "0.4.3" @@ -1252,6 +1464,18 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "png" +version = "0.16.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" +dependencies = [ + "bitflags", + "crc32fast", + "deflate", + "miniz_oxide 0.3.7", +] + [[package]] name = "ppv-lite86" version = "0.2.10" @@ -1381,11 +1605,36 @@ dependencies = [ "libc", ] +[[package]] +name = "rayon" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + [[package]] name = "redox_syscall" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" dependencies = [ "bitflags", ] @@ -1461,6 +1710,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + [[package]] name = "scopeguard" version = "1.1.0" @@ -1546,9 +1801,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "syn" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87" +checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" dependencies = [ "proc-macro2", "quote", @@ -1575,6 +1830,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tiff" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" +dependencies = [ + "jpeg-decoder", + "miniz_oxide 0.4.4", + "weezl", +] + [[package]] name = "tiralabra" version = "0.1.0" @@ -1619,7 +1885,7 @@ checksum = "62ddb402ac6c2af6f7a2844243887631c4e94b51585b229fcfddb43958cd55ca" [[package]] name = "tuix" version = "0.1.0" -source = "git+https://github.com/geom3trik/tuix?branch=experiment#f30f1c325cf43a61696a4df8fc75207dc1808e3c" +source = "git+https://github.com/geom3trik/tuix?branch=experiment#5abe0ff88f5d5bf51628362b0a7cf03669cf89f3" dependencies = [ "tuix_core", "tuix_glutin", @@ -1629,11 +1895,12 @@ dependencies = [ [[package]] name = "tuix_core" version = "0.1.0" -source = "git+https://github.com/geom3trik/tuix?branch=experiment#f30f1c325cf43a61696a4df8fc75207dc1808e3c" +source = "git+https://github.com/geom3trik/tuix?branch=experiment#5abe0ff88f5d5bf51628362b0a7cf03669cf89f3" dependencies = [ "cssparser", "femtovg", "fnv", + "image", "keyboard-types", "num-traits", ] @@ -1641,7 +1908,7 @@ dependencies = [ [[package]] name = "tuix_glutin" version = "0.1.0" -source = "git+https://github.com/geom3trik/tuix?branch=experiment#f30f1c325cf43a61696a4df8fc75207dc1808e3c" +source = "git+https://github.com/geom3trik/tuix?branch=experiment#5abe0ff88f5d5bf51628362b0a7cf03669cf89f3" dependencies = [ "femtovg", "glutin", @@ -1652,7 +1919,7 @@ dependencies = [ [[package]] name = "tuix_inspector_derive" version = "0.1.0" -source = "git+https://github.com/geom3trik/tuix?branch=experiment#f30f1c325cf43a61696a4df8fc75207dc1808e3c" +source = "git+https://github.com/geom3trik/tuix?branch=experiment#5abe0ff88f5d5bf51628362b0a7cf03669cf89f3" dependencies = [ "proc-macro2", "quote", @@ -1661,9 +1928,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" dependencies = [ "matches", ] @@ -1880,6 +2147,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "weezl" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a32b378380f4e9869b22f0b5177c68a5519f03b3454fde0b291455ddbae266c" + [[package]] name = "winapi" version = "0.2.8" diff --git a/examples/demo.rs b/examples/demo.rs index e2d86d1..3bd3bc0 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -20,16 +20,12 @@ fn main() -> Result<(), Box> { let app = Application::new(move |state, window| { state.add_theme(style::themes::DEFAULT_THEME); state.add_theme(THEME); - window.set_flex_direction(state, FlexDirection::Row); + window.set_layout_type(state, LayoutType::Horizontal); Control::default().build(state, window.entity(), |builder| { - builder - .set_width(Length::Percentage(0.2)) - .set_min_width(Length::Pixels(200.)) + builder.set_width(Stretch(1.)).set_min_width(Pixels(200.)) }); plot.build(state, window.entity(), |builder| { - builder - .set_flex_grow(1.0) - .set_align_self(AlignSelf::Stretch) + builder.set_width(Stretch(4.)).set_height(Stretch(1.)) }); window.set_title("Tiralabra demo").set_inner_size(800, 600); }); @@ -116,7 +112,7 @@ impl Plot { stabilize_enabled: true, show_memory: false, display_decay: decay_time_to_factor(0.2), - memory_decay: decay_time_to_factor(0.2), + memory_decay: decay_time_to_factor(0.8), }, PlotIngest { publish_handle: buf_in, @@ -137,10 +133,7 @@ impl Widget for Plot { } fn on_draw(&mut self, state: &mut State, entity: Entity, canvas: &mut Canvas) { state.insert_event(Event::new(WindowEvent::Redraw).target(Entity::root())); - let x = state.data.get_posx(entity); - let y = state.data.get_posy(entity); - let h = state.data.get_height(entity); - let w = state.data.get_width(entity); + let BoundingBox { x, y, h, w } = state.data.get_bounds(entity); let buf = self.consume_handle.read(); let offset; @@ -152,12 +145,10 @@ impl Widget for Plot { offset = 0; } let factor = self.display_decay; - //println!("d{}", factor); for (i, tr) in self.last_displayed.iter_mut().enumerate() { *tr = factor * buf[i + offset] + (1. - factor) * *tr; } let factor = self.memory_decay; - //println!("f{}", factor); for (i, tr) in self.memory.iter_mut().enumerate() { *tr = factor * buf[i + offset] + (1. - factor) * *tr; } @@ -173,7 +164,7 @@ impl Widget for Plot { for (x, y) in points { path.line_to(x, y); } - canvas.stroke_path(&mut path, Paint::color(Color::rgb(12, 120, 230))); + canvas.stroke_path(&mut path, Paint::color(Color::rgb(12, 170, 255))); } let mut path = Path::new(); let mut points = self @@ -212,7 +203,14 @@ impl Widget for Plot { #[derive(Default)] struct Control { - memory_slider: Entity + memory_over: bool, + memory_press: bool, +} + +#[derive(Clone, PartialEq, Debug)] +enum MemoryHoverEvent { + OverChange(bool), + PressChange(bool), } impl Widget for Control { @@ -220,7 +218,7 @@ impl Widget for Control { fn on_build(&mut self, state: &mut State, entity: Entity) -> Self::Ret { entity.set_element(state, "control"); entity.set_flex_direction(state, FlexDirection::Column); - let checkbox = HBox::new().build(state, entity, |builder| builder.class("check")); + let checkbox = Row::new().build(state, entity, |builder| builder.class("check")); Checkbox::new(true) .on_checked(Event::new(PlotControlEvent::Stabilize(true)).propagate(Propagation::All)) .on_unchecked( @@ -228,44 +226,47 @@ impl Widget for Control { ) .build(state, checkbox, |builder| builder); Label::new("Vakauta").build(state, checkbox, |builder| builder); - let checkbox = HBox::new().build(state, entity, |builder| builder.class("check")); - Checkbox::new(false) - .on_checked(Event::new(PlotControlEvent::ShowMemory(true)).propagate(Propagation::All)) - .on_unchecked(Event::new(PlotControlEvent::ShowMemory(false)).propagate(Propagation::All)) - .build(state, checkbox, |builder| builder); - Label::new("Näytä muisti").build(state, checkbox, |builder| builder); Label::new("Näytön vaimenemisaika").build(state, entity, |builder| builder); Slider::new() .with_min(0.) .with_max(2.) .with_initial_value(0.2) - .on_change(move |val| { - Event::new(PlotControlEvent::DisplayDecayTime(val)).propagate(Propagation::All).target(entity) + .on_changing(move |val| { + Event::new(PlotControlEvent::DisplayDecayTime(val)) + .propagate(Propagation::All) + .target(entity) }) .build(state, entity, |builder| builder); Label::new("Muistin vaimenemisaika").build(state, entity, |builder| builder); - self.memory_slider = Slider::new() + Slider::new() .with_min(0.) .with_max(2.) - .with_initial_value(0.2) - .on_change(move |val| { - Event::new(PlotControlEvent::MemoryDecayTime(val)).propagate(Propagation::All).target(entity) + .with_initial_value(0.8) + .on_over(Event::new(MemoryHoverEvent::OverChange(true)).direct(entity)) + .on_out(Event::new(MemoryHoverEvent::OverChange(false)).direct(entity)) + .on_press(Event::new(MemoryHoverEvent::PressChange(true)).direct(entity)) + .on_release(Event::new(MemoryHoverEvent::PressChange(false)).direct(entity)) + .on_changing(move |val| { + Event::new(PlotControlEvent::MemoryDecayTime(val)) + .propagate(Propagation::All) + .target(entity) }) .build(state, entity, |builder| builder); entity } - // fn on_event(&mut self, state: &mut State, entity: Entity, event: &mut Event) { - // if let Some(mouse_event) = event.message.downcast() { - // match mouse_event { - // WindowEvent::MouseOver if state.hierarchy.event.target == self.memory_slider => { - // println!("moi"); - // } - // WindowEvent::MouseOut if event.target == self.memory_slider => { - // println!("heips"); - // } - // _ => {} - // } - // } - // } + fn on_event(&mut self, state: &mut State, _entity: Entity, event: &mut Event) { + if let Some(ev) = event.message.downcast() { + match ev { + MemoryHoverEvent::OverChange(status) => self.memory_over = *status, + MemoryHoverEvent::PressChange(status) => self.memory_press = *status, + } + state.insert_event( + Event::new(PlotControlEvent::ShowMemory( + self.memory_over || self.memory_press, + )) + .propagate(Propagation::All), + ); + } + } } diff --git a/examples/theme.css b/examples/theme.css index 9e6fb58..d32b563 100644 --- a/examples/theme.css +++ b/examples/theme.css @@ -1,11 +1,12 @@ control { - border-width: 2px; border-color: #383838; - padding: 10px; - margin-left: -2px; - margin-top: -2px; - margin-bottom: -2px; + child-space: 10px; + child-between: 12px; + border-width: 2px; + left: -2px; + top: -2px; + bottom: -2px; } label { @@ -14,17 +15,24 @@ label { } .check { - margin-bottom: 20px; + width: 1s; + child-between: 5px; } .check label { - align-self: center; - flex-grow: 1; - margin-left: 5px; + top: 1s; + bottom: 1s; + width: 1s; } -control slider { - margin-top: 10px; - margin-bottom: 20px; +slider { + top: 5px; +} + +slider>.track { + left: 2px; +} +slider>.track>.active { + left: -2px; }