Skip to content

Commit 1317488

Browse files
authored
refactor: Split core render functions (#937)
* refactor: Split core render functions * lint
1 parent 0cb934f commit 1317488

File tree

11 files changed

+638
-566
lines changed

11 files changed

+638
-566
lines changed

crates/core/src/elements/label.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use torin::prelude::{
1111
};
1212

1313
use super::utils::ElementUtils;
14-
use crate::prelude::{
15-
align_main_align_paragraph,
16-
DioxusNode,
14+
use crate::{
15+
prelude::DioxusNode,
16+
render::align_main_align_paragraph,
1717
};
1818

1919
pub struct LabelElement;

crates/core/src/elements/paragraph.rs

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ use torin::{
3131
use super::utils::ElementUtils;
3232
use crate::{
3333
dom::DioxusNode,
34-
prelude::{
35-
align_highlights_and_cursor_paragraph,
34+
prelude::TextGroupMeasurement,
35+
render::{
3636
align_main_align_paragraph,
37-
TextGroupMeasurement,
37+
create_paragraph,
38+
draw_cursor,
39+
draw_cursor_highlights,
3840
},
39-
render::create_paragraph,
4041
};
4142

4243
pub struct ParagraphElement;
@@ -230,80 +231,3 @@ impl ElementUtils for ParagraphElement {
230231
area
231232
}
232233
}
233-
234-
fn draw_cursor_highlights(
235-
area: &Area,
236-
paragraph: &Paragraph,
237-
canvas: &Canvas,
238-
node_ref: &DioxusNode,
239-
) -> Option<()> {
240-
let node_cursor_state = &*node_ref.get::<CursorState>().unwrap();
241-
242-
let highlights = node_cursor_state.highlights.as_ref()?;
243-
let highlight_color = node_cursor_state.highlight_color;
244-
245-
for (from, to) in highlights.iter() {
246-
let (from, to) = {
247-
if from < to {
248-
(from, to)
249-
} else {
250-
(to, from)
251-
}
252-
};
253-
let cursor_rects = paragraph.get_rects_for_range(
254-
*from..*to,
255-
RectHeightStyle::Tight,
256-
RectWidthStyle::Tight,
257-
);
258-
for cursor_rect in cursor_rects {
259-
let rect = align_highlights_and_cursor_paragraph(
260-
node_ref,
261-
area,
262-
paragraph,
263-
&cursor_rect,
264-
None,
265-
);
266-
267-
let mut paint = Paint::default();
268-
paint.set_anti_alias(true);
269-
paint.set_style(PaintStyle::Fill);
270-
paint.set_color(highlight_color);
271-
272-
canvas.draw_rect(rect, &paint);
273-
}
274-
}
275-
276-
Some(())
277-
}
278-
279-
fn draw_cursor(
280-
area: &Area,
281-
paragraph: &Paragraph,
282-
canvas: &Canvas,
283-
node_ref: &DioxusNode,
284-
) -> Option<()> {
285-
let node_cursor_state = &*node_ref.get::<CursorState>().unwrap();
286-
287-
let cursor = node_cursor_state.position?;
288-
let cursor_color = node_cursor_state.color;
289-
let cursor_position = cursor as usize;
290-
291-
let cursor_rects = paragraph.get_rects_for_range(
292-
cursor_position..cursor_position + 1,
293-
RectHeightStyle::Tight,
294-
RectWidthStyle::Tight,
295-
);
296-
let cursor_rect = cursor_rects.first()?;
297-
298-
let rect =
299-
align_highlights_and_cursor_paragraph(node_ref, area, paragraph, cursor_rect, Some(1.0));
300-
301-
let mut paint = Paint::default();
302-
paint.set_anti_alias(true);
303-
paint.set_style(PaintStyle::Fill);
304-
paint.set_color(cursor_color);
305-
306-
canvas.draw_rect(rect, &paint);
307-
308-
Some(())
309-
}

0 commit comments

Comments
 (0)