Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/core/src/dom/doms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ use freya_native_core::{
};
use freya_node_state::{
AccessibilityNodeState,
CursorSettings,
CursorState,
CustomAttributeValues,
FontStyleState,
LayerState,
LayoutState,
References,
Style,
Transform,
ReferencesState,
StyleState,
TransformState,
ViewportState,
};
use torin::prelude::*;
Expand Down Expand Up @@ -124,12 +124,12 @@ pub struct FreyaDOM {
impl Default for FreyaDOM {
fn default() -> Self {
let mut rdom = RealDom::<CustomAttributeValues>::new([
CursorSettings::to_type_erased(),
CursorState::to_type_erased(),
FontStyleState::to_type_erased(),
References::to_type_erased(),
ReferencesState::to_type_erased(),
LayoutState::to_type_erased(),
Style::to_type_erased(),
Transform::to_type_erased(),
StyleState::to_type_erased(),
TransformState::to_type_erased(),
AccessibilityNodeState::to_type_erased(),
ViewportState::to_type_erased(),
LayerState::to_type_erased(),
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/dom/mutations_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use freya_native_core::{
NodeId,
};
use freya_node_state::{
CursorSettings,
CursorState,
CustomAttributeValues,
LayerState,
};
Expand Down Expand Up @@ -63,8 +63,8 @@ impl<'a> MutationsWriter<'a> {
.remove_node_from_layer(node_id, layer_state.layer);

// Remove from paragraph elements
let cursor_settings = node.get::<CursorSettings>().unwrap();
if let Some(cursor_ref) = cursor_settings.cursor_ref.as_ref() {
let cursor_state = node.get::<CursorState>().unwrap();
if let Some(cursor_ref) = cursor_state.cursor_ref.as_ref() {
self.paragraphs
.remove_paragraph(node_id, &cursor_ref.text_id);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/events/events_measurer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use freya_native_core::{
};
use freya_node_state::{
Fill,
Style,
StyleState,
ViewportState,
};
use itertools::sorted;
Expand Down Expand Up @@ -232,7 +232,7 @@ fn measure_dom_events(
}
}

let Style { background, .. } = &*node.get::<Style>().unwrap();
let StyleState { background, .. } = &*node.get::<StyleState>().unwrap();

if background != &Fill::Color(Color::TRANSPARENT)
&& !event.get_name().does_go_through_solid()
Expand Down
28 changes: 16 additions & 12 deletions crates/core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use freya_native_core::real_dom::NodeImmutable;
use freya_node_state::{
Border,
CornerRadius,
CursorSettings,
CursorState,
Fill,
FontStyleState,
LayoutState,
References,
ReferencesState,
Shadow,
Style,
StyleState,
TextOverflow,
Transform,
TransformState,
};
use torin::{
alignment::Alignment,
Expand All @@ -24,17 +24,17 @@ use crate::dom::DioxusNode;

#[derive(Clone, PartialEq)]
pub struct NodeState {
pub cursor: CursorSettings,
pub cursor: CursorState,
pub font_style: FontStyleState,
pub references: References,
pub references: ReferencesState,
pub size: LayoutState,
pub style: Style,
pub transform: Transform,
pub style: StyleState,
pub transform: TransformState,
}

pub fn get_node_state(node: &DioxusNode) -> NodeState {
let cursor = node
.get::<CursorSettings>()
.get::<CursorState>()
.as_deref()
.cloned()
.unwrap_or_default();
Expand All @@ -44,7 +44,7 @@ pub fn get_node_state(node: &DioxusNode) -> NodeState {
.cloned()
.unwrap_or_default();
let references = node
.get::<References>()
.get::<ReferencesState>()
.as_deref()
.cloned()
.unwrap_or_default();
Expand All @@ -53,9 +53,13 @@ pub fn get_node_state(node: &DioxusNode) -> NodeState {
.as_deref()
.cloned()
.unwrap_or_default();
let style = node.get::<Style>().as_deref().cloned().unwrap_or_default();
let style = node
.get::<StyleState>()
.as_deref()
.cloned()
.unwrap_or_default();
let transform = node
.get::<Transform>()
.get::<TransformState>()
.as_deref()
.cloned()
.unwrap_or_default();
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/skia/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use freya_common::{
TextGroupMeasurement,
};
use freya_native_core::prelude::NodeImmutable;
use freya_node_state::CursorSettings;
use freya_node_state::CursorState;
use torin::prelude::{
CursorPoint,
LayoutNode,
Expand All @@ -32,17 +32,17 @@ pub fn measure_paragraph(
.unwrap()
.0;

let cursor_settings = node.get::<CursorSettings>().unwrap();
let cursor_state = node.get::<CursorState>().unwrap();

let scale_factors = scale_factor as f64;

if cursor_settings.cursor_id != Some(text_measurement.cursor_id) {
if cursor_state.cursor_id != Some(text_measurement.cursor_id) {
return;
}

let y = align_main_align_paragraph(node, &layout_node.area, paragraph);

if let Some(cursor_reference) = &cursor_settings.cursor_ref {
if let Some(cursor_reference) = &cursor_state.cursor_ref {
if let Some(cursor_position) = text_measurement.cursor_position {
let position = CursorPoint::new(cursor_position.x, cursor_position.y - y as f64);

Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/skia/skia_measurer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use freya_native_core::{
NodeId,
};
use freya_node_state::{
CursorSettings,
CursorState,
FontStyleState,
HighlightMode,
LayoutState,
Expand Down Expand Up @@ -166,12 +166,12 @@ pub fn align_highlights_and_cursor_paragraph(
cursor_rect: &TextBox,
width: Option<f32>,
) -> (Point2D, Point2D) {
let cursor_settings = node.get::<CursorSettings>().unwrap();
let cursor_state = node.get::<CursorState>().unwrap();

let x = area.min_x() + cursor_rect.rect.left;
let x2 = x + width.unwrap_or(cursor_rect.rect.right - cursor_rect.rect.left);

match cursor_settings.highlight_mode {
match cursor_state.highlight_mode {
HighlightMode::Fit => {
let y = area.min_y()
+ align_main_align_paragraph(node, area, paragraph)
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/skia/skia_renderer/image.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use freya_engine::prelude::*;
use freya_native_core::real_dom::NodeImmutable;
use freya_node_state::{
References,
Style,
ReferencesState,
StyleState,
};
use torin::geometry::Area;

use crate::dom::DioxusNode;

/// Render an `image` element
pub fn render_image(area: &Area, node_ref: &DioxusNode, canvas: &Canvas) {
let node_style = node_ref.get::<Style>().unwrap();
let node_references = node_ref.get::<References>().unwrap();
let node_style = node_ref.get::<StyleState>().unwrap();
let node_references = node_ref.get::<ReferencesState>().unwrap();

let draw_img = |bytes: &[u8]| {
let pic = Image::from_encoded(Data::new_copy(bytes));
Expand Down
18 changes: 9 additions & 9 deletions crates/core/src/skia/skia_renderer/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use freya_native_core::{
real_dom::NodeImmutable,
SendAnyMap,
};
use freya_node_state::CursorSettings;
use freya_node_state::CursorState;
use torin::geometry::Area;

use crate::{
Expand All @@ -28,7 +28,7 @@ pub fn render_paragraph(
default_fonts: &[String],
scale_factor: f32,
) {
let node_cursor_settings = &*dioxus_node.get::<CursorSettings>().unwrap();
let node_cursor_state = &*dioxus_node.get::<CursorState>().unwrap();

let paint = |paragraph: &Paragraph| {
let x = area.min_x();
Expand All @@ -43,7 +43,7 @@ pub fn render_paragraph(
paragraph.paint(canvas, (x, y));
};

if node_cursor_settings.position.is_some() {
if node_cursor_state.position.is_some() {
let paragraph = create_paragraph(
dioxus_node,
&area.size,
Expand All @@ -65,10 +65,10 @@ fn draw_cursor_highlights(
canvas: &Canvas,
dioxus_node: &DioxusNode,
) -> Option<()> {
let node_cursor_settings = &*dioxus_node.get::<CursorSettings>().unwrap();
let node_cursor_state = &*dioxus_node.get::<CursorState>().unwrap();

let highlights = node_cursor_settings.highlights.as_ref()?;
let highlight_color = node_cursor_settings.highlight_color;
let highlights = node_cursor_state.highlights.as_ref()?;
let highlight_color = node_cursor_state.highlight_color;

for (from, to) in highlights.iter() {
let (from, to) = {
Expand Down Expand Up @@ -110,10 +110,10 @@ fn draw_cursor(
canvas: &Canvas,
dioxus_node: &DioxusNode,
) -> Option<()> {
let node_cursor_settings = &*dioxus_node.get::<CursorSettings>().unwrap();
let node_cursor_state = &*dioxus_node.get::<CursorState>().unwrap();

let cursor = node_cursor_settings.position?;
let cursor_color = node_cursor_settings.color;
let cursor = node_cursor_state.position?;
let cursor_color = node_cursor_state.color;
let cursor_position = cursor as usize;

let cursor_rects = paragraph.get_rects_for_range(
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/skia/skia_renderer/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use freya_node_state::{
BorderAlignment,
BorderStyle,
Fill,
References,
ReferencesState,
ShadowPosition,
Style,
StyleState,
};
use torin::{
prelude::Area,
Expand All @@ -23,7 +23,7 @@ pub fn render_rect(
font_collection: &mut FontCollection,
scale_factor: f32,
) {
let node_style = &*node_ref.get::<Style>().unwrap();
let node_style = &*node_ref.get::<StyleState>().unwrap();

let mut paint = Paint::default();
let mut path = Path::new();
Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn render_rect(
canvas.draw_path(&border_path, &border_paint);
}

let references = node_ref.get::<References>().unwrap();
let references = node_ref.get::<ReferencesState>().unwrap();

if let Some(canvas_ref) = &references.canvas_ref {
(canvas_ref.runner)(canvas, font_collection, area, scale_factor);
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/skia/skia_renderer/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use freya_native_core::{
NodeId,
};
use freya_node_state::{
Style,
Transform,
StyleState,
TransformState,
ViewportState,
};
use torin::{
Expand Down Expand Up @@ -67,8 +67,8 @@ impl SkiaRenderer<'_> {
if let NodeType::Element(ElementNode { tag, .. }) = node_type {
self.canvas.save();

let node_transform = &*dioxus_node.get::<Transform>().unwrap();
let node_style = &*dioxus_node.get::<Style>().unwrap();
let node_transform = &*dioxus_node.get::<TransformState>().unwrap();
let node_style = &*dioxus_node.get::<StyleState>().unwrap();

// Pass rotate effect to children
if let Some(rotate_degs) = node_transform.rotate_degs {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/skia/skia_renderer/svg.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use freya_engine::prelude::*;
use freya_native_core::real_dom::NodeImmutable;
use freya_node_state::Style;
use freya_node_state::StyleState;
use torin::geometry::Area;

use crate::dom::DioxusNode;

/// Render a `svg` element
pub fn render_svg(area: &Area, node_ref: &DioxusNode, canvas: &Canvas, font_manager: &FontMgr) {
let node_style = &*node_ref.get::<Style>().unwrap();
let node_style = &*node_ref.get::<StyleState>().unwrap();

let x = area.min_x();
let y = area.min_y();
Expand Down
6 changes: 3 additions & 3 deletions crates/state/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
};

#[derive(Clone, Debug, PartialEq, Component)]
pub struct CursorSettings {
pub struct CursorState {
pub position: Option<i32>,
pub color: Color,
pub mode: CursorMode,
Expand All @@ -36,7 +36,7 @@ pub struct CursorSettings {
pub cursor_ref: Option<CursorReference>,
}

impl Default for CursorSettings {
impl Default for CursorState {
fn default() -> Self {
Self {
position: None,
Expand All @@ -52,7 +52,7 @@ impl Default for CursorSettings {
}

#[partial_derive_state]
impl State<CustomAttributeValues> for CursorSettings {
impl State<CustomAttributeValues> for CursorState {
type ParentDependencies = (Self,);

type ChildDependencies = ();
Expand Down
2 changes: 1 addition & 1 deletion crates/state/src/font_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl FontStyleState {

text_style
.set_color(self.color)
.set_font_style(freya_engine::prelude::FontStyle::new(
.set_font_style(FontStyle::new(
self.font_weight,
self.font_width,
self.font_slant,
Expand Down
Loading