diff --git a/Cargo.toml b/Cargo.toml index 509b88d..ece5575 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +druid = { version = "0.7.0", features = ["image"] } +palette = "0.6.0" +image = "0.23.14" diff --git a/emma_and_mujika.png b/emma_and_mujika.png new file mode 100644 index 0000000..4255c1d Binary files /dev/null and b/emma_and_mujika.png differ diff --git a/src/main.rs b/src/main.rs index e7a11a9..535c933 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,68 @@ -fn main() { - println!("Hello, world!"); +use std::borrow::Cow; +use std::fs::File; +use std::io::Read; +use std::sync::{Arc, Mutex}; + +use druid::piet::{Brush, FixedGradient, ImageFormat, InterpolationMode, IntoBrush, PaintBrush}; +use druid::widget::{Align, Flex, Image, Label, Painter, TextBox}; +use druid::{ + AppLauncher, Color, Data, Env, ImageBuf, Lens, LocalizedString, RenderContext, Widget, + WidgetExt, WindowDesc, +}; +use image::io::Reader as ImageReader; +use image::GenericImageView; + +struct Tab { + buf: ImageBuf, +} + +impl IntoBrush

for Tab { + fn make_brush<'a>( + &'a self, + piet: &mut P, + bbox: impl FnOnce() -> druid::Rect, + ) -> Cow<'a, P::Brush> { + let ctx = self.to_owned().buf.to_image(piet); + piet.draw_image(&ctx, bbox(), InterpolationMode::Bilinear); + Cow::Owned(piet.solid_brush(Color::rgba(0.0, 0.0, 0.0, 1.0))) + } +} + +struct KamintaState { + tabs: Vec, +} + +const TEST_IMAGE_PATH: &str = "emma_and_mujika.png"; + +fn main() { + let mut app_state = KamintaState { tabs: vec![] }; + let img = ImageReader::open(TEST_IMAGE_PATH) + .unwrap() + .decode() + .unwrap(); + app_state.tabs.push(Tab { + buf: ImageBuf::from_raw( + img.to_bytes(), + ImageFormat::Rgb, + img.dimensions().0.try_into().unwrap(), + img.dimensions().1.try_into().unwrap(), + ), + }); + println!["HERE ===================="]; + + let main_window = WindowDesc::new(build_root_widget) + .title("Kaminta") + .window_size((800.0, 600.0)); + + AppLauncher::with_window(main_window) + .launch(Arc::new(Mutex::new(app_state))) + .expect("failed to launch"); +} + +fn build_root_widget() -> impl Widget>> { + let img = Painter::new(|ctx, data: &Arc>, env| { + let bounds = ctx.size().to_rect(); + ctx.fill(bounds, data.lock().unwrap().tabs.get(0).unwrap()); + }); + img }