improved documentation and refactored naming to be more self-explanatory
This commit is contained in:
1 parent
e4d60c8dfc
commit
adfbb6c380
91 files changed
+1663
-1553
No files matched your search
+26
-25
@@ -83,36 +83,37 @@ impl State for Focus {
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
let new = Focus {
|
||||
level: if let Some(a) = node_view
|
||||
.attributes()
|
||||
.and_then(|mut a| a.find(|a| a.attribute.name == "tabindex"))
|
||||
{
|
||||
if let Some(index) = a
|
||||
.value
|
||||
.as_int()
|
||||
.or_else(|| a.value.as_text().and_then(|v| v.parse::<i64>().ok()))
|
||||
level:
|
||||
if let Some(a) = node_view
|
||||
.attributes()
|
||||
.and_then(|mut a| a.find(|a| a.attribute.name == "tabindex"))
|
||||
{
|
||||
match index.cmp(&0) {
|
||||
Ordering::Less => FocusLevel::Unfocusable,
|
||||
Ordering::Equal => FocusLevel::Focusable,
|
||||
Ordering::Greater => {
|
||||
FocusLevel::Ordered(NonZeroU16::new(index as u16).unwrap())
|
||||
if let Some(index) = a
|
||||
.value
|
||||
.as_int()
|
||||
.or_else(|| a.value.as_text().and_then(|v| v.parse::<i64>().ok()))
|
||||
{
|
||||
match index.cmp(&0) {
|
||||
Ordering::Less => FocusLevel::Unfocusable,
|
||||
Ordering::Equal => FocusLevel::Focusable,
|
||||
Ordering::Greater => {
|
||||
FocusLevel::Ordered(NonZeroU16::new(index as u16).unwrap())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
FocusLevel::Unfocusable
|
||||
}
|
||||
} else if node_view
|
||||
.listeners()
|
||||
.and_then(
|
||||
|mut listeners| listeners.any(|l| FOCUS_EVENTS.contains(&l)).then_some(())
|
||||
)
|
||||
.is_some()
|
||||
{
|
||||
FocusLevel::Focusable
|
||||
} else {
|
||||
FocusLevel::Unfocusable
|
||||
}
|
||||
} else if node_view
|
||||
.listeners()
|
||||
.and_then(|mut listeners| {
|
||||
listeners.any(|l| FOCUS_EVENTS.contains(&l)).then_some(())
|
||||
})
|
||||
.is_some()
|
||||
{
|
||||
FocusLevel::Focusable
|
||||
} else {
|
||||
FocusLevel::Unfocusable
|
||||
},
|
||||
},
|
||||
};
|
||||
if *self != new {
|
||||
*self = new;
|
||||
|
||||
+46
-44
@@ -585,13 +585,14 @@ impl RinkInputHandler {
|
||||
let queued_events = Rc::new(RefCell::new(Vec::new()));
|
||||
let queued_events2 = Rc::downgrade(&queued_events);
|
||||
|
||||
let regester_event = move |evt: crossterm::event::Event| {
|
||||
if let Some(evt) = get_event(evt) {
|
||||
if let Some(v) = queued_events2.upgrade() {
|
||||
(*v).borrow_mut().push(evt);
|
||||
let regester_event =
|
||||
move |evt: crossterm::event::Event| {
|
||||
if let Some(evt) = get_event(evt) {
|
||||
if let Some(v) = queued_events2.upgrade() {
|
||||
(*v).borrow_mut().push(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
let state = Rc::new(RefCell::new(InnerInputState::create(rdom)));
|
||||
|
||||
@@ -680,48 +681,49 @@ fn get_event(evt: TermEvent) -> Option<(&'static str, EventData)> {
|
||||
let ctrl = m.modifiers.contains(KeyModifiers::CONTROL);
|
||||
let meta = false;
|
||||
|
||||
let get_mouse_data = |crossterm_button: Option<MouseButton>| {
|
||||
let button = crossterm_button.map(|b| match b {
|
||||
MouseButton::Left => DioxusMouseButton::Primary,
|
||||
MouseButton::Right => DioxusMouseButton::Secondary,
|
||||
MouseButton::Middle => DioxusMouseButton::Auxiliary,
|
||||
});
|
||||
let get_mouse_data =
|
||||
|crossterm_button: Option<MouseButton>| {
|
||||
let button = crossterm_button.map(|b| match b {
|
||||
MouseButton::Left => DioxusMouseButton::Primary,
|
||||
MouseButton::Right => DioxusMouseButton::Secondary,
|
||||
MouseButton::Middle => DioxusMouseButton::Auxiliary,
|
||||
});
|
||||
|
||||
// from https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
|
||||
// from https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
|
||||
|
||||
// The `page` and `screen` coordinates are inconsistent with the MDN definition, as they are relative to the viewport (client), not the target element/page/screen, respectively.
|
||||
// todo?
|
||||
// But then, MDN defines them in terms of pixels, yet crossterm provides only row/column, and it might not be possible to get pixels. So we can't get 100% consistency anyway.
|
||||
let coordinates = Coordinates::new(
|
||||
ScreenPoint::new(x, y),
|
||||
ClientPoint::new(x, y),
|
||||
// offset x/y are set when the origin of the event is assigned to an element
|
||||
ElementPoint::new(0., 0.),
|
||||
PagePoint::new(x, y),
|
||||
);
|
||||
// The `page` and `screen` coordinates are inconsistent with the MDN definition, as they are relative to the viewport (client), not the target element/page/screen, respectively.
|
||||
// todo?
|
||||
// But then, MDN defines them in terms of pixels, yet crossterm provides only row/column, and it might not be possible to get pixels. So we can't get 100% consistency anyway.
|
||||
let coordinates = Coordinates::new(
|
||||
ScreenPoint::new(x, y),
|
||||
ClientPoint::new(x, y),
|
||||
// offset x/y are set when the origin of the event is assigned to an element
|
||||
ElementPoint::new(0., 0.),
|
||||
PagePoint::new(x, y),
|
||||
);
|
||||
|
||||
let mut modifiers = Modifiers::empty();
|
||||
if shift {
|
||||
modifiers.insert(Modifiers::SHIFT);
|
||||
}
|
||||
if ctrl {
|
||||
modifiers.insert(Modifiers::CONTROL);
|
||||
}
|
||||
if meta {
|
||||
modifiers.insert(Modifiers::META);
|
||||
}
|
||||
if alt {
|
||||
modifiers.insert(Modifiers::ALT);
|
||||
}
|
||||
let mut modifiers = Modifiers::empty();
|
||||
if shift {
|
||||
modifiers.insert(Modifiers::SHIFT);
|
||||
}
|
||||
if ctrl {
|
||||
modifiers.insert(Modifiers::CONTROL);
|
||||
}
|
||||
if meta {
|
||||
modifiers.insert(Modifiers::META);
|
||||
}
|
||||
if alt {
|
||||
modifiers.insert(Modifiers::ALT);
|
||||
}
|
||||
|
||||
// held mouse buttons get set later by maintaining state, as crossterm does not provide them
|
||||
EventData::Mouse(MouseData::new(
|
||||
coordinates,
|
||||
button,
|
||||
DioxusMouseButtons::empty(),
|
||||
modifiers,
|
||||
))
|
||||
};
|
||||
// held mouse buttons get set later by maintaining state, as crossterm does not provide them
|
||||
EventData::Mouse(MouseData::new(
|
||||
coordinates,
|
||||
button,
|
||||
DioxusMouseButtons::empty(),
|
||||
modifiers,
|
||||
))
|
||||
};
|
||||
|
||||
let get_wheel_data = |up| {
|
||||
let y = if up { -1.0 } else { 1.0 };
|
||||
|
||||
@@ -195,11 +195,12 @@ impl State for TaffyLayout {
|
||||
taffy.set_children(n, &child_layout).unwrap();
|
||||
}
|
||||
} else {
|
||||
self.node = PossiblyUninitalized::Initialized(
|
||||
taffy
|
||||
.new_with_children(scaled_style, &child_layout)
|
||||
.unwrap(),
|
||||
);
|
||||
self.node =
|
||||
PossiblyUninitalized::Initialized(
|
||||
taffy
|
||||
.new_with_children(scaled_style, &child_layout)
|
||||
.unwrap(),
|
||||
);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,27 +43,28 @@ impl State for PreventDefault {
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
let new = match node_view.attributes().and_then(|mut attrs| {
|
||||
attrs
|
||||
.find(|a| a.attribute.name == "dioxus-prevent-default")
|
||||
.and_then(|a| a.value.as_text())
|
||||
}) {
|
||||
Some("onfocus") => PreventDefault::Focus,
|
||||
Some("onkeypress") => PreventDefault::KeyPress,
|
||||
Some("onkeyrelease") => PreventDefault::KeyRelease,
|
||||
Some("onkeydown") => PreventDefault::KeyDown,
|
||||
Some("onkeyup") => PreventDefault::KeyUp,
|
||||
Some("onclick") => PreventDefault::Click,
|
||||
Some("onmousedown") => PreventDefault::MouseDown,
|
||||
Some("onmouseup") => PreventDefault::MouseUp,
|
||||
Some("onmouseenter") => PreventDefault::MouseEnter,
|
||||
Some("onmouseover") => PreventDefault::MouseOver,
|
||||
Some("onmouseleave") => PreventDefault::MouseLeave,
|
||||
Some("onmouseout") => PreventDefault::MouseOut,
|
||||
Some("onwheel") => PreventDefault::Wheel,
|
||||
Some("oncontextmenu") => PreventDefault::ContextMenu,
|
||||
_ => return false,
|
||||
};
|
||||
let new =
|
||||
match node_view.attributes().and_then(|mut attrs| {
|
||||
attrs
|
||||
.find(|a| a.attribute.name == "dioxus-prevent-default")
|
||||
.and_then(|a| a.value.as_text())
|
||||
}) {
|
||||
Some("onfocus") => PreventDefault::Focus,
|
||||
Some("onkeypress") => PreventDefault::KeyPress,
|
||||
Some("onkeyrelease") => PreventDefault::KeyRelease,
|
||||
Some("onkeydown") => PreventDefault::KeyDown,
|
||||
Some("onkeyup") => PreventDefault::KeyUp,
|
||||
Some("onclick") => PreventDefault::Click,
|
||||
Some("onmousedown") => PreventDefault::MouseDown,
|
||||
Some("onmouseup") => PreventDefault::MouseUp,
|
||||
Some("onmouseenter") => PreventDefault::MouseEnter,
|
||||
Some("onmouseover") => PreventDefault::MouseOver,
|
||||
Some("onmouseleave") => PreventDefault::MouseLeave,
|
||||
Some("onmouseout") => PreventDefault::MouseOut,
|
||||
Some("onwheel") => PreventDefault::Wheel,
|
||||
Some("oncontextmenu") => PreventDefault::ContextMenu,
|
||||
_ => return false,
|
||||
};
|
||||
if new == *self {
|
||||
false
|
||||
} else {
|
||||
|
||||
+18
-16
@@ -350,24 +350,26 @@ pub fn convert(mode: RenderingMode, c: Color) -> Color {
|
||||
let rgb = to_rgb(c);
|
||||
Color::Rgb(rgb[0], rgb[1], rgb[2])
|
||||
}
|
||||
crate::RenderingMode::Ansi => match c {
|
||||
Color::Indexed(_) => c,
|
||||
_ => {
|
||||
let rgb = to_rgb(c);
|
||||
// 16-231: 6 × 6 × 6 color cube
|
||||
// 232-255: 23 step grayscale
|
||||
if rgb[0] == rgb[1] && rgb[1] == rgb[2] {
|
||||
let idx = 232 + (rgb[0] as u16 * 23 / 255) as u8;
|
||||
Color::Indexed(idx)
|
||||
} else {
|
||||
let r = (rgb[0] as u16 * 5) / 255;
|
||||
let g = (rgb[1] as u16 * 5) / 255;
|
||||
let b = (rgb[2] as u16 * 5) / 255;
|
||||
let idx = 16 + r * 36 + g * 6 + b;
|
||||
Color::Indexed(idx as u8)
|
||||
crate::RenderingMode::Ansi => {
|
||||
match c {
|
||||
Color::Indexed(_) => c,
|
||||
_ => {
|
||||
let rgb = to_rgb(c);
|
||||
// 16-231: 6 × 6 × 6 color cube
|
||||
// 232-255: 23 step grayscale
|
||||
if rgb[0] == rgb[1] && rgb[1] == rgb[2] {
|
||||
let idx = 232 + (rgb[0] as u16 * 23 / 255) as u8;
|
||||
Color::Indexed(idx)
|
||||
} else {
|
||||
let r = (rgb[0] as u16 * 5) / 255;
|
||||
let g = (rgb[1] as u16 * 5) / 255;
|
||||
let b = (rgb[2] as u16 * 5) / 255;
|
||||
let idx = 16 + r * 36 + g * 6 + b;
|
||||
Color::Indexed(idx as u8)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,11 +90,12 @@ impl Button {
|
||||
}
|
||||
|
||||
fn switch(&mut self, ctx: &WidgetContext, node: NodeMut) {
|
||||
let data = FormData {
|
||||
value: self.value.to_string(),
|
||||
values: HashMap::new(),
|
||||
files: None,
|
||||
};
|
||||
let data =
|
||||
FormData {
|
||||
value: self.value.to_string(),
|
||||
values: HashMap::new(),
|
||||
files: None,
|
||||
};
|
||||
ctx.send(crate::Event {
|
||||
id: node.id(),
|
||||
name: "input",
|
||||
|
||||
@@ -236,10 +236,11 @@ impl Slider {
|
||||
let id = root.id();
|
||||
let rdom = root.real_dom_mut();
|
||||
let world = rdom.raw_world_mut();
|
||||
let taffy = {
|
||||
let query: UniqueView<Query> = world.borrow().unwrap();
|
||||
query.stretch.clone()
|
||||
};
|
||||
let taffy =
|
||||
{
|
||||
let query: UniqueView<Query> = world.borrow().unwrap();
|
||||
query.stretch.clone()
|
||||
};
|
||||
|
||||
let taffy = taffy.lock().unwrap();
|
||||
|
||||
@@ -267,10 +268,11 @@ impl CustomElement for Slider {
|
||||
panic!("input must be an element")
|
||||
};
|
||||
|
||||
let value = el.attributes.get(&OwnedAttributeDiscription {
|
||||
name: "value".to_string(),
|
||||
namespace: None,
|
||||
});
|
||||
let value =
|
||||
el.attributes.get(&OwnedAttributeDiscription {
|
||||
name: "value".to_string(),
|
||||
namespace: None,
|
||||
});
|
||||
let value = value
|
||||
.and_then(|value| match value {
|
||||
OwnedAttributeValue::Text(text) => text.as_str().parse().ok(),
|
||||
@@ -301,11 +303,12 @@ impl CustomElement for Slider {
|
||||
|
||||
let cursor_text = rdom.create_node("|".to_string());
|
||||
let cursor_text_id = cursor_text.id();
|
||||
let mut cursor_span = rdom.create_node(NodeType::Element(ElementNode {
|
||||
tag: "div".to_string(),
|
||||
attributes: [].into_iter().collect(),
|
||||
..Default::default()
|
||||
}));
|
||||
let mut cursor_span =
|
||||
rdom.create_node(NodeType::Element(ElementNode {
|
||||
tag: "div".to_string(),
|
||||
attributes: [].into_iter().collect(),
|
||||
..Default::default()
|
||||
}));
|
||||
cursor_span.add_child(cursor_text_id);
|
||||
let cursor_span_id = cursor_span.id();
|
||||
|
||||
|
||||
Reference in new issue
Block a user