Skip to content

Commit ea591d7

Browse files
committed
WIP
1 parent 5f2a0e2 commit ea591d7

7 files changed

Lines changed: 155 additions & 146 deletions

File tree

src/graph/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::node::{
88
ChannelDirection, ChannelPassBy, ChannelRef, ConnectionPassBy, DynTypeTrait, NodeConfiguration,
99
NodeStateRefcounter, OptionRefMutExt, RefAnyExt,
1010
};
11-
use crate::style::{self, consts, Theme, Themeable};
11+
use crate::style::{self, consts};
1212
use crate::widgets::{
1313
node::FloatingPanesBehaviour, FloatingPane, FloatingPaneBehaviourData, FloatingPaneBehaviourState,
1414
FloatingPaneState, NodeElement, NodeElementState,
@@ -20,7 +20,7 @@ use alloc::Allocator;
2020
use arc_swap::ArcSwapOption;
2121
use iced::{Element, Settings};
2222
use iced_futures::futures;
23-
use iced_wgpu::wgpu::{self, TextureFormat};
23+
use iced_wgpu::wgpu::{self, Backends, TextureFormat};
2424
use iced_winit::winit::window::Window;
2525
use petgraph::{stable_graph::StableGraph, visit::EdgeRef, Directed, Direction};
2626
use std::borrow::Cow;
@@ -888,7 +888,7 @@ pub struct Renderer {
888888

889889
impl Renderer {
890890
pub async fn new(settings: &Settings<ApplicationFlags>, window: Arc<Window>) -> Self {
891-
let backends = wgpu::util::backend_bits_from_env().unwrap_or(wgpu::BackendBit::PRIMARY);
891+
let backends = wgpu::util::backend_bits_from_env().unwrap_or(Backends::PRIMARY);
892892
let instance =
893893
Arc::new(wgpu::Instance::new(wgpu::InstanceDescriptor { backends, ..Default::default() }));
894894
let surface = instance.create_surface(window.clone()).expect("Could not create surface.");
@@ -917,7 +917,7 @@ impl Renderer {
917917
&wgpu::DeviceDescriptor {
918918
label: None,
919919
required_features: adapter_features & wgpu::Features::default(),
920-
required_limits: required_limits,
920+
required_limits,
921921
// features: wgpu::Features::empty(),
922922
// limits: wgpu::Limits { max_bind_groups: 2, ..wgpu::Limits::default() },
923923
// shader_validation: false,
@@ -934,6 +934,7 @@ impl Renderer {
934934
.find(wgpu::TextureFormat::is_srgb)
935935
.or_else(|| capabilities.formats.first().copied())
936936
.expect("Get preferred format");
937+
let physical_size = window.inner_size();
937938

938939
surface.configure(
939940
&device,
@@ -963,7 +964,7 @@ impl Renderer {
963964
#[derive(Debug)]
964965
pub enum TextureAllocation {
965966
TextureView(wgpu::TextureView),
966-
SwapchainFrame(wgpu::SwapChainFrame),
967+
// SwapchainFrame(wgpu::SwapChainFrame),
967968
}
968969

969970
impl Deref for TextureAllocation {

src/node/behaviour.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ pub type MainThreadTask = dyn Send + FnOnce(&EventLoop<crate::Message>);
275275
pub trait NodeBehaviourContainer: DynClone + std::fmt::Debug + Send + Sync + 'static {
276276
fn name(&self) -> &str;
277277
fn update(&mut self, event: NodeEventContainer) -> Vec<NodeCommand>;
278-
fn view(&mut self, theme: &dyn Theme) -> Option<Element<Box<dyn NodeBehaviourMessage>>>;
278+
fn view(&mut self) -> Option<Element<Box<dyn NodeBehaviourMessage>>>;
279279
fn create_state<'state>(&self, context: &ApplicationContext) -> NodeStateContainer<'state>;
280280
fn update_state<'state>(&self, context: &ApplicationContext, state: &mut NodeStateContainer<'state>);
281281
}
@@ -288,7 +288,7 @@ pub trait NodeBehaviour: std::fmt::Debug + Clone + Send + Sync + 'static {
288288

289289
fn name(&self) -> &str;
290290
fn update(&mut self, event: NodeEvent<Self::Message>) -> Vec<NodeCommand>;
291-
fn view(&mut self, theme: &dyn Theme) -> Option<Element<Self::Message>>;
291+
fn view(&mut self) -> Option<Element<Self::Message>>;
292292
fn create_state<'state>(&self, context: &ApplicationContext) -> Self::State<'state>;
293293
}
294294

@@ -301,8 +301,8 @@ impl<T: NodeBehaviour> NodeBehaviourContainer for T {
301301
NodeBehaviour::update(self, NodeEvent::from_container(event).unwrap())
302302
}
303303

304-
fn view(&mut self, theme: &dyn Theme) -> Option<Element<Box<dyn NodeBehaviourMessage>>> {
305-
NodeBehaviour::view(self, theme)
304+
fn view(&mut self) -> Option<Element<Box<dyn NodeBehaviourMessage>>> {
305+
NodeBehaviour::view(self)
306306
.map(|element| element.map(|message| Box::new(message) as Box<dyn NodeBehaviourMessage>))
307307
}
308308

src/node/behaviour/array_constructor.rs

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
use crate::{
2-
node::{
3-
behaviour::{
4-
ApplicationContext, ExecutionContext, ExecutorClosure, NodeBehaviour, NodeCommand, NodeEvent,
5-
NodeStateClosure,
6-
},
7-
ArrayType, BytesRefExt, Channel, NodeConfiguration, OptionRefMutExt, PrimitiveType,
8-
PrimitiveTypeEnum,
9-
},
10-
style::{self, Themeable},
11-
};
12-
use iced::pick_list::{self, PickList};
131
use iced::{
14-
button::{Button, State as ButtonState},
15-
Element,
2+
widget::{Button, PickList, Row, Text},
3+
Alignment, Element, Length,
4+
};
5+
6+
use crate::node::{
7+
behaviour::{
8+
ApplicationContext, ExecutionContext, ExecutorClosure, NodeBehaviour, NodeCommand, NodeEvent,
9+
NodeStateClosure,
10+
},
11+
ArrayType, BytesRefExt, Channel, NodeConfiguration, OptionRefMutExt, PrimitiveTypeEnum,
1612
};
17-
use iced::{Align, Length, Row, Text};
1813
use std::io::{Cursor, Write};
1914
use std::num::NonZeroUsize;
20-
use style::Theme;
2115

2216
#[derive(Debug, Clone)]
2317
pub enum ArrayConstructorNodeMessage {
@@ -30,20 +24,11 @@ pub enum ArrayConstructorNodeMessage {
3024
pub struct ArrayConstructorNodeBehaviour {
3125
ty: PrimitiveTypeEnum,
3226
channel_count: NonZeroUsize,
33-
pick_list_state: pick_list::State<PrimitiveTypeEnum>,
34-
button_add_state: ButtonState,
35-
button_remove_state: ButtonState,
3627
}
3728

3829
impl Default for ArrayConstructorNodeBehaviour {
3930
fn default() -> Self {
40-
Self {
41-
ty: PrimitiveTypeEnum::F32,
42-
channel_count: unsafe { NonZeroUsize::new_unchecked(1) },
43-
pick_list_state: Default::default(),
44-
button_add_state: Default::default(),
45-
button_remove_state: Default::default(),
46-
}
31+
Self { ty: PrimitiveTypeEnum::F32, channel_count: unsafe { NonZeroUsize::new_unchecked(1) } }
4732
}
4833
}
4934

@@ -101,28 +86,24 @@ impl NodeBehaviour for ArrayConstructorNodeBehaviour {
10186
fn view(&mut self, theme: &dyn Theme) -> Option<Element<Self::Message>> {
10287
Some(
10388
Row::new()
104-
.theme(theme)
10589
.push(
106-
PickList::new(
107-
&mut self.pick_list_state,
108-
&PrimitiveTypeEnum::VALUES[..],
109-
Some(self.ty),
110-
|new_value| ArrayConstructorNodeMessage::UpdateType(new_value),
111-
)
90+
PickList::new(&PrimitiveTypeEnum::VALUES[..], Some(self.ty), |new_value| {
91+
ArrayConstructorNodeMessage::UpdateType(new_value)
92+
})
11293
.theme(theme)
11394
.width(Length::Units(64)),
11495
)
11596
.push(
116-
Button::new(&mut self.button_add_state, Text::new("+"))
97+
Button::new(Text::new("+"))
11798
.width(Length::Fill)
11899
.on_press(ArrayConstructorNodeMessage::AddChannel),
119100
)
120101
.push(
121-
Button::new(&mut self.button_remove_state, Text::new("-"))
102+
Button::new(Text::new("-"))
122103
.width(Length::Fill)
123104
.on_press(ArrayConstructorNodeMessage::RemoveChannel),
124105
)
125-
.align_items(Align::Center)
106+
.align_y(Alignment::Center)
126107
.width(Length::Fill)
127108
.into(),
128109
)

src/util.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
#![allow(dead_code)]
22

3-
use iced::widget::canvas::{Fill, Frame, Path};
4-
use iced::{Border, Color, Rectangle};
5-
use iced_core::renderer::Quad;
6-
use iced_core::Layout;
7-
use iced_graphics::geometry::fill::Rule;
3+
use iced::Color;
4+
use iced::Rectangle;
85
use iced_graphics::geometry::path::Builder;
9-
use iced_graphics::geometry::Style;
10-
use lyon_geom::{LineSegment, Point, QuadraticBezierSegment, Scalar, Segment};
6+
use lyon_geom::{math::Point, LineSegment, QuadraticBezierSegment, Scalar, Segment};
117
use smallvec::{smallvec, Array, SmallVec};
128
use std::borrow::Cow;
139
use std::ops::Deref;
1410
use std::ops::DerefMut;
11+
use std::ops::Range;
1512
use vek::Vec2;
1613

17-
use crate::widgets::PrimitiveEnum;
18-
1914
pub enum StrokeType {
2015
Contiguous,
2116
Dashed { filled_length: f32, gap_length: f32 },
@@ -29,7 +24,7 @@ pub struct ProjectionResult {
2924
}
3025

3126
pub trait ConnectionSegment {
32-
type Flattened: Iterator<Item = Point<f32>>;
27+
type Flattened: Iterator<Item = Point>;
3328

3429
fn build_segment(&self, builder: &mut Builder);
3530
fn approx_length(&self) -> f32;
@@ -338,26 +333,25 @@ pub fn softminabs(abs_softness: f32, max_sharpness: f32, max: f32, x: f32) -> f3
338333
softmax(-max, max_sharpness, 0.0) - softmax(-max, max_sharpness, -softabs2(abs_softness, x))
339334
}
340335

341-
pub fn draw_point<R>(renderer: &R, position: Vec2<f32>, color: Color, radius: f32) -> R::Geometry
342-
where R: iced_graphics::geometry::Renderer {
336+
pub fn draw_point(position: Vec2<f32>, color: Color, radius: f32) -> Primitive {
343337
let connection_point_center = radius + 1.0; // extra pixel for anti aliasing
344338
let frame_size = connection_point_center * 2.0;
345-
let mut frame = Frame::new(renderer, [frame_size, frame_size].into());
339+
let mut frame = Frame::new([frame_size, frame_size].into());
346340
let path = Path::new(|builder| {
347341
builder.circle([connection_point_center, connection_point_center].into(), radius);
348342
});
349343

350-
frame.fill(&path, Fill { style: Style::Solid(color), rule: Rule::NonZero });
351-
// TODO: This might need to be negated or placed before frame.fill? Or just translate the center
352-
// before drawing the circle?
353-
frame.translate(
354-
(position - Vec2::new(connection_point_center, connection_point_center)).into_array().into(),
355-
);
344+
frame.fill(&path, Fill { color, rule: FillRule::NonZero });
356345

357-
frame.into_geometry()
346+
Primitive::Translate {
347+
translation: (position - Vec2::new(connection_point_center, connection_point_center))
348+
.into_array()
349+
.into(),
350+
content: Box::new(frame.into_geometry().into_primitive()),
351+
}
358352
}
359353

360-
pub fn draw_rectangle(rectangle: Rectangle<f32>, color: Color) -> PrimitiveEnum {
354+
pub fn draw_rectangle(rectangle: Rectangle<f32>, color: Color) -> Primitive {
361355
// let layout_position = Vector::new(layout.position().x, layout.position().y);
362356
// let layout_size = Vector::new(layout.bounds().size().width, layout.bounds().size().height);
363357

@@ -373,14 +367,16 @@ pub fn draw_rectangle(rectangle: Rectangle<f32>, color: Color) -> PrimitiveEnum
373367
// ),
374368
// ],
375369
// }
376-
PrimitiveEnum::Quad(Quad {
370+
Primitive::Quad {
377371
bounds: rectangle,
378-
border: Border { radius: 0, width: 1, color },
379-
shadow: None,
380-
})
372+
background: Background::Color(Color::TRANSPARENT),
373+
border_radius: 0,
374+
border_width: 1,
375+
border_color: color,
376+
}
381377
}
382378

383-
pub fn draw_bounds(layout: Layout<'_>, color: Color) -> PrimitiveEnum {
379+
pub fn draw_bounds(layout: Layout<'_>, color: Color) -> Primitive {
384380
draw_rectangle(layout.bounds(), color)
385381
}
386382

src/widgets/floating_panes.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use iced_core::layout::{Limits, Node};
1010
use iced_core::renderer::Quad;
1111
use iced_core::widget::Tree;
1212
use iced_core::{self, Clipboard, Event, Layout, Length, Point, Shell, Text, Widget};
13-
use iced_core::{overlay, Element};
1413
use iced_core::{Background, Color, Rectangle};
1514
use iced_winit::winit::event::MouseButton;
1615
use indexmap::IndexMap;
@@ -280,7 +279,7 @@ impl<'a, M: 'a, T: 'a, R: 'a + WidgetRenderer, C: 'a + FloatingPanesBehaviour<'a
280279
self
281280
}
282281

283-
pub fn build(mut self) -> FloatingPane<'a, M, R, C> {
282+
pub fn build(mut self) -> FloatingPane<'a, M, T, R, C> {
284283
FloatingPane {
285284
behaviour_data: self.behaviour_data,
286285
min_size: self.min_size,
@@ -673,7 +672,7 @@ impl<'a, M: 'a, T: 'a, R: 'a + WidgetRenderer, C: 'a + FloatingPanesBehaviour<'a
673672
// self
674673
// }
675674

676-
pub fn insert(mut self, index: C::FloatingPaneIndex, child: FloatingPane<'a, M, R, C>) -> Self {
675+
pub fn insert(mut self, index: C::FloatingPaneIndex, child: FloatingPane<'a, M, T, R, C>) -> Self {
677676
self.children.insert(index, child.into());
678677
self
679678
}
@@ -960,7 +959,7 @@ impl<'a, M: 'a, T: 'a, R: 'a + WidgetRenderer, C: 'a + FloatingPanesBehaviour<'a
960959
renderer: &R,
961960
translation: Vector,
962961
) -> Option<Element<'b, M, T, R>> {
963-
C::overlay(self, layout, renderer)
962+
C::overlay(self, state, layout, renderer, translation)
964963
}
965964
}
966965

@@ -1018,35 +1017,35 @@ where R: margin::WidgetRenderer + iced_core::Renderer + iced_core::text::Rendere
10181017
.gesture
10191018
.as_ref()
10201019
.map(Gesture::get_mouse_interaction)
1021-
.unwrap_or(mouse::Interaction::default());
1020+
.unwrap_or(Interaction::default());
10221021

1023-
let background_primitive = Primitive::Quad {
1022+
let background_primitive = PrimitiveEnum::Quad(Quad {
10241023
bounds: Rectangle::new(Point::ORIGIN, layout.bounds().size()),
1025-
background: Background::Color(
1026-
element
1027-
.style
1028-
.as_ref()
1029-
.map(|style| style.style().background_color)
1030-
.unwrap_or(Color::TRANSPARENT),
1031-
),
1024+
// background: Background::Color(
1025+
// element
1026+
// .style
1027+
// .as_ref()
1028+
// .map(|style| style.style().background_color)
1029+
// .unwrap_or(Color::TRANSPARENT),
1030+
// ),
10321031
border: iced::Border::default(),
10331032
shadow: iced::Shadow::default(),
1034-
};
1033+
});
10351034

10361035
let ContentDrawResult {
10371036
override_parent_cursor,
1038-
output: (panes_primitive, content_mouse_interaction),
1037+
// output: (panes_primitive, content_mouse_interaction),
10391038
} = C::draw_panes(element, tree, self, theme, style, layout, cursor, viewport);
10401039

1041-
if override_parent_cursor {
1042-
mouse_interaction = content_mouse_interaction;
1043-
} else {
1044-
mouse_interaction = std::cmp::max(mouse_interaction, content_mouse_interaction);
1045-
};
1040+
// if override_parent_cursor {
1041+
// mouse_interaction = content_mouse_interaction;
1042+
// } else {
1043+
// mouse_interaction = std::cmp::max(mouse_interaction, content_mouse_interaction);
1044+
// };
10461045

1047-
let primitives = vec![background_primitive, panes_primitive];
1046+
// let primitives = vec![background_primitive, panes_primitive];
10481047

1049-
(Primitive::Group { primitives }, mouse_interaction)
1048+
(background_primitive /* Originally `primitives` */, mouse_interaction)
10501049
}
10511050
}
10521051

0 commit comments

Comments
 (0)