Skip to content

Commit

Permalink
Publish v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Aug 16, 2023
1 parent 7b86682 commit b17347b
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 61 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[package]
name = "concoct"
version = "0.2.0"
version = "0.4.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Generic UI compiler and runtime library"
repository = "https://github.com/concoct-rs/concoct"

[features]
full = []
gl = ["dep:gl", "dep:glutin", "dep:glutin-winit", "dep:raw-window-handle", "dep:slotmap", "dep:winit"]

[dependencies]
tokio = { version = "1.29.1", features = ["full"] }
accesskit = "0.11.1"
gl = "0.14.0"
glutin = "0.30.9"
glutin-winit = "0.3.0"
raw-window-handle = "0.5.2"
gl = { version = "0.14.0", optional = true }
glutin = { version = "0.30.9", optional = true }
glutin-winit = { version = "0.3.0", optional = true }
raw-window-handle = { version = "0.5.2", optional = true }
skia-safe = { version = "0.64.0", features = ["gl"] }
slotmap = "1.0.6"
slotmap = { version = "1.0.6", optional = true }
taffy = "0.3.12"
winit = "0.28.6"
winit = { version = "0.28.6", optional = true }
3 changes: 1 addition & 2 deletions examples/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use accesskit::Role;
use concoct::{
clickable,
view::{remember, Canvas, View},
view::{clickable, remember, Canvas, View},
Renderer,
};
use skia_safe::{Color4f, Paint};
Expand Down
49 changes: 2 additions & 47 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
#[cfg(feature = "gl")]
mod renderer;

use std::any::Any;

use accesskit::Role;
#[cfg(feature = "gl")]
pub use renderer::{Event, Renderer};
use view::{Id, View};

pub mod view;

pub fn clickable<F, V>(_role: Role, on_click: F, view: V) -> EventHandler<F, V> {
EventHandler::new(on_click, view)
}

pub struct EventHandler<F, V> {
on_event: F,
view: V,
}

impl<F, V> EventHandler<F, V> {
pub fn new(on_event: F, view: V) -> Self {
Self { on_event, view }
}
}

impl<T, A, F, V> View<T, A> for EventHandler<F, V>
where
V: View<T, A>,
F: FnMut(&mut T),
{
fn build(&mut self, cx: &mut view::BuildContext) -> Id {
self.view.build(cx)
}

fn rebuild(&mut self, cx: &mut view::BuildContext, old: &mut Self) {
self.view.rebuild(cx, &mut old.view)
}

fn layout(&mut self, cx: &mut view::LayoutContext, id: Id) {
self.view.layout(cx, id)
}

fn paint(&mut self, taffy: &taffy::Taffy, canvas: &mut skia_safe::Canvas) {
self.view.paint(taffy, canvas)
}

fn message(&mut self, state: &mut T, id_path: &[Id], message: &dyn Any) -> Option<A> {
(self.on_event)(state);
self.view.message(state, id_path, message)
}
}
6 changes: 2 additions & 4 deletions src/view/canvas.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use super::{Id, LayoutContext, View};

use skia_safe::Rect;
use slotmap::DefaultKey;
use std::any::Any;
use taffy::{
prelude::Layout,
prelude::{Layout, Node},
style::{Dimension, Style},
Taffy,
};

/// Canvas element.
/// This lets you draw directly to the skia canvas.
pub struct Canvas<F> {
layout_key: Option<DefaultKey>,
layout_key: Option<Node>,
draw: F,
style: Style,
}
Expand Down
46 changes: 46 additions & 0 deletions src/view/handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::any::Any;
use accesskit::Role;
use super::{View, BuildContext, LayoutContext, Id};


pub fn clickable<F, V>(_role: Role, on_click: F, view: V) -> EventHandler<F, V> {
EventHandler::new(on_click, view)
}

pub struct EventHandler<F, V> {
on_event: F,
view: V,
}

impl<F, V> EventHandler<F, V> {
pub fn new(on_event: F, view: V) -> Self {
Self { on_event, view }
}
}

impl<T, A, F, V> View<T, A> for EventHandler<F, V>
where
V: View<T, A>,
F: FnMut(&mut T),
{
fn build(&mut self, cx: &mut BuildContext) -> Id {
self.view.build(cx)
}

fn rebuild(&mut self, cx: &mut BuildContext, old: &mut Self) {
self.view.rebuild(cx, &mut old.view)
}

fn layout(&mut self, cx: &mut LayoutContext, id: Id) {
self.view.layout(cx, id)
}

fn paint(&mut self, taffy: &taffy::Taffy, canvas: &mut skia_safe::Canvas) {
self.view.paint(taffy, canvas)
}

fn message(&mut self, state: &mut T, id_path: &[Id], message: &dyn Any) -> Option<A> {
(self.on_event)(state);
self.view.message(state, id_path, message)
}
}
3 changes: 3 additions & 0 deletions src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub use adapt::{Adapt, AdaptThunk};
mod canvas;
pub use canvas::Canvas;

mod handler;
pub use handler::{EventHandler, clickable};

pub mod layout_context;
pub use layout_context::LayoutContext;

Expand Down

0 comments on commit b17347b

Please sign in to comment.