-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pretty much usable (there are missing functions such as remove and so…
…, but I think the main parts are done (mainly parsing Style, returning Layout))
- Loading branch information
Showing
21 changed files
with
1,424 additions
and
736 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
package com.dioxuslabs.taffy; | ||
|
||
import com.dioxuslabs.taffy.geom.TaffyPoint; | ||
import com.dioxuslabs.taffy.geom.TaffyRect; | ||
import com.dioxuslabs.taffy.geom.measure.TaffyLengthPercentageAuto; | ||
import com.dioxuslabs.taffy.style.TaffyOverflow; | ||
import com.dioxuslabs.taffy.geom.TaffySize; | ||
import com.dioxuslabs.taffy.geom.measure.TaffyLengthPercentage; | ||
import com.dioxuslabs.taffy.style.TaffyStyle; | ||
import com.dioxuslabs.taffy.tree.TaffyLayout; | ||
|
||
class Taffy { | ||
static { | ||
System.loadLibrary("jtaffy"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
TaffyTree tree = new TaffyTree(); | ||
System.out.println(tree.ptr); | ||
|
||
long id = tree.newLeaf(TaffyStyle.builder() | ||
.overflow(new TaffyPoint<>(TaffyOverflow.SCROLL, TaffyOverflow.HIDDEN)) | ||
.inset(new TaffyRect<>(TaffyLengthPercentageAuto.auto(), TaffyLengthPercentageAuto.length(1), TaffyLengthPercentageAuto.length(1), TaffyLengthPercentageAuto.length(1))) | ||
TaffyTree taffy = new TaffyTree(); | ||
long node = taffy.newLeaf(TaffyStyle.builder() | ||
.padding(new TaffyRect<>( | ||
TaffyLengthPercentage.percentage(1f), | ||
TaffyLengthPercentage.length(0f), | ||
TaffyLengthPercentage.percentage(1f), | ||
TaffyLengthPercentage.length(0f) | ||
)) | ||
); | ||
|
||
System.out.println("Leaf id: " + id); | ||
taffy.computeLayout(node, TaffySize.definiteAvailableSize(200, 100)); | ||
|
||
int children = tree.childCount(id); | ||
System.out.println("Getting the layout of nodes"); | ||
|
||
System.out.println("Child count: " + children); | ||
TaffyLayout layout = taffy.layout(node); | ||
System.out.println("Width: " + layout.size().width() + " = 200.0"); | ||
System.out.println("Height: " + layout.size().height() + " = 200.0"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
bindings/java/java/com/dioxuslabs/taffy/com_dioxuslabs_taffy_TaffyTree.h
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
bindings/java/java/com/dioxuslabs/taffy/geom/measure/TaffyAvailableSpace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.dioxuslabs.taffy.geom.measure; | ||
|
||
public class TaffyAvailableSpace { | ||
private final byte type; | ||
private final float value; | ||
|
||
private TaffyAvailableSpace(byte type, float value) { | ||
this.type = type; | ||
this.value = value; | ||
} | ||
|
||
public static TaffyAvailableSpace definite(float value) { | ||
return new TaffyAvailableSpace((byte) 0, value); | ||
} | ||
|
||
public static TaffyAvailableSpace minContent() { | ||
return new TaffyAvailableSpace((byte) 1, 0); | ||
} | ||
|
||
public static TaffyAvailableSpace maxContent() { | ||
return new TaffyAvailableSpace((byte) 2, 0); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof TaffyAvailableSpace as)) { | ||
return false; | ||
} | ||
return type == as.type && value == as.value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
bindings/java/java/com/dioxuslabs/taffy/tree/TaffyLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.dioxuslabs.taffy.tree; | ||
|
||
import com.dioxuslabs.taffy.geom.TaffyPoint; | ||
import com.dioxuslabs.taffy.geom.TaffyRect; | ||
import com.dioxuslabs.taffy.geom.TaffySize; | ||
|
||
/** | ||
* The final result of a layout algorithm for a single node. | ||
* @param order The relative ordering of the node | ||
* <p> | ||
* Nodes with a higher order should be rendered on top of those with a lower order. This is | ||
* effectively a topological sort of each tree. | ||
* @param location The top-left corner of the node | ||
* @param size The width and height of the node | ||
* @param contentSize The width and height of the content inside the node. This may be larger than the size | ||
* of the node in the case of overflowing content and is useful for computing a "scroll | ||
* width/height" for scrollable nodes | ||
* @param scrollbarSize The size of the scrollbars in each dimension. If there is no scrollbar then the | ||
* size will be zero. | ||
* @param border The size of the borders of the node | ||
* @param padding The size of the padding of the node | ||
* @param margin The size of the margin of the node | ||
*/ | ||
public record TaffyLayout( | ||
int order, | ||
TaffyPoint<Float> location, | ||
TaffySize<Float> size, | ||
TaffySize<Float> contentSize, | ||
TaffySize<Float> scrollbarSize, | ||
TaffyRect<Float> border, | ||
TaffyRect<Float> padding, | ||
TaffyRect<Float> margin | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::convert::TryInto; | ||
use jni::JNIEnv; | ||
use jni::objects::{JObject, JValue, JValueOwned}; | ||
use crate::conversions::f_get_value; | ||
|
||
/// Unwraps a Java List into a Rust Vec | ||
pub unsafe fn get_list<'local, T, F>(env: &mut JNIEnv<'local>, value: JValueOwned<'local>, f: F) -> Vec<T> | ||
where | ||
F: Fn(&mut JNIEnv<'local>, JValueOwned<'local>) -> Option<T>, | ||
{ | ||
let jlist_object = value.l().unwrap(); | ||
|
||
if jlist_object.is_null() { | ||
return Vec::with_capacity(0); | ||
} | ||
|
||
let list = env.get_list(&jlist_object).unwrap(); | ||
|
||
let jlist_size = env | ||
.call_method(&list, "size", "()I", &[]) | ||
.expect("Couldn't call size on List") | ||
.i() | ||
.unwrap(); | ||
|
||
let mut vec: Vec<T> = Vec::new(); | ||
for i in 0..jlist_size { | ||
let element = env.call_method(&list, "get", "(I)Ljava/lang/Object;", &[JValue::Int(i)]).unwrap(); | ||
|
||
let value = f(env, element); | ||
if value.is_some() { | ||
vec.push(value.unwrap()); | ||
} | ||
} | ||
|
||
vec | ||
} | ||
|
||
/// Unwraps a Java List into a Rust array, it basically uses `unwrap_jlist` and then tries to convert the Vec into an array | ||
#[allow(dead_code)] | ||
pub unsafe fn get_array<'local, T, F, const N: usize>(env: &mut JNIEnv<'local>, value: JValueOwned<'local>, f: F) -> [T; N] | ||
where | ||
F: Fn(&mut JNIEnv<'local>, JValueOwned<'local>) -> Option<T>, | ||
{ | ||
let vec = get_list(env, value, f); | ||
vec.try_into() | ||
.unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len())) | ||
} | ||
|
||
pub unsafe fn f_get_list<'local, T, F>(env: &mut JNIEnv<'local>, base: &JObject<'local>, field: &str, f: F) -> Vec<T> | ||
where | ||
F: Fn(&mut JNIEnv<'local>, JValueOwned<'local>) -> Option<T>, | ||
{ | ||
let value = f_get_value(env, base, field, "Ljava/util/List;"); | ||
get_list(env, value, f) | ||
} |
Oops, something went wrong.