Skip to content

Commit

Permalink
feat: Devtools fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Nov 3, 2023
1 parent f3813c1 commit c487a8b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
37 changes: 32 additions & 5 deletions crates/core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use freya_dom::prelude::DioxusNode;
use freya_engine::prelude::*;
use freya_node_state::{
Border, CornerRadius, CursorSettings, Fill, FontStyleState, LayoutState, References, Shadow,
Style, Transform,
Style, TextOverflow, Transform,
};
use torin::{alignment::Alignment, direction::DirectionMode, gaps::Gaps, size::Size};

Expand Down Expand Up @@ -114,20 +114,28 @@ impl<'a> Iterator for NodeStateIterator<'a> {
"line_height",
AttributeType::Measure(self.state.font_style.line_height),
)),
17 => Some(("offset_x", AttributeType::Measure(self.state.size.offset_x))),
18 => Some(("offset_y", AttributeType::Measure(self.state.size.offset_y))),
17 => Some((
"text_align",
AttributeType::TextAlignment(&self.state.font_style.text_align),
)),
18 => Some((
"text_overflow",
AttributeType::TextOverflow(&self.state.font_style.text_overflow),
)),
19 => Some(("offset_x", AttributeType::Measure(self.state.size.offset_x))),
20 => Some(("offset_y", AttributeType::Measure(self.state.size.offset_y))),
n => {
let shadows = &self.state.style.shadows;
let shadow = shadows
.get(n - 19)
.get(n - 21)
.map(|shadow| ("shadow", AttributeType::Shadow(shadow)));

if shadow.is_some() {
shadow
} else {
let text_shadows = &self.state.font_style.text_shadows;
text_shadows
.get(n - 19 + shadows.len())
.get(n - 21 + shadows.len())
.map(|text_shadow| ("text_shadow", AttributeType::TextShadow(text_shadow)))
}
}
Expand Down Expand Up @@ -155,4 +163,23 @@ pub enum AttributeType<'a> {
TextShadow(&'a TextShadow),
Text(String),
Border(&'a Border),
TextAlignment(&'a TextAlign),
TextOverflow(&'a TextOverflow),
}

pub trait ExternalPretty {
fn pretty(&self) -> String;
}

impl ExternalPretty for TextAlign {
fn pretty(&self) -> String {
match self {
TextAlign::Left => "left".to_string(),
TextAlign::Right => "right".to_string(),
TextAlign::Center => "center".to_string(),
TextAlign::Justify => "justify".to_string(),
TextAlign::Start => "start".to_string(),
TextAlign::End => "end".to_string(),
}
}
}
18 changes: 18 additions & 0 deletions crates/devtools/src/tabs/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ pub fn NodeInspectorStyle(cx: Scope, node_id: NodeId) -> Element {
}
}
}
AttributeType::TextAlignment(text_align) => {
rsx!{
Property {
key: "{i}",
name: "{name}",
value: text_align.pretty()
}
}
}
AttributeType::TextOverflow(text_overflow) => {
rsx!{
Property {
key: "{i}",
name: "{name}",
value: text_overflow.pretty()
}
}
}
}
})
}
Expand Down
8 changes: 8 additions & 0 deletions crates/state/src/values/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ impl TextOverflow {
Self::Custom(custom) => Some(custom),
}
}

pub fn pretty(&self) -> String {
match self {
TextOverflow::Clip => "clip".to_string(),
TextOverflow::Ellipsis => "ellipsis".to_string(),
TextOverflow::Custom(text_overflow) => text_overflow.to_string(),
}
}
}

#[derive(Debug, PartialEq, Eq)]
Expand Down
6 changes: 5 additions & 1 deletion crates/torin/src/values/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ impl Alignment {
}

pub fn pretty(&self) -> String {
format!("{self:?}")
match self {
Alignment::Start => "start".to_string(),
Alignment::Center => "center".to_string(),
Alignment::End => "end".to_string(),
}
}
}
2 changes: 1 addition & 1 deletion crates/torin/src/values/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Default for Size {
impl Size {
pub fn pretty(&self) -> String {
match self {
Size::Inner => "inner".to_string(),
Size::Inner => "auto".to_string(),
Size::Pixels(s) => format!("{}", s.get()),
Size::DynamicCalculations(calcs) => format!(
"calc({})",
Expand Down

0 comments on commit c487a8b

Please sign in to comment.