Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree #1

Merged
merged 22 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
members = [
"macros",
"api",
"testable",
# "testable",
"lib"
]
4 changes: 2 additions & 2 deletions api/src/callbacks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{controls, types};
use crate::{controls, types::{adapter}};

pub use crate::inner::{
auto::OnFrame,
Expand Down Expand Up @@ -111,4 +111,4 @@ macro_rules! callback {
//callback!(OnFrame, FnMut(&mut dyn controls::Window) -> bool);
callback!(Action, FnMut(&mut dyn controls::Member) -> bool);

on!(ItemChange (&mut MemberBase, types::Change));
on!(ItemChange (&mut MemberBase, adapter::Change));
1 change: 1 addition & 0 deletions api/src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ pub use crate::inner::{
closeable::{Closeable, MaybeCloseable},
adapted::{Adapted, MaybeAdapted},
list::{List, MaybeList, NewList},
tree::{Tree, MaybeTree, NewTree},
};
14 changes: 7 additions & 7 deletions api/src/inner/adapted.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{callbacks, types, utils};
use crate::{callbacks, types::{self, adapter}, utils};

use super::auto::{HasInner, Abstract};
use super::container::{Container, ContainerInner, AContainer};
Expand All @@ -14,12 +14,12 @@ define_abstract! {
fn adapter(&self) -> &dyn types::Adapter;
fn adapter_mut(&mut self) -> &mut dyn types::Adapter;

fn len(&self) -> usize {
self.adapter().len()
fn len_at(&self, indexes: &[usize]) -> Option<usize> {
self.adapter().len_at(indexes)
}
}
inner: {
fn on_item_change(&mut self, base: &mut MemberBase, value: types::Change);
fn on_item_change<'a>(&mut self, base: &mut MemberBase, value: adapter::Change<'a>);
}
}
}
Expand All @@ -37,7 +37,7 @@ impl<T: AdaptedInner + 'static> AAdapted<T> {
t
}
#[inline]
fn on_item_change(base: &mut MemberBase, value: types::Change) {
fn on_item_change(base: &mut MemberBase, value: adapter::Change) {
let this = base.as_any_mut().downcast_mut::<AMember<AControl<AContainer<AAdapted<T>>>>>().unwrap();
let this2 = this as *mut AMember<AControl<AContainer<AAdapted<T>>>>; // bck is stupid;
let inner = unsafe {&mut *this2}.inner_mut().inner_mut().inner_mut().inner_mut();
Expand All @@ -62,7 +62,7 @@ pub struct AdapterInnerCallback {
on_item_change: callbacks::OnItemChange,
}
impl AdapterInnerCallback {
pub fn on_item_change(&mut self, value: types::Change) {
pub fn on_item_change(&mut self, value: adapter::Change) {
if !self.target.is_null() {
(self.on_item_change.as_mut())(unsafe {&mut *self.target}, value)
}
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<T: AdaptedInner> Adapted for AMember<AControl<AContainer<AAdapted<T>>>> {
}
impl<II: AdaptedInner, T: HasInner<I = II> + Abstract + 'static> AdaptedInner for T {
#[inline]
fn on_item_change(&mut self, base: &mut MemberBase, value: types::Change) {
fn on_item_change(&mut self, base: &mut MemberBase, value: adapter::Change) {
self.inner_mut().on_item_change(base, value)
}
}
23 changes: 21 additions & 2 deletions api/src/inner/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ pub trait AdapterInner: 'static {
}

pub trait Adapter: AdapterInner + AsAny {
fn len(&self) -> usize;
fn spawn_item_view(&mut self, i: usize, parent: &dyn Adapted) -> Box<dyn Control>;
fn len_at(&self, indexes: &[usize]) -> Option<usize>;
fn node_at(&self, indexes: &[usize]) -> Option<Node>;
fn spawn_item_view(&mut self, indexes: &[usize], parent: &dyn Adapted) -> Option<Box<dyn Control>>;

fn for_each<'a, 'b:'a, 'c: 'b>(&'c self, f: &'a mut dyn FnNodeItem);
}

pub trait FnNodeItem: for<'i, 'v> FnMut(&'i [usize], &'v Node) {}

impl<F: for<'i, 'v> FnMut(&'i [usize], &'v Node)> FnNodeItem for F {}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Node {
Leaf,
Branch(bool),
}
#[derive(Debug, Clone, PartialEq)]
pub enum Change<'a> {
Added(&'a [usize], Node),
Removed(&'a [usize]),
Edited(&'a [usize], Node)
}
16 changes: 8 additions & 8 deletions api/src/inner/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ define! {
outer: {
fn name(&self) -> ::std::borrow::Cow<'_, str>;
fn start(&mut self);
fn find_member_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Member>;
fn find_member(&self, arg: types::FindBy) -> Option<&dyn Member>;
fn find_member_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Member>;
fn find_member<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Member>;
fn exit(self: Box<Self>);
fn prepare_exit(&mut self);
fn on_frame(&mut self, cb: OnFrame);
Expand All @@ -49,8 +49,8 @@ define! {
fn name(&self) -> Cow<'_, str>;
fn start(&mut self);

fn find_member_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Member>;
fn find_member(&self, arg: types::FindBy) -> Option<&dyn Member>;
fn find_member_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Member>;
fn find_member<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Member>;

fn exit(&mut self);

Expand Down Expand Up @@ -138,11 +138,11 @@ impl<T: ApplicationInner> Application for AApplication<T> {
self.inner_mut().start()
}
#[inline]
fn find_member_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Member> {
fn find_member_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Member> {
self.inner_mut().find_member_mut(arg)
}
#[inline]
fn find_member(&self, arg: types::FindBy) -> Option<&dyn Member> {
fn find_member<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Member> {
self.inner().find_member(arg)
}
#[inline]
Expand Down Expand Up @@ -229,10 +229,10 @@ impl<II: ApplicationInner, T: HasInner<I = II> + Abstract + 'static> Application
self.inner_mut().start()
}

fn find_member_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Member> {
fn find_member_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Member> {
self.inner_mut().find_member_mut(arg)
}
fn find_member(&self, arg: types::FindBy) -> Option<&dyn Member> {
fn find_member<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Member> {
self.inner().find_member(arg)
}

Expand Down
39 changes: 25 additions & 14 deletions api/src/inner/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ use super::member::{AMember, Member, MemberInner};
use super::container_single::{MaybeSingleContainer};
use super::container_multi::{MaybeMultiContainer};
use super::adapted::{MaybeAdapted};
use super::has_native_id::HasNativeIdInner;

define_abstract! {
Container: Member {
outer: {
fn find_control_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Control>;
fn find_control(&self, arg: types::FindBy) -> Option<&dyn Control>;
fn find_control_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Control>;
fn find_control<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Control>;
unsafe fn native_container_id(&self) -> usize;
},
inner: {
fn find_control_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Control>;
fn find_control(&self, arg: types::FindBy) -> Option<&dyn Control>;
fn find_control_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Control>;
fn find_control<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Control>;
fn native_container_id(&self) -> <Self as HasNativeIdInner>::Id { self.native_id() }
}
extends: {
MaybeSingleContainer + MaybeMultiContainer + MaybeAdapted
Expand All @@ -24,11 +27,11 @@ define_abstract! {
}
impl<T: ContainerInner> Container for AMember<T> {
#[inline]
default fn find_control_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Control> {
default fn find_control_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Control> {
self.inner.find_control_mut(arg)
}
#[inline]
default fn find_control(&self, arg: types::FindBy) -> Option<&dyn Control> {
default fn find_control<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Control> {
self.inner.find_control(arg)
}

Expand All @@ -44,19 +47,23 @@ impl<T: ContainerInner> Container for AMember<T> {
default fn into_container(self: Box<Self>) -> Box<dyn Container> {
self
}
#[inline]
default unsafe fn native_container_id(&self) -> usize {
self.inner.native_container_id().into()
}
}
impl<T: ContainerInner + ControlInner> Container for AMember<AControl<T>> {
#[inline]
default fn find_control_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Control> {
default fn find_control_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Control> {
match arg {
types::FindBy::Id(id) => {
if self.base.id() == id {
return Some(self);
}
}
types::FindBy::Tag(ref tag) => {
types::FindBy::Tag(tag) => {
if let Some(mytag) = self.base.tag() {
if tag.as_str() == mytag {
if tag == mytag {
return Some(self);
}
}
Expand All @@ -65,16 +72,16 @@ impl<T: ContainerInner + ControlInner> Container for AMember<AControl<T>> {
self.inner.find_control_mut(arg)
}
#[inline]
default fn find_control(&self, arg: types::FindBy) -> Option<&dyn Control> {
default fn find_control<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Control> {
match arg {
types::FindBy::Id(id) => {
if self.base.id() == id {
return Some(self);
}
}
types::FindBy::Tag(ref tag) => {
types::FindBy::Tag(tag) => {
if let Some(mytag) = self.base.tag() {
if tag.as_str() == mytag {
if tag == mytag {
return Some(self);
}
}
Expand All @@ -98,11 +105,15 @@ impl<T: ContainerInner + ControlInner> Container for AMember<AControl<T>> {
}
impl<II: ContainerInner, T: HasInner<I = II> + Abstract + 'static> ContainerInner for T {
#[inline]
fn find_control_mut(&mut self, arg: types::FindBy) -> Option<&mut dyn Control> {
fn find_control_mut<'a>(&'a mut self, arg: types::FindBy<'a>) -> Option<&'a mut dyn Control> {
self.inner_mut().find_control_mut(arg)
}
#[inline]
fn find_control(&self, arg: types::FindBy) -> Option<&dyn Control> {
fn find_control<'a>(&'a self, arg: types::FindBy<'a>) -> Option<&'a dyn Control> {
self.inner().find_control(arg)
}
#[inline]
fn native_container_id(&self) -> <Self as HasNativeIdInner>::Id {
self.inner().native_container_id()
}
}
6 changes: 3 additions & 3 deletions api/src/inner/item_clickable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use super::auto::{HasInner, AsAny, Abstract};
use super::member::{Member, MemberInner, AMember};
use super::control::{Control, ControlInner, AControl};

able_to!(ItemClick (usize, &mut dyn Control): Control);
able_to!(ItemClick (&[usize], &mut dyn Control): Control);

impl<T: ItemClickableInner + MemberInner> ItemClickable for AMember<AControl<T>> {
#[inline]
default fn on_item_click(&mut self, cb: Option<OnItemClick>) {
self.inner.inner.on_item_click(cb)
}
#[inline]
default fn item_click(&mut self, i: usize, parent: &mut dyn Control, skip_callbacks: bool) {
default fn item_click(&mut self, i: &[usize], parent: &mut dyn Control, skip_callbacks: bool) {
self.inner.inner.item_click(i, parent, skip_callbacks)
}

Expand All @@ -31,7 +31,7 @@ impl<T: ItemClickableInner + MemberInner> ItemClickable for AMember<AControl<T>>
}

impl<II: ItemClickableInner, T: HasInner<I = II> + Abstract + 'static> ItemClickableInner for T {
default fn item_click(&mut self, i: usize, parent: &mut dyn Control, skip_callbacks: bool) {
default fn item_click(&mut self, i: &[usize], parent: &mut dyn Control, skip_callbacks: bool) {
self.inner_mut().item_click(i, parent, skip_callbacks)
}
default fn on_item_click(&mut self, callback: Option<OnItemClick>) {
Expand Down
12 changes: 12 additions & 0 deletions api/src/inner/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub trait Member: HasNativeId + AsAny + Sealed
fn as_member(&self) -> &dyn Member;
fn as_member_mut(&mut self) -> &mut dyn Member;
fn into_member(self: Box<Self>) -> Box<dyn Member>;

fn as_base(&self) -> &MemberBase;
fn as_base_mut(&mut self) -> &mut MemberBase;
}

pub trait MemberInner: HasNativeIdInner + Sized + 'static {}
Expand Down Expand Up @@ -138,6 +141,15 @@ impl<T: MemberInner> Member for AMember<T> {
fn into_member(self: Box<Self>) -> Box<dyn Member> {
self
}

#[inline]
fn as_base(&self) -> &MemberBase {
&self.base
}
#[inline]
fn as_base_mut(&mut self) -> &mut MemberBase {
&mut self.base
}
}
impl<T: MemberInner> AsAny for AMember<T> {
#[inline]
Expand Down
1 change: 1 addition & 0 deletions api/src/inner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod frame;
pub mod image;
pub mod layout_linear;
pub mod list;
pub mod tree;
pub mod message;
pub mod progress_bar;
pub mod splitted;
Expand Down
Loading