Skip to content

Commit

Permalink
renderer compiles again!
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed Sep 19, 2024
1 parent 6b952fd commit f2c82ee
Show file tree
Hide file tree
Showing 21 changed files with 371 additions and 278 deletions.
2 changes: 1 addition & 1 deletion crates/gosub_css3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod matcher;
pub mod node;
pub mod parser;
pub mod stylesheet;
mod system;
pub mod system;
pub mod tokenizer;
mod unicode;
pub mod walker;
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_css3/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::stylesheet::{CssDeclaration, CssValue, Specificity};
use gosub_shared::types::Result;

#[derive(Debug, Clone)]
struct Css3System;
pub struct Css3System;

impl CssSystem for Css3System {
type Stylesheet = crate::stylesheet::CssStylesheet;
Expand Down
25 changes: 25 additions & 0 deletions crates/gosub_html5/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,31 @@ pub struct Html5Parser<'chars, D: Document<C>, C: CssSystem> {
context_doc: Option<DocumentHandle<D, C>>,
}

impl<D: Document<C>, C: CssSystem> gosub_shared::traits::html5::Html5Parser<C>
for Html5Parser<'_, D, C>
{
type Document = D;
type Options = Html5ParserOptions;

fn parse(
stream: &mut ByteStream,
doc: DocumentHandle<Self::Document, C>,
opts: Option<Self::Options>,
) -> Result<Vec<ParseError>> {
Self::parse_document(stream, doc, opts)
}

fn parse_fragment(
stream: &mut ByteStream,
doc: DocumentHandle<Self::Document, C>,
context_node: &<Self::Document as Document<C>>::Node,
options: Option<Self::Options>,
start_location: Location,
) -> Result<Vec<ParseError>> {
Self::parse_fragment(stream, doc, context_node, options, start_location)
}
}

/// Defines the scopes for in_scope()
#[derive(Clone, Copy)]
enum Scope {
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_render_backend/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub trait Layout: Default {
pub trait Node {
type Property: CssProperty;

fn get_property(&mut self, name: &str) -> Option<&mut Self::Property>;
fn get_property(&self, name: &str) -> Option<&Self::Property>;
fn text_data(&self) -> Option<&str>;

fn text_size(&self) -> Option<Size>;
Expand Down
1 change: 0 additions & 1 deletion crates/gosub_render_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use smallvec::SmallVec;
pub mod geo;
pub mod layout;
pub mod svg;
mod render_tree;

pub trait WindowHandle: HasDisplayHandle + HasWindowHandle + Send + Sync + Clone {}

Expand Down
3 changes: 2 additions & 1 deletion crates/gosub_render_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
//!

pub mod position;
pub mod macos_render_tree;
// pub mod macos_render_tree;
pub mod render_tree;
pub mod text;
10 changes: 5 additions & 5 deletions crates/gosub_render_utils/src/macos_render_tree.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::borrow::BorrowMut;
use std::{cell::RefCell, rc::Rc};
use gosub_html5::node::node::NodeDataTypeInternal;
use gosub_shared::document::DocumentHandle;

use crate::macos_render_tree::properties::Position;
use crate::macos_render_tree::{properties::Rectangle, text::TextNode};
use gosub_html5::node::node::NodeDataTypeInternal;
use gosub_shared::document::DocumentHandle;
use gosub_shared::traits::node::TextDataType;
use std::borrow::BorrowMut;
use std::{cell::RefCell, rc::Rc};

pub mod properties;
pub mod text;
Expand Down
11 changes: 8 additions & 3 deletions crates/gosub_render_utils/src/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use std::cmp::Ordering;

use rstar::{RTree, RTreeObject, AABB};

use crate::render_tree::RenderTree;
use gosub_render_backend::layout::{Layout, LayoutTree, Layouter};
use gosub_render_backend::RenderBackend;
use gosub_shared::node::NodeId;
use gosub_shared::traits::css3::CssSystem;
use gosub_shared::traits::document::Document;

#[derive(Debug)]
pub struct Element {
Expand Down Expand Up @@ -32,7 +35,9 @@ pub struct PositionTree {
}

impl PositionTree {
pub fn from_tree<B: RenderBackend, L: Layouter>(from_tree: &RenderTree<L>) -> Self {
pub fn from_tree<B: RenderBackend, L: Layouter, D: Document<C>, C: CssSystem>(
from_tree: &RenderTree<L, D, C>,
) -> Self {
let mut tree = RTree::new();

//TODO: we somehow need to get the border radius and a potential stacking context of the element here
Expand All @@ -42,8 +47,8 @@ impl PositionTree {
Self { tree }
}

fn add_node_to_tree<L: Layouter>(
from_tree: &RenderTree<L>,
fn add_node_to_tree<L: Layouter, D: Document<C>, C: CssSystem>(
from_tree: &RenderTree<L, D, C>,
id: NodeId,
z_index: i32,
tree: &mut RTree<Element>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use crate::geo::Size;
use crate::layout::{HasTextLayout, Layout, LayoutTree, Layouter, Node, TextLayout};
use gosub_html5::document::document::TreeIterator;
use gosub_html5::node::data::element::ElementData;
use gosub_render_backend::layout::{HasTextLayout, Layout, LayoutTree, Layouter, TextLayout};
use gosub_render_backend::{layout, Size};
use gosub_shared::document::DocumentHandle;
use gosub_shared::node::NodeId;
use gosub_shared::traits::css3::CssStylesheet;
use gosub_shared::traits::css3::{CssProperty, CssPropertyMap, CssSystem};
use gosub_shared::traits::document::Document;
use gosub_shared::traits::node::NodeData;
use gosub_shared::traits::node::{ElementDataType, Node as DocumentNode, TextDataType};
use gosub_shared::traits::node::{Node, NodeData};
use gosub_shared::types::Result;
use log::warn;
use std::collections::HashMap;
use std::fmt::{Debug, Formatter};
use std::marker::PhantomData;

mod desc;

Expand All @@ -30,7 +26,7 @@ pub struct RenderTree<L: Layouter, D: Document<C>, C: CssSystem> {
pub root: NodeId,
pub dirty: bool,
next_id: NodeId,
handle: Option<DocumentHandle<D, C>>,
pub handle: Option<DocumentHandle<D, C>>,
}

#[allow(unused)]
Expand Down Expand Up @@ -308,7 +304,7 @@ impl<L: Layouter, D: Document<C>, C: CssSystem> RenderTree<L, D, C> {

for id in self.nodes.keys() {
// Check CSS styles and remove if not renderable
if let Some(mut prop) = self.get_property(*id, "display") {
if let Some(prop) = self.get_property(*id, "display") {
if prop.as_string() == Some("none") {
delete_list.append(&mut self.get_child_node_ids(*id));
delete_list.push(*id);
Expand Down Expand Up @@ -602,11 +598,11 @@ impl<L: Layouter, C: CssSystem> HasTextLayout<L> for RenderTreeNode<L, C> {
}
}

impl<L: Layouter, C: CssSystem> Node for RenderTreeNode<L, C> {
impl<L: Layouter, C: CssSystem> layout::Node for RenderTreeNode<L, C> {
type Property = C::Property;

fn get_property(&mut self, name: &str) -> Option<&mut Self::Property> {
self.get_property(name)
fn get_property(&self, name: &str) -> Option<&Self::Property> {
self.properties.get(name)
}
fn text_data(&self) -> Option<&str> {
if let RenderNodeData::Text(text) = &self.data {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::layout::{Layout, Layouter};
use crate::render_tree::{RenderNodeData, RenderTree};
use crate::{NodeDesc, Point, Size};
use gosub_render_backend::layout::{Layout, Layouter};
use gosub_render_backend::{NodeDesc, Point, Size};
use gosub_shared::node::NodeId;
use gosub_shared::traits::css3::{CssPropertyMap, CssSystem};
use gosub_shared::traits::document::Document;
Expand Down
Loading

0 comments on commit f2c82ee

Please sign in to comment.