3 Commits

Author SHA1 Message Date
dab6cf298a Merge branch 'work' of git.arirex.me:shadowcat/iris into work 2026-02-17 18:14:38 -05:00
38d896d44d selector 2026-02-17 18:14:19 -05:00
7b54aaf3c4 readme 2026-01-29 16:39:19 -05:00
3 changed files with 52 additions and 2 deletions

View File

@@ -4,12 +4,12 @@ My experimental attempt at a rust ui library (also my first ui library).
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 you can just `cargo run` to see it working.
Examples are in `examples`, eg. `cargo run --example tabs`.
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)
3. reasonably fast / efficient (a lot faster than electron, save battery life, try to beat iced and xilem)
## dev details

View File

@@ -5,6 +5,7 @@ mod ptr;
mod rect;
mod text;
mod trait_fns;
mod selector;
pub use image::*;
pub use mask::*;
@@ -13,3 +14,4 @@ pub use ptr::*;
pub use rect::*;
pub use text::*;
pub use trait_fns::*;
pub use selector::*;

48
src/widget/selector.rs Normal file
View File

@@ -0,0 +1,48 @@
use std::hash::Hash;
use iris_core::util::HashMap;
use crate::prelude::*;
pub struct WidgetSelector<T> {
current: (T, StrongWidget),
map: HashMap<T, StrongWidget>,
}
impl<T: Hash + Eq> WidgetSelector<T> {
pub fn new(key: T, widget: StrongWidget) -> Self {
Self {
current: (key, widget),
map: Default::default(),
}
}
pub fn set(&mut self, key: T, widget: StrongWidget) {
self.map.insert(key, widget);
}
pub fn select(&mut self, key: T) -> bool {
if let Some(val) = self.map.remove(&key) {
let mut new = (key, val);
std::mem::swap(&mut new, &mut self.current);
self.map.insert(new.0, new.1);
true
} else {
false
}
}
}
impl<T: 'static> Widget for WidgetSelector<T> {
fn draw(&mut self, painter: &mut Painter) {
painter.widget(&self.current.1);
}
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
ctx.width(&self.current.1)
}
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
ctx.height(&self.current.1)
}
}