bugfixes, docs, and pass clippy
This commit is contained in:
1 parent
5b25500c0b
commit
32b2e3a135
11 files changed
+350
-306
No files matched your search
@@ -1,6 +1,18 @@
|
||||
#[derive(Default, Clone, Copy)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Config {
|
||||
pub rendering_mode: RenderingMode,
|
||||
/// Should the terminal quit when the user presses `ctrl+c`?
|
||||
/// To handle quiting on your own, use the [crate::TuiContext] root context.
|
||||
pub ctrl_c_quit: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
rendering_mode: Default::default(),
|
||||
ctrl_c_quit: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
||||
+94
-109
@@ -5,8 +5,7 @@ use dioxus_core::*;
|
||||
use fxhash::{FxHashMap, FxHashSet};
|
||||
|
||||
use dioxus_html::{on::*, KeyCode};
|
||||
use dioxus_native_core::real_dom::{RealDom, TreeNode};
|
||||
use futures::{channel::mpsc::UnboundedReceiver, StreamExt};
|
||||
use dioxus_native_core::real_dom::{Node, RealDom};
|
||||
use std::{
|
||||
any::Any,
|
||||
cell::RefCell,
|
||||
@@ -162,7 +161,7 @@ impl InnerInputState {
|
||||
}
|
||||
}
|
||||
|
||||
fn update<'a>(
|
||||
fn update(
|
||||
&mut self,
|
||||
evts: &mut Vec<EventCore>,
|
||||
resolved_events: &mut Vec<UserEvent>,
|
||||
@@ -176,9 +175,11 @@ impl InnerInputState {
|
||||
|
||||
self.wheel = None;
|
||||
|
||||
println!("update {evts:?}");
|
||||
for e in evts.iter_mut() {
|
||||
self.apply_event(e);
|
||||
}
|
||||
println!("->update {evts:?}");
|
||||
|
||||
self.resolve_mouse_events(previous_mouse, resolved_events, layout, tree);
|
||||
|
||||
@@ -216,7 +217,7 @@ impl InnerInputState {
|
||||
data: Arc<dyn Any + Send + Sync>,
|
||||
will_bubble: &mut FxHashSet<ElementId>,
|
||||
resolved_events: &mut Vec<UserEvent>,
|
||||
node: &TreeNode<StretchLayout, StyleModifier>,
|
||||
node: &Node<StretchLayout, StyleModifier>,
|
||||
tree: &RealDom<StretchLayout, StyleModifier>,
|
||||
) {
|
||||
// only trigger event if the event was not triggered already by a child
|
||||
@@ -231,7 +232,7 @@ impl InnerInputState {
|
||||
priority: EventPriority::Medium,
|
||||
name,
|
||||
element: Some(node.id),
|
||||
data: data,
|
||||
data,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -269,17 +270,15 @@ impl InnerInputState {
|
||||
.is_some();
|
||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||
|
||||
if currently_contains {
|
||||
if previously_contained {
|
||||
try_create_event(
|
||||
"mousemove",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
if currently_contains && previously_contained {
|
||||
try_create_event(
|
||||
"mousemove",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,17 +294,15 @@ impl InnerInputState {
|
||||
.is_some();
|
||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||
|
||||
if currently_contains {
|
||||
if !previously_contained {
|
||||
try_create_event(
|
||||
"mouseenter",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
if currently_contains && !previously_contained {
|
||||
try_create_event(
|
||||
"mouseenter",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -321,17 +318,15 @@ impl InnerInputState {
|
||||
.is_some();
|
||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||
|
||||
if currently_contains {
|
||||
if !previously_contained {
|
||||
try_create_event(
|
||||
"mouseover",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
if currently_contains && !previously_contained {
|
||||
try_create_event(
|
||||
"mouseover",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -343,17 +338,15 @@ impl InnerInputState {
|
||||
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
|
||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||
|
||||
if currently_contains {
|
||||
if data.clicked {
|
||||
try_create_event(
|
||||
"mousedown",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
if currently_contains && data.clicked {
|
||||
try_create_event(
|
||||
"mousedown",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -365,17 +358,15 @@ impl InnerInputState {
|
||||
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
|
||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||
|
||||
if currently_contains {
|
||||
if data.released {
|
||||
try_create_event(
|
||||
"mouseup",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
if currently_contains && data.released {
|
||||
try_create_event(
|
||||
"mouseup",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -387,17 +378,15 @@ impl InnerInputState {
|
||||
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
|
||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||
|
||||
if currently_contains {
|
||||
if data.released && data.mouse_data.button == 0 {
|
||||
try_create_event(
|
||||
"click",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
if currently_contains && data.released && data.mouse_data.button == 0 {
|
||||
try_create_event(
|
||||
"click",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -409,17 +398,15 @@ impl InnerInputState {
|
||||
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
|
||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||
|
||||
if currently_contains {
|
||||
if data.released && data.mouse_data.button == 2 {
|
||||
try_create_event(
|
||||
"contextmenu",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
if currently_contains && data.released && data.mouse_data.button == 2 {
|
||||
try_create_event(
|
||||
"contextmenu",
|
||||
Arc::new(clone_mouse_data(data.mouse_data)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,18 +418,16 @@ impl InnerInputState {
|
||||
let node_layout = layout.layout(node.up_state.node.unwrap()).unwrap();
|
||||
let currently_contains = layout_contains_point(node_layout, data.new_pos);
|
||||
|
||||
if currently_contains {
|
||||
if let Some(w) = data.wheel_data {
|
||||
if data.wheel_delta != 0.0 {
|
||||
try_create_event(
|
||||
"wheel",
|
||||
Arc::new(clone_wheel_data(w)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
if let Some(w) = data.wheel_data {
|
||||
if currently_contains && data.wheel_delta != 0.0 {
|
||||
try_create_event(
|
||||
"wheel",
|
||||
Arc::new(clone_wheel_data(w)),
|
||||
&mut will_bubble,
|
||||
resolved_events,
|
||||
node,
|
||||
tree,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -511,24 +496,22 @@ pub struct RinkInputHandler {
|
||||
impl RinkInputHandler {
|
||||
/// global context that handles events
|
||||
/// limitations: GUI key modifier is never detected, key up events are not detected, and only two mouse buttons may be pressed at once
|
||||
pub fn new(
|
||||
mut receiver: UnboundedReceiver<TermEvent>,
|
||||
cx: &ScopeState,
|
||||
) -> (Self, Rc<RefCell<InnerInputState>>) {
|
||||
pub fn new() -> (
|
||||
Self,
|
||||
Rc<RefCell<InnerInputState>>,
|
||||
impl FnMut(crossterm::event::Event),
|
||||
) {
|
||||
let queued_events = Rc::new(RefCell::new(Vec::new()));
|
||||
let queued_events2 = Rc::downgrade(&queued_events);
|
||||
|
||||
cx.push_future(async move {
|
||||
while let Some(evt) = receiver.next().await {
|
||||
if let Some(evt) = get_event(evt) {
|
||||
if let Some(v) = queued_events2.upgrade() {
|
||||
(*v).borrow_mut().push(evt);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
let regester_event = move |evt: crossterm::event::Event| {
|
||||
if let Some(evt) = get_event(evt) {
|
||||
if let Some(v) = queued_events2.upgrade() {
|
||||
println!("queued event: {:?}", evt);
|
||||
(*v).borrow_mut().push(evt);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let state = Rc::new(RefCell::new(InnerInputState::new()));
|
||||
|
||||
@@ -538,14 +521,16 @@ impl RinkInputHandler {
|
||||
queued_events,
|
||||
},
|
||||
state,
|
||||
regester_event,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_events<'a>(
|
||||
pub fn get_events(
|
||||
&self,
|
||||
layout: &Stretch,
|
||||
tree: &mut RealDom<StretchLayout, StyleModifier>,
|
||||
) -> Vec<UserEvent> {
|
||||
println!("get_events");
|
||||
let mut resolved_events = Vec::new();
|
||||
|
||||
(*self.state).borrow_mut().update(
|
||||
@@ -799,7 +784,7 @@ fn translate_key_event(event: crossterm::event::KeyEvent) -> Option<EventData> {
|
||||
// from https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
|
||||
Some(EventData::Keyboard(KeyboardData {
|
||||
char_code: code.raw_code(),
|
||||
key: key_str.to_string(),
|
||||
key: key_str,
|
||||
key_code: code,
|
||||
alt_key: event.modifiers.contains(KeyModifiers::ALT),
|
||||
ctrl_key: event.modifiers.contains(KeyModifiers::CONTROL),
|
||||
|
||||
@@ -65,7 +65,7 @@ impl BubbledUpState for StretchLayout {
|
||||
}
|
||||
|
||||
if let Some(n) = self.node {
|
||||
if &stretch.children(n).unwrap() != &child_layout {
|
||||
if stretch.children(n).unwrap() != child_layout {
|
||||
stretch.set_children(n, &child_layout).unwrap();
|
||||
}
|
||||
if self.style != style {
|
||||
|
||||
+40
-28
@@ -1,6 +1,3 @@
|
||||
// notes:
|
||||
// mouse events binary search was broken for absolutely positioned elements
|
||||
|
||||
use anyhow::Result;
|
||||
use crossterm::{
|
||||
event::{DisableMouseCapture, EnableMouseCapture, Event as TermEvent, KeyCode, KeyModifiers},
|
||||
@@ -48,11 +45,8 @@ pub fn launch(app: Component<()>) {
|
||||
|
||||
pub fn launch_cfg(app: Component<()>, cfg: Config) {
|
||||
let mut dom = VirtualDom::new(app);
|
||||
let (tx, rx) = unbounded();
|
||||
|
||||
let cx = dom.base_scope();
|
||||
|
||||
let (handler, state) = RinkInputHandler::new(rx, cx);
|
||||
let (handler, state, register_event) = RinkInputHandler::new();
|
||||
|
||||
// Setup input handling
|
||||
let (event_tx, event_rx) = unbounded();
|
||||
@@ -70,6 +64,7 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
|
||||
}
|
||||
});
|
||||
|
||||
let cx = dom.base_scope();
|
||||
cx.provide_root_context(state);
|
||||
cx.provide_root_context(TuiContext { tx: event_tx_clone });
|
||||
|
||||
@@ -81,17 +76,26 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
|
||||
.update_state(&dom, to_update, &mut stretch, &mut ())
|
||||
.unwrap();
|
||||
|
||||
render_vdom(&mut dom, tx, event_rx, handler, cfg, tree, stretch).unwrap();
|
||||
render_vdom(
|
||||
&mut dom,
|
||||
event_rx,
|
||||
handler,
|
||||
cfg,
|
||||
tree,
|
||||
stretch,
|
||||
register_event,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn render_vdom(
|
||||
vdom: &mut VirtualDom,
|
||||
crossterm_event_sender: UnboundedSender<TermEvent>,
|
||||
mut event_reciever: UnboundedReceiver<InputEvent>,
|
||||
handler: RinkInputHandler,
|
||||
cfg: Config,
|
||||
mut tree: RealDom<StretchLayout, StyleModifier>,
|
||||
mut stretch: Stretch,
|
||||
mut register_event: impl FnMut(crossterm::event::Event),
|
||||
) -> Result<()> {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
@@ -105,7 +109,7 @@ fn render_vdom(
|
||||
|
||||
terminal.clear().unwrap();
|
||||
let mut to_rerender: fxhash::FxHashSet<usize> = vec![0].into_iter().collect();
|
||||
let mut redraw = true;
|
||||
let mut resized = true;
|
||||
|
||||
loop {
|
||||
/*
|
||||
@@ -119,8 +123,8 @@ fn render_vdom(
|
||||
todo: lazy re-rendering
|
||||
*/
|
||||
|
||||
if !to_rerender.is_empty() || redraw {
|
||||
redraw = false;
|
||||
if !to_rerender.is_empty() || resized {
|
||||
resized = false;
|
||||
terminal.draw(|frame| {
|
||||
// size is guaranteed to not change when rendering
|
||||
let dims = frame.size();
|
||||
@@ -138,8 +142,8 @@ fn render_vdom(
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let root = &tree[tree.root_id()];
|
||||
render::render_vnode(frame, &stretch, &tree, &root, cfg);
|
||||
// let root = &tree[tree.root_id()];
|
||||
// render::render_vnode(frame, &stretch, &tree, &root, cfg);
|
||||
})?;
|
||||
}
|
||||
|
||||
@@ -158,35 +162,44 @@ fn render_vdom(
|
||||
TermEvent::Key(key) => {
|
||||
if matches!(key.code, KeyCode::Char('C' | 'c'))
|
||||
&& key.modifiers.contains(KeyModifiers::CONTROL)
|
||||
&& cfg.ctrl_c_quit
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
TermEvent::Resize(_, _) => redraw = true,
|
||||
TermEvent::Resize(_, _) => resized = true,
|
||||
TermEvent::Mouse(_) => {}
|
||||
},
|
||||
InputEvent::Close => break,
|
||||
};
|
||||
|
||||
if let InputEvent::UserInput(evt) = evt.unwrap() {
|
||||
crossterm_event_sender.unbounded_send(evt).unwrap();
|
||||
register_event(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// resolve events before rendering
|
||||
for e in handler.get_events(&stretch, &mut tree) {
|
||||
vdom.handle_message(SchedulerMsg::Event(e));
|
||||
{
|
||||
// resolve events before rendering
|
||||
let evts = handler.get_events(&stretch, &mut tree);
|
||||
println!("evts: {:?}", evts);
|
||||
for e in evts {
|
||||
vdom.handle_message(SchedulerMsg::Event(e));
|
||||
}
|
||||
let mutations = vdom.work_with_deadline(|| false);
|
||||
// updates the tree's nodes
|
||||
let to_update = tree.apply_mutations(mutations);
|
||||
// update the style and layout
|
||||
to_rerender.extend(
|
||||
tree.update_state(vdom, to_update, &mut stretch, &mut ())
|
||||
.unwrap()
|
||||
.iter(),
|
||||
)
|
||||
}
|
||||
vdom.process_all_messages();
|
||||
let mutations = vdom.work_with_deadline(|| false);
|
||||
// updates the tree's nodes
|
||||
let to_update = tree.apply_mutations(mutations);
|
||||
// update the style and layout
|
||||
to_rerender = tree
|
||||
.update_state(&vdom, to_update, &mut stretch, &mut ())
|
||||
.unwrap();
|
||||
println!();
|
||||
println!();
|
||||
println!();
|
||||
}
|
||||
|
||||
disable_raw_mode()?;
|
||||
@@ -203,6 +216,5 @@ fn render_vdom(
|
||||
|
||||
enum InputEvent {
|
||||
UserInput(TermEvent),
|
||||
#[allow(dead_code)]
|
||||
Close,
|
||||
}
|
||||
+13
-14
@@ -1,7 +1,7 @@
|
||||
use crate::layout::StretchLayout;
|
||||
use dioxus_native_core::{
|
||||
layout_attributes::UnitSystem,
|
||||
real_dom::{RealDom, TreeNode},
|
||||
real_dom::{Node, RealDom},
|
||||
};
|
||||
use std::io::Stdout;
|
||||
use stretch2::{
|
||||
@@ -20,18 +20,17 @@ use crate::{
|
||||
|
||||
const RADIUS_MULTIPLIER: [f32; 2] = [1.0, 0.5];
|
||||
|
||||
pub fn render_vnode<'a>(
|
||||
pub fn render_vnode(
|
||||
frame: &mut tui::Frame<CrosstermBackend<Stdout>>,
|
||||
layout: &Stretch,
|
||||
tree: &RealDom<StretchLayout, StyleModifier>,
|
||||
node: &TreeNode<StretchLayout, StyleModifier>,
|
||||
node: &Node<StretchLayout, StyleModifier>,
|
||||
cfg: Config,
|
||||
) {
|
||||
use dioxus_native_core::real_dom::TreeNodeType;
|
||||
use dioxus_native_core::real_dom::NodeType;
|
||||
|
||||
match &node.node_type {
|
||||
TreeNodeType::Placeholder => return,
|
||||
_ => (),
|
||||
if let NodeType::Placeholder = &node.node_type {
|
||||
return;
|
||||
}
|
||||
|
||||
let Layout { location, size, .. } = layout.layout(node.up_state.node.unwrap()).unwrap();
|
||||
@@ -40,7 +39,7 @@ pub fn render_vnode<'a>(
|
||||
let Size { width, height } = size;
|
||||
|
||||
match &node.node_type {
|
||||
TreeNodeType::Text { text } => {
|
||||
NodeType::Text { text } => {
|
||||
#[derive(Default)]
|
||||
struct Label<'a> {
|
||||
text: &'a str,
|
||||
@@ -59,7 +58,7 @@ pub fn render_vnode<'a>(
|
||||
}
|
||||
|
||||
let label = Label {
|
||||
text: &text,
|
||||
text,
|
||||
style: node.down_state.style,
|
||||
};
|
||||
let area = Rect::new(*x as u16, *y as u16, *width as u16, *height as u16);
|
||||
@@ -69,7 +68,7 @@ pub fn render_vnode<'a>(
|
||||
frame.render_widget(WidgetWithContext::new(label, cfg), area);
|
||||
}
|
||||
}
|
||||
TreeNodeType::Element { children, .. } => {
|
||||
NodeType::Element { children, .. } => {
|
||||
let area = Rect::new(*x as u16, *y as u16, *width as u16, *height as u16);
|
||||
|
||||
// the renderer will panic if a node is rendered out of range even if the size is zero
|
||||
@@ -81,11 +80,11 @@ pub fn render_vnode<'a>(
|
||||
render_vnode(frame, layout, tree, &tree[c.0], cfg);
|
||||
}
|
||||
}
|
||||
TreeNodeType::Placeholder => unreachable!(),
|
||||
NodeType::Placeholder => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
impl RinkWidget for &TreeNode<StretchLayout, StyleModifier> {
|
||||
impl RinkWidget for &Node<StretchLayout, StyleModifier> {
|
||||
fn render(self, area: Rect, mut buf: RinkBuffer<'_>) {
|
||||
use tui::symbols::line::*;
|
||||
|
||||
@@ -249,8 +248,8 @@ impl RinkWidget for &TreeNode<StretchLayout, StyleModifier> {
|
||||
|
||||
fn get_radius(border: &BorderEdge, area: Rect) -> f32 {
|
||||
match border.style {
|
||||
BorderStyle::HIDDEN => 0.0,
|
||||
BorderStyle::NONE => 0.0,
|
||||
BorderStyle::Hidden => 0.0,
|
||||
BorderStyle::None => 0.0,
|
||||
_ => match border.radius {
|
||||
UnitSystem::Percent(p) => p * area.width as f32 / 100.0,
|
||||
UnitSystem::Point(p) => p,
|
||||
|
||||
@@ -51,33 +51,28 @@ impl PushedDownState for StyleModifier {
|
||||
if parent.is_some() {
|
||||
self.style.fg = None;
|
||||
}
|
||||
match vnode {
|
||||
VNode::Element(el) => {
|
||||
// handle text modifier elements
|
||||
if el.namespace.is_none() {
|
||||
match el.tag {
|
||||
"b" => apply_style_attributes("font-weight", "bold", self),
|
||||
"strong" => apply_style_attributes("font-weight", "bold", self),
|
||||
"u" => apply_style_attributes("text-decoration", "underline", self),
|
||||
"ins" => apply_style_attributes("text-decoration", "underline", self),
|
||||
"del" => apply_style_attributes("text-decoration", "line-through", self),
|
||||
"i" => apply_style_attributes("font-style", "italic", self),
|
||||
"em" => apply_style_attributes("font-style", "italic", self),
|
||||
"mark" => apply_style_attributes(
|
||||
"background-color",
|
||||
"rgba(241, 231, 64, 50%)",
|
||||
self,
|
||||
),
|
||||
_ => (),
|
||||
if let VNode::Element(el) = vnode {
|
||||
// handle text modifier elements
|
||||
if el.namespace.is_none() {
|
||||
match el.tag {
|
||||
"b" => apply_style_attributes("font-weight", "bold", self),
|
||||
"strong" => apply_style_attributes("font-weight", "bold", self),
|
||||
"u" => apply_style_attributes("text-decoration", "underline", self),
|
||||
"ins" => apply_style_attributes("text-decoration", "underline", self),
|
||||
"del" => apply_style_attributes("text-decoration", "line-through", self),
|
||||
"i" => apply_style_attributes("font-style", "italic", self),
|
||||
"em" => apply_style_attributes("font-style", "italic", self),
|
||||
"mark" => {
|
||||
apply_style_attributes("background-color", "rgba(241, 231, 64, 50%)", self)
|
||||
}
|
||||
}
|
||||
|
||||
// gather up all the styles from the attribute list
|
||||
for &Attribute { name, value, .. } in el.attributes {
|
||||
apply_style_attributes(name, value, self);
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
||||
// gather up all the styles from the attribute list
|
||||
for &Attribute { name, value, .. } in el.attributes {
|
||||
apply_style_attributes(name, value, self);
|
||||
}
|
||||
}
|
||||
|
||||
// keep the text styling from the parent element
|
||||
@@ -125,7 +120,7 @@ impl Default for BorderEdge {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
color: None,
|
||||
style: BorderStyle::NONE,
|
||||
style: BorderStyle::None,
|
||||
width: UnitSystem::Point(0.0),
|
||||
radius: UnitSystem::Point(0.0),
|
||||
}
|
||||
@@ -134,16 +129,16 @@ impl Default for BorderEdge {
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum BorderStyle {
|
||||
DOTTED,
|
||||
DASHED,
|
||||
SOLID,
|
||||
DOUBLE,
|
||||
GROOVE,
|
||||
RIDGE,
|
||||
INSET,
|
||||
OUTSET,
|
||||
HIDDEN,
|
||||
NONE,
|
||||
Dotted,
|
||||
Dashed,
|
||||
Solid,
|
||||
Double,
|
||||
Groove,
|
||||
Ridge,
|
||||
Inset,
|
||||
Outset,
|
||||
Hidden,
|
||||
None,
|
||||
}
|
||||
|
||||
impl BorderStyle {
|
||||
@@ -160,16 +155,16 @@ impl BorderStyle {
|
||||
..NORMAL
|
||||
};
|
||||
match self {
|
||||
BorderStyle::DOTTED => Some(DOTTED),
|
||||
BorderStyle::DASHED => Some(DASHED),
|
||||
BorderStyle::SOLID => Some(NORMAL),
|
||||
BorderStyle::DOUBLE => Some(DOUBLE),
|
||||
BorderStyle::GROOVE => Some(NORMAL),
|
||||
BorderStyle::RIDGE => Some(NORMAL),
|
||||
BorderStyle::INSET => Some(NORMAL),
|
||||
BorderStyle::OUTSET => Some(NORMAL),
|
||||
BorderStyle::HIDDEN => None,
|
||||
BorderStyle::NONE => None,
|
||||
BorderStyle::Dotted => Some(DOTTED),
|
||||
BorderStyle::Dashed => Some(DASHED),
|
||||
BorderStyle::Solid => Some(NORMAL),
|
||||
BorderStyle::Double => Some(DOUBLE),
|
||||
BorderStyle::Groove => Some(NORMAL),
|
||||
BorderStyle::Ridge => Some(NORMAL),
|
||||
BorderStyle::Inset => Some(NORMAL),
|
||||
BorderStyle::Outset => Some(NORMAL),
|
||||
BorderStyle::Hidden => None,
|
||||
BorderStyle::None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,16 +329,16 @@ fn apply_background(name: &str, value: &str, style: &mut StyleModifier) {
|
||||
fn apply_border(name: &str, value: &str, style: &mut StyleModifier) {
|
||||
fn parse_border_style(v: &str) -> BorderStyle {
|
||||
match v {
|
||||
"dotted" => BorderStyle::DOTTED,
|
||||
"dashed" => BorderStyle::DASHED,
|
||||
"solid" => BorderStyle::SOLID,
|
||||
"double" => BorderStyle::DOUBLE,
|
||||
"groove" => BorderStyle::GROOVE,
|
||||
"ridge" => BorderStyle::RIDGE,
|
||||
"inset" => BorderStyle::INSET,
|
||||
"outset" => BorderStyle::OUTSET,
|
||||
"none" => BorderStyle::NONE,
|
||||
"hidden" => BorderStyle::HIDDEN,
|
||||
"dotted" => BorderStyle::Dotted,
|
||||
"dashed" => BorderStyle::Dashed,
|
||||
"solid" => BorderStyle::Solid,
|
||||
"double" => BorderStyle::Double,
|
||||
"groove" => BorderStyle::Groove,
|
||||
"ridge" => BorderStyle::Ridge,
|
||||
"inset" => BorderStyle::Inset,
|
||||
"outset" => BorderStyle::Outset,
|
||||
"none" => BorderStyle::None,
|
||||
"hidden" => BorderStyle::Hidden,
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
@@ -505,7 +500,7 @@ fn apply_border(name: &str, value: &str, style: &mut StyleModifier) {
|
||||
.zip(style.modifier.borders.slice().iter_mut())
|
||||
{
|
||||
if let Some(w) = parse_value(v) {
|
||||
width.width = w.into();
|
||||
width.width = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user