Skip to content

Commit 8bfdcfd

Browse files
committed
Move Vec<u8> to Table<u8>
1 parent ccca512 commit 8bfdcfd

5 files changed

Lines changed: 30 additions & 9 deletions

File tree

editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn generate_layout(introspected_data: &Arc<dyn std::any::Any + Send + Sync + 'st
170170
Table<Color>,
171171
Table<GradientStops>,
172172
Table<String>,
173+
Table<u8>,
173174
GradientStops,
174175
f64,
175176
u32,
@@ -616,6 +617,21 @@ impl TableRowLayout for f64 {
616617
}
617618
}
618619

620+
impl TableRowLayout for u8 {
621+
fn type_name() -> &'static str {
622+
"Byte"
623+
}
624+
fn identifier(&self) -> String {
625+
format!("{self:02X}")
626+
}
627+
fn cell_widget(&self, _target: PathStep) -> WidgetInstance {
628+
TextLabel::new(self.identifier()).narrow(true).widget_instance()
629+
}
630+
fn element_page(&self, _data: &mut LayoutData) -> Vec<LayoutGroup> {
631+
vec![LayoutGroup::row(vec![self.cell_widget(PathStep::Element(0))])]
632+
}
633+
}
634+
619635
impl TableRowLayout for u32 {
620636
fn type_name() -> &'static str {
621637
"Number (u32)"
@@ -813,6 +829,7 @@ macro_rules! known_table_row_types {
813829
Table<Color>,
814830
Table<GradientStops>,
815831
Table<String>,
832+
Table<u8>,
816833
GradientStops,
817834
Color,
818835
Option<NodeId>,

node-graph/interpreted-executor/src/node_registry.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
9797
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Option<f64>]),
9898
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Option<NodeId>]),
9999
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<String>]),
100+
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Table<u8>]),
100101
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => [f64; 4]]),
101102
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Graphic]),
102103
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => graphene_std::text::Font]),
@@ -152,6 +153,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
152153
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Image<Color>]),
153154
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<GradientStops>]),
154155
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<String>]),
156+
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Table<u8>]),
155157
#[cfg(target_family = "wasm")]
156158
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => CanvasHandle]),
157159
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => f64]),

node-graph/nodes/gcore/src/context_modification.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ async fn context_modification<T>(
2828
Context -> DVec2,
2929
Context -> Option<NodeId>,
3030
Context -> Table<String>,
31+
Context -> Table<u8>,
3132
Context -> Table<Vector>,
3233
Context -> Table<Graphic>,
3334
Context -> Table<Raster<CPU>>,

node-graph/nodes/gstd/src/platform_application_io.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use canvas_utils::{Canvas, CanvasHandle};
66
use core_types::WasmNotSend;
77
#[cfg(target_family = "wasm")]
88
use core_types::math::bbox::Bbox;
9-
use core_types::table::Table;
9+
use core_types::table::{Table, TableRow};
1010
#[cfg(target_family = "wasm")]
1111
use core_types::transform::Footprint;
1212
use core_types::{Color, Ctx};
@@ -85,14 +85,15 @@ async fn post_request(
8585
#[name("URL")]
8686
url: String,
8787
/// The binary data to include in the body of the POST request.
88-
body: Vec<u8>,
88+
body: Table<u8>,
8989
/// Makes the request run in the background without waiting on a response. This is useful for triggering webhooks without blocking the continued execution of the graph.
9090
discard_result: bool,
9191
#[widget(ParsedWidgetOverride::Custom = "text_area")] headers: String,
9292
) -> String {
9393
let mut header_map = parse_headers(&headers);
9494
header_map.insert("Content-Type", "application/octet-stream".parse().unwrap());
95-
let request = reqwest::Client::new().post(url).body(body).headers(header_map);
95+
let body_bytes: Vec<u8> = body.iter_element_values().copied().collect();
96+
let request = reqwest::Client::new().post(url).body(body_bytes).headers(header_map);
9697

9798
if discard_result {
9899
#[cfg(target_family = "wasm")]
@@ -114,15 +115,15 @@ async fn post_request(
114115

115116
/// Converts a text string to raw binary data. Useful for transmission over HTTP or writing to files.
116117
#[node_macro::node(category("Web Request"), name("String to Bytes"))]
117-
fn string_to_bytes(_: impl Ctx, string: String) -> Vec<u8> {
118-
string.into_bytes()
118+
fn string_to_bytes(_: impl Ctx, string: String) -> Table<u8> {
119+
string.into_bytes().into_iter().map(TableRow::new_from_element).collect()
119120
}
120121

121122
/// Converts extracted raw RGBA pixel data from an input image. Each pixel becomes 4 sequential bytes. Useful for transmission over HTTP or writing to files.
122123
#[node_macro::node(category("Web Request"), name("Image to Bytes"))]
123-
fn image_to_bytes(_: impl Ctx, image: Table<Raster<CPU>>) -> Vec<u8> {
124-
let Some(image) = image.element(0) else { return vec![] };
125-
image.data.iter().flat_map(|color| color.to_rgba8_srgb().into_iter()).collect::<Vec<u8>>()
124+
fn image_to_bytes(_: impl Ctx, image: Table<Raster<CPU>>) -> Table<u8> {
125+
let Some(image) = image.element(0) else { return Table::new() };
126+
image.data.iter().flat_map(|color| color.to_rgba8_srgb()).map(TableRow::new_from_element).collect()
126127
}
127128

128129
/// Loads binary from URLs and local asset paths. Returns a transparent placeholder if the resource fails to load, allowing rendering to continue.
@@ -188,7 +189,6 @@ async fn rasterize<T: WasmNotSend + Clone + 'n>(
188189
where
189190
Table<T>: Render + Clone + graphic_types::IntoGraphicTable,
190191
{
191-
use core_types::table::TableRow;
192192
use glam::{DAffine2, DVec2};
193193

194194
if footprint.transform.matrix2.determinant() == 0. {

node-graph/nodes/vector/src/vector_nodes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,7 @@ async fn count_elements<I: Count>(
28632863
Table<Color>,
28642864
Table<GradientStops>,
28652865
Table<String>,
2866+
Table<u8>,
28662867
)]
28672868
content: I,
28682869
) -> f64 {

0 commit comments

Comments
 (0)