diff --git a/core/src/lib.rs b/core/src/lib.rs index 980b946..62992b9 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -18,7 +18,7 @@ mod num; mod orientation; mod primitive; mod render; -mod state; +mod typed; mod ui; mod widget; diff --git a/core/src/state.rs b/core/src/typed.rs similarity index 100% rename from core/src/state.rs rename to core/src/typed.rs diff --git a/core/src/ui/active.rs b/core/src/ui/active.rs new file mode 100644 index 0000000..76c7438 --- /dev/null +++ b/core/src/ui/active.rs @@ -0,0 +1,23 @@ +use crate::{LayerId, Len, MaskIdx, PrimitiveHandle, TextureHandle, UiRegion, UiVec2, WidgetId}; + +/// important non rendering data for retained drawing +#[derive(Debug)] +pub struct ActiveData { + pub id: WidgetId, + pub region: UiRegion, + pub parent: Option, + pub textures: Vec, + pub primitives: Vec, + pub children: Vec, + pub resize: ResizeRef, + pub mask: MaskIdx, + pub layer: LayerId, +} + +/// stores information for children about the highest level parent that needed their size +/// so that they can redraw the parent if their size changes +#[derive(Clone, Copy, Debug, Default)] +pub struct ResizeRef { + pub x: Option<(WidgetId, (UiVec2, Len))>, + pub y: Option<(WidgetId, (UiVec2, Len))>, +} diff --git a/core/src/ui/draw_state.rs b/core/src/ui/draw_state.rs index f6b0a94..338584d 100644 --- a/core/src/ui/draw_state.rs +++ b/core/src/ui/draw_state.rs @@ -1,7 +1,7 @@ use crate::{ ActiveData, Len, Painter, SizeCtx, Ui, UiRegion, UiVec2, WidgetId, render::MaskIdx, - ui::painter::ResizeRef, + ui::ResizeRef, util::{HashMap, HashSet}, }; use std::ops::{Deref, DerefMut}; diff --git a/core/src/ui/mod.rs b/core/src/ui/mod.rs index 94a0ac3..4f1ecdb 100644 --- a/core/src/ui/mod.rs +++ b/core/src/ui/mod.rs @@ -10,11 +10,14 @@ use std::{ sync::mpsc::{Receiver, Sender, channel}, }; +mod active; mod draw_state; mod painter; mod size; +mod state; -pub use painter::{ActiveData, Painter}; +pub use active::*; +pub use painter::Painter; pub use size::*; pub struct Ui { diff --git a/core/src/ui/painter.rs b/core/src/ui/painter.rs index 83bbca4..3256b2d 100644 --- a/core/src/ui/painter.rs +++ b/core/src/ui/painter.rs @@ -1,5 +1,5 @@ use crate::{ - Axis, Len, RenderedText, Size, SizeCtx, TextAttrs, TextBuffer, TextData, TextureHandle, Ui, + Axis, Len, RenderedText, Size, SizeCtx, TextAttrs, TextBuffer, TextData, TextureHandle, UiRegion, UiVec2, WidgetHandle, WidgetId, render::{Mask, MaskIdx, Primitive, PrimitiveHandle, PrimitiveInst}, ui::draw_state::DrawState, @@ -21,28 +21,6 @@ pub struct Painter<'a, 'b, State> { pub(super) id: WidgetId, } -/// stores information for children about the highest level parent that needed their size -/// so that they can redraw the parent if their size changes -#[derive(Clone, Copy, Debug, Default)] -pub struct ResizeRef { - pub x: Option<(WidgetId, (UiVec2, Len))>, - pub y: Option<(WidgetId, (UiVec2, Len))>, -} - -/// important non rendering data for retained drawing -#[derive(Debug)] -pub struct ActiveData { - pub id: WidgetId, - pub region: UiRegion, - pub parent: Option, - pub textures: Vec, - pub primitives: Vec, - pub children: Vec, - pub resize: ResizeRef, - pub mask: MaskIdx, - pub layer: usize, -} - impl<'a, 'c, State: 'static> Painter<'a, 'c, State> { fn primitive_at(&mut self, primitive: P, region: UiRegion) { let h = self.state.layers.write( @@ -168,6 +146,3 @@ impl<'a, 'c, State: 'static> Painter<'a, 'c, State> { ) } } - -impl Ui { -} diff --git a/core/src/ui/state.rs b/core/src/ui/state.rs new file mode 100644 index 0000000..1db0d9d --- /dev/null +++ b/core/src/ui/state.rs @@ -0,0 +1,3 @@ +pub struct DynState { + +} diff --git a/readme.md b/readme.md index 91b3d16..5e2cbe9 100644 --- a/readme.md +++ b/readme.md @@ -1,22 +1,25 @@ # iris -my take on a rust ui library (also my first ui library) +My experimental attempt at a rust ui library (also my first ui library). -it's called iris because it's the structure around what you actually want to display and colorful +It's currently designed around using retained data structures (widgets), rather than diffing generated trees from data like xilem or iced. This is an experiment and I'm not sure if it's a good idea or not. -there's a `main.rs` that runs a testing window, so can just `cargo run` to see it working +There's a `main.rs` that runs a testing window, so you can just `cargo run` to see it working. -goals, in general order: +Goals, in general order: 1. does what I want it to (text, images, video, animations) 2. very easy to use ignoring ergonomic ref counting 3. reasonably fast / efficient (a lot faster than electron, save battery life) -not targeting web rn cause wanna use actual nice gpu features & entire point of this is to make desktop apps +## dev details + +not targeting web rn cause wanna use actual nice gpu features & entire point of this is to make desktop apps / not need a web browser general ideas trynna use rn / experiment with: - retained mode -- specifically designed around wgpu +- specifically designed around wgpu so there's no translation - postfix functions for most things to prevent unreadable indentation (going very well) +- events can be done directly where you draw the widgets - almost no macros in user code & actual LSP typechecking (variadic generics if you can hear me please save us) - relative anchor + absolute offset coord system (+ "rest" / leftover during widget layout) - single threaded ui & pass context around to make non async usage straightforward (pretty unsure about this) @@ -24,3 +27,5 @@ general ideas trynna use rn / experiment with: under heavy initial development so not gonna try to explain status, maybe check TODO for that; sizable chance it gets a rewrite once I know everything I need and what seems to work best + +it's called iris because it's the structure around what you actually want to display and colorful diff --git a/src/lib.rs b/src/lib.rs index 3aa71d4..fd0a774 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ pub mod default; pub mod event; -pub mod state; +pub mod typed; pub mod widget; pub use iris_core; @@ -37,5 +37,5 @@ pub mod prelude { pub use widget::*; pub use iris_core::util::Vec2; - pub use state::*; + pub use typed::*; } diff --git a/src/state.rs b/src/typed.rs similarity index 100% rename from src/state.rs rename to src/typed.rs