Skip to content

Commit 0fac027

Browse files
committed
WIP
1 parent ce284f6 commit 0fac027

File tree

2 files changed

+61
-32
lines changed

2 files changed

+61
-32
lines changed

src/widgets/margin.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use iced::event::Status;
22
use iced::mouse::Cursor;
33
use iced::widget::{Column, Row, Space};
4-
use iced::{Element, Event, Length, Point, Rectangle, Vector, overlay};
4+
use iced::{Element, Event, Length, Rectangle, Vector, overlay};
55
use iced_core::layout::{Limits, Node};
66
use iced_core::widget::Tree;
77
use iced_core::{Clipboard, Layout, Renderer, Shell, Widget};
@@ -52,11 +52,11 @@ impl<'a, M: 'a, T: 'a, R: WidgetRenderer + 'a> Margin<'a, M, T, R> {
5252

5353
impl<'a, M: 'a, T: 'a, R: WidgetRenderer + 'a> Widget<M, T, R> for Margin<'a, M, T, R> {
5454
fn size(&self) -> iced::Size<iced::Length> {
55-
self.child.size()
55+
self.child.as_widget().size()
5656
}
5757

5858
fn layout(&self, state: &mut Tree, renderer: &R, limits: &Limits) -> Node {
59-
self.child.layout(renderer, limits)
59+
self.child.as_widget().layout(state, renderer, limits)
6060
}
6161

6262
fn draw(
@@ -87,7 +87,9 @@ impl<'a, M: 'a, T: 'a, R: WidgetRenderer + 'a> Widget<M, T, R> for Margin<'a, M,
8787
shell: &mut Shell<'_, M>,
8888
viewport: &Rectangle,
8989
) -> Status {
90-
self.child.on_event(event, layout, cursor, renderer, clipboard, shell)
90+
self.child
91+
.as_widget_mut()
92+
.on_event(state, event, layout, cursor, renderer, clipboard, shell, viewport)
9193
}
9294

9395
fn overlay<'b>(
@@ -97,11 +99,11 @@ impl<'a, M: 'a, T: 'a, R: WidgetRenderer + 'a> Widget<M, T, R> for Margin<'a, M,
9799
renderer: &R,
98100
translation: Vector,
99101
) -> Option<overlay::Element<'b, M, T, R>> {
100-
self.child.overlay(layout, renderer)
102+
self.child.as_widget_mut().overlay(state, layout, renderer, translation)
101103
}
102104
}
103105

104-
impl<'a, M: 'a, T, R: WidgetRenderer + 'a> From<Margin<'a, M, T, R>> for Element<'a, M, T, R> {
106+
impl<'a, M: 'a, T: 'a, R: WidgetRenderer + 'a> From<Margin<'a, M, T, R>> for Element<'a, M, T, R> {
105107
fn from(other: Margin<'a, M, T, R>) -> Self {
106108
Element::new(other)
107109
}

src/widgets/node.rs

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use iced_core::layout::{Layout, Limits, Node};
1414
use iced_core::mouse::{self, Button as MouseButton, Event as MouseEvent};
1515
use iced_core::overlay::{self, Overlay};
1616
use iced_core::widget::{Tree, Widget};
17-
use iced_core::{self, Clipboard, Element, Event, Length, Point, Rectangle, Text};
17+
use iced_core::{self, Clipboard, Element, Event, Length, Point, Rectangle};
1818
use iced_core::{Color, Shell};
1919
use iced_graphics::geometry::{LineCap, LineDash, LineJoin, Path, Stroke, Style};
2020
use lyon_geom::QuadraticBezierSegment;
@@ -25,7 +25,12 @@ use std::marker::PhantomData;
2525
use vek::Vec2;
2626

2727
impl<'a> ChannelRef<'a> {
28-
pub fn render<M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer>(&self) -> Element<'a, M, T, R> {
28+
pub fn render<M, T, R>(&self) -> Element<'a, M, T, R>
29+
where
30+
M: 'a + Clone,
31+
T: 'a + iced::widget::text::Catalog,
32+
R: 'a + WidgetRenderer,
33+
{
2934
Text::new(self.title.to_string()).size(style::consts::TEXT_SIZE_REGULAR).into()
3035
}
3136
}
@@ -58,7 +63,12 @@ pub struct NodeElement<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> {
5863
element_tree: Element<'a, M, T, R>,
5964
}
6065

61-
impl<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> NodeElementBuilder<'a, M, T, R> {
66+
impl<'a, M, T, R> NodeElementBuilder<'a, M, T, R>
67+
where
68+
M: 'a + Clone,
69+
T: 'a + iced::widget::text::Catalog,
70+
R: 'a + WidgetRenderer,
71+
{
6272
pub fn new(index: NodeIndex, state: &'a mut NodeElementState) -> Self {
6373
Self {
6474
index,
@@ -160,7 +170,12 @@ impl<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> NodeElementBuilder<'a, M,
160170
}
161171
}
162172

163-
impl<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> NodeElement<'a, M, T, R> {
173+
impl<'a, M, T, R> NodeElement<'a, M, T, R>
174+
where
175+
M: 'a + Clone,
176+
T: 'a + iced::widget::text::Catalog,
177+
R: 'a + WidgetRenderer,
178+
{
164179
pub fn builder(index: NodeIndex, state: &'a mut NodeElementState) -> NodeElementBuilder<'a, M, T, R> {
165180
NodeElementBuilder::new(index, state)
166181
}
@@ -223,7 +238,12 @@ impl<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> NodeElement<'a, M, T, R>
223238
}
224239
}
225240

226-
impl<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> Widget<M, T, R> for NodeElement<'a, M, T, R> {
241+
impl<'a, M, T, R> Widget<M, T, R> for NodeElement<'a, M, T, R>
242+
where
243+
M: 'a + Clone,
244+
T: 'a + iced::widget::text::Catalog,
245+
R: 'a + WidgetRenderer,
246+
{
227247
fn size(&self) -> Size<iced::Length> {
228248
Size::new(self.width, self.height)
229249
}
@@ -234,7 +254,7 @@ impl<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> Widget<M, T, R> for NodeE
234254
// .max_height(self.extents[1])
235255
// .width(self.width)
236256
// .height(self.height);
237-
self.element_tree.layout(renderer, limits)
257+
self.element_tree.as_widget().layout(state, renderer, limits)
238258
}
239259

240260
fn draw(
@@ -266,19 +286,22 @@ impl<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> Widget<M, T, R> for NodeE
266286
.on_event(state, event, layout, cursor, renderer, clipboard, shell, viewport)
267287
}
268288

269-
fn overlay(
270-
&mut self,
271-
state: &mut Tree,
289+
fn overlay<'b>(
290+
&'b mut self,
291+
state: &'b mut Tree,
272292
layout: Layout<'_>,
273293
renderer: &R,
274294
translation: Vector,
275-
) -> Option<Element<'_, M, T, R>> {
276-
self.element_tree.overlay(state, layout)
295+
) -> Option<overlay::Element<'b, M, T, R>> {
296+
self.element_tree.as_widget_mut().overlay(state, layout, renderer, translation)
277297
}
278298
}
279299

280-
impl<'a, M: 'a + Clone, T: 'a, R: 'a + WidgetRenderer> From<NodeElement<'a, M, T, R>>
281-
for Element<'a, M, T, R>
300+
impl<'a, M, T, R> From<NodeElement<'a, M, T, R>> for Element<'a, M, T, R>
301+
where
302+
M: 'a + Clone,
303+
T: 'a + iced::widget::text::Catalog,
304+
R: 'a + WidgetRenderer,
282305
{
283306
fn from(other: NodeElement<'a, M, T, R>) -> Self {
284307
Element::new(other)
@@ -326,8 +349,11 @@ impl<M: Clone, R: WidgetRenderer> FloatingPanesBehaviour<M, R> {
326349
}
327350
}
328351

329-
impl<'a, M: Clone + 'a, T: 'a, R: 'a + WidgetRenderer> floating_panes::FloatingPanesBehaviour<'a, M, T, R>
330-
for FloatingPanesBehaviour<M, R>
352+
impl<'a, M, T, R> floating_panes::FloatingPanesBehaviour<'a, M, T, R> for FloatingPanesBehaviour<M, R>
353+
where
354+
M: Clone + 'a,
355+
T: 'a + iced::widget::text::Catalog + iced::widget::container::Catalog,
356+
R: 'a + WidgetRenderer,
331357
{
332358
type FloatingPaneIndex = NodeIndex;
333359
type FloatingPaneBehaviourData = FloatingPaneBehaviourData;
@@ -351,7 +377,7 @@ impl<'a, M: Clone + 'a, T: 'a, R: 'a + WidgetRenderer> floating_panes::FloatingP
351377
panes: &mut FloatingPanes<'a, M, T, R, Self>,
352378
state: &mut Tree,
353379
event: Event,
354-
layout: Layout<'_>,
380+
layout: FloatingPanesLayout<'_>,
355381
cursor: Cursor,
356382
renderer: &R,
357383
clipboard: &mut dyn Clipboard,
@@ -398,7 +424,7 @@ impl<'a, M: Clone + 'a, T: 'a, R: 'a + WidgetRenderer> floating_panes::FloatingP
398424
}
399425
}
400426

401-
NodeElement::<M, R>::is_channel_selected(
427+
NodeElement::<M, T, R>::is_channel_selected(
402428
channel_layout.clone(),
403429
channel_ref.direction,
404430
cursor_position,
@@ -426,7 +452,7 @@ impl<'a, M: Clone + 'a, T: 'a, R: 'a + WidgetRenderer> floating_panes::FloatingP
426452
let layout_from = layout
427453
.panes()
428454
.nth(
429-
NodeElement::<M, R>::get_layout_index_from_channel(
455+
NodeElement::<M, T, R>::get_layout_index_from_channel(
430456
panes,
431457
connection.from(),
432458
)
@@ -436,7 +462,7 @@ impl<'a, M: Clone + 'a, T: 'a, R: 'a + WidgetRenderer> floating_panes::FloatingP
436462
let layout_to = layout
437463
.panes()
438464
.nth(
439-
NodeElement::<M, R>::get_layout_index_from_channel(
465+
NodeElement::<M, T, R>::get_layout_index_from_channel(
440466
panes,
441467
connection.to(),
442468
)
@@ -555,7 +581,7 @@ impl<'a, M: Clone + 'a, T: 'a, R: 'a + WidgetRenderer> floating_panes::FloatingP
555581
layout: Layout<'_>,
556582
renderer: &R,
557583
translation: Vector,
558-
) -> Option<Element<'b, M, T, R>> {
584+
) -> Option<overlay::Element<'b, M, T, R>> {
559585
let mut errors = panes
560586
.behaviour_state
561587
.highlight
@@ -589,7 +615,7 @@ impl<'a, M: Clone + 'a, T: 'a, R: 'a + WidgetRenderer> floating_panes::FloatingP
589615

590616
for error in errors {
591617
let display = error.display();
592-
let mut error_element = Column::<M, R>::new()
618+
let mut error_element = Column::<M, T, R>::new()
593619
.max_width(512)
594620
.push(Text::new(display.title.to_string()).size(style::consts::TEXT_SIZE_TITLE))
595621
.push(Text::new(display.description.to_string()).size(style::consts::TEXT_SIZE_REGULAR));
@@ -601,17 +627,18 @@ impl<'a, M: Clone + 'a, T: 'a, R: 'a + WidgetRenderer> floating_panes::FloatingP
601627
);
602628
}
603629

604-
let mut container = Container::new(Margin::new(error_element, style::consts::SPACING));
630+
let mut container =
631+
Container::<M, T, R>::new(Margin::new(error_element, style::consts::SPACING));
605632

606-
if let Some(style) = panes.behaviour.tooltip_style.as_ref() {
607-
container = container.style(style.container_style());
608-
}
633+
// if let Some(style) = panes.behaviour.tooltip_style.as_ref() {
634+
// container = container.style(style.container_style());
635+
// }
609636

610637
column = column.push(container);
611638
}
612639

613640
let position: Point = panes.state.cursor_position.into_array().into();
614-
let overlay = WidgetOverlay::<M, R, _>::new(
641+
let overlay = WidgetOverlay::<M, T, R, _>::new(
615642
column,
616643
WidgetOverlayAlignment { top: true, left: false },
617644
position,

0 commit comments

Comments
 (0)