Merge 5695ec9b94 into d4630616b1
This commit is contained in:
commit
db5effcfd6
23 changed files with 170 additions and 171 deletions
|
|
@ -28,7 +28,7 @@ impl AppDelegate for DefaultAppDelegate {}
|
|||
/// also stored here for easy access.
|
||||
pub struct App {
|
||||
pub(crate) bridge: Mutex<Option<PlatformAppBridge>>,
|
||||
pub delegate: Mutex<Box<AppDelegate>>,
|
||||
pub delegate: Mutex<Box<dyn AppDelegate>>,
|
||||
pub windows: WindowManager
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub struct FragmentProps;
|
|||
/// Fragments are special - you can do something like the following in cases where you
|
||||
/// want to render some views without requiring an intermediate view.
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// <Fragment>
|
||||
/// <View />
|
||||
/// <View />
|
||||
|
|
@ -29,7 +29,7 @@ impl Fragment {
|
|||
}
|
||||
|
||||
impl Props for Fragment {
|
||||
fn set_props(&mut self, _: &mut std::any::Any) {}
|
||||
fn set_props(&mut self, _: &mut dyn std::any::Any) {}
|
||||
}
|
||||
|
||||
impl Component for Fragment {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub struct TextProps;
|
|||
///
|
||||
/// Views accept styles and event callbacks as props. For example:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// <Text styles=["styleKey1", "styleKey2"] />
|
||||
/// ```
|
||||
pub struct Text(Mutex<PlatformTextBridge>);
|
||||
|
|
@ -38,7 +38,7 @@ impl Text {
|
|||
}
|
||||
|
||||
impl Props for Text {
|
||||
fn set_props(&mut self, _: &mut std::any::Any) {}
|
||||
fn set_props(&mut self, _: &mut dyn std::any::Any) {}
|
||||
}
|
||||
|
||||
impl Component for Text {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ pub struct ViewProps;
|
|||
///
|
||||
/// Views accept styles and event callbacks as props. For example:
|
||||
///
|
||||
/// ```
|
||||
/// ```ignore
|
||||
/// <View styles=["styleKey1", "styleKey2"] />
|
||||
/// ```
|
||||
pub struct View {
|
||||
|
|
@ -46,7 +46,7 @@ impl View {
|
|||
}
|
||||
|
||||
impl Props for View {
|
||||
fn set_props(&mut self, _: &mut std::any::Any) {}
|
||||
fn set_props(&mut self, _: &mut dyn std::any::Any) {}
|
||||
}
|
||||
|
||||
impl Component for View {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ impl WindowManager {
|
|||
/// Adds an `AppWindow` to this instance.
|
||||
pub(crate) fn add(&self, window: Arc<Mutex<AppWindow>>) {
|
||||
let mut windows = self.0.lock().unwrap();
|
||||
if let None = windows.iter().position(|w| Arc::ptr_eq(&w, &window)) {
|
||||
if windows.iter().position(|w| Arc::ptr_eq(&w, &window)).is_none() {
|
||||
windows.push(window);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ pub struct AppWindow {
|
|||
pub title: String,
|
||||
pub dimensions: (f64, f64, f64, f64),
|
||||
pub bridge: PlatformWindowBridge,
|
||||
pub delegate: Box<WindowDelegate>,
|
||||
pub delegate: Box<dyn WindowDelegate>,
|
||||
pub render_key: ComponentKey
|
||||
}
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ impl Window {
|
|||
style_keys: "".into(),
|
||||
title: "".into(),
|
||||
dimensions: (0., 0., 0., 0.),
|
||||
bridge: bridge,
|
||||
bridge,
|
||||
delegate: Box::new(delegate),
|
||||
render_key: key
|
||||
})))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
cyclomatic-complexity-threshold = 30
|
||||
cognitive-complexity-threshold = 30
|
||||
doc-valid-idents = [
|
||||
"MiB", "GiB", "TiB", "PiB", "EiB",
|
||||
"DirectX", "OpenGL", "TrueType",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! A wrapper for `NSApplication` on macOS. If you opt in to the `cocoa` feature on
|
||||
//! Alchemy, this will loop system-level application events back to your `AppDelegate`.
|
||||
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::{Once};
|
||||
|
||||
use cocoa::base::{id, nil};
|
||||
use cocoa::appkit::{NSApplication, NSRunningApplication};
|
||||
|
|
@ -127,7 +127,7 @@ extern fn will_terminate<T: AppDelegate>(this: &Object, _: Sel, _: id) {
|
|||
/// pointers we need to have.
|
||||
fn register_app_delegate_class<T: AppDelegate>() -> *const Class {
|
||||
static mut DELEGATE_CLASS: *const Class = 0 as *const Class;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
INIT.call_once(|| unsafe {
|
||||
let superclass = Class::get("NSObject").unwrap();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! This wraps NTextField on macOS, and configures it to act like a label
|
||||
//! with standard behavior that most users would expect.
|
||||
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::{Once};
|
||||
|
||||
use objc_id::{Id, ShareId};
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
|
|
@ -112,7 +112,7 @@ extern fn enforce_normalcy(_: &Object, _: Sel) -> BOOL {
|
|||
/// to store.
|
||||
fn register_class() -> *const Class {
|
||||
static mut VIEW_CLASS: *const Class = 0 as *const Class;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
INIT.call_once(|| unsafe {
|
||||
let superclass = Class::get("NSTextField").unwrap();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! Implements a View Component struct. The most common
|
||||
//! basic building block of any app. Wraps NSView on macOS.
|
||||
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::{Once};
|
||||
|
||||
use objc_id::{Id, ShareId};
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
|
|
@ -107,7 +107,7 @@ extern fn update_layer(this: &Object, _: Sel) {
|
|||
/// to store.
|
||||
fn register_class() -> *const Class {
|
||||
static mut VIEW_CLASS: *const Class = 0 as *const Class;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
INIT.call_once(|| unsafe {
|
||||
let superclass = Class::get("NSView").unwrap();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
//! Cocoa and associated widgets. This also handles looping back
|
||||
//! lifecycle events, such as window resizing or close events.
|
||||
|
||||
use std::sync::{Once, ONCE_INIT};
|
||||
use std::sync::{Once};
|
||||
|
||||
use cocoa::base::{id, nil, YES, NO};
|
||||
use cocoa::appkit::{NSWindow, NSWindowStyleMask, NSBackingStoreType};
|
||||
|
|
@ -149,7 +149,7 @@ extern fn will_close<T: AppDelegate>(this: &Object, _: Sel, _: id) {
|
|||
/// need to do.
|
||||
fn register_window_class<T: AppDelegate>() -> *const Class {
|
||||
static mut DELEGATE_CLASS: *const Class = 0 as *const Class;
|
||||
static INIT: Once = ONCE_INIT;
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
INIT.call_once(|| unsafe {
|
||||
let superclass = Class::get("NSObject").unwrap();
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
/// A generic Error type that we use. It currently just aliases to `Box<std::error::Error>`,
|
||||
/// but could change in the future.
|
||||
pub type Error = Box<std::error::Error>;
|
||||
pub type Error = Box<dyn std::error::Error>;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl GenericRootView {
|
|||
}
|
||||
|
||||
impl Props for GenericRootView {
|
||||
fn set_props(&mut self, _: &mut Any) {}
|
||||
fn set_props(&mut self, _: &mut dyn Any) {}
|
||||
}
|
||||
|
||||
impl Component for GenericRootView {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ impl RenderEngine {
|
|||
/// they get a key back. When they want to instruct the global `RenderEngine`
|
||||
/// to re-render or update their tree, they pass that key and whatever the new tree
|
||||
/// should be.
|
||||
pub fn register_root_component<C: Component + 'static>(&self, component: C) -> Result<ComponentKey, Box<Error>> {
|
||||
pub fn register_root_component<C: Component + 'static>(&self, component: C) -> Result<ComponentKey, Box<dyn Error>> {
|
||||
// Conceivably, this doesn't NEED to be a thing... but for now it is. If you've stumbled
|
||||
// upon here, wayward traveler, in need of a non-native-root-component, please open an
|
||||
// issue to discuss. :)
|
||||
|
|
@ -85,7 +85,7 @@ impl RenderEngine {
|
|||
key: ComponentKey,
|
||||
dimensions: (f64, f64),
|
||||
child: RSX
|
||||
) -> Result<(), Box<Error>> {
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let mut component_store = self.components.lock().unwrap();
|
||||
let mut layout_store = self.layouts.lock().unwrap();
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ fn recursively_diff_tree(
|
|||
new_tree: RSX,
|
||||
component_store: &mut ComponentStore,
|
||||
layout_store: &mut LayoutStore
|
||||
) -> Result<(), Box<Error>> {
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
// First we need to determine if this node is being replaced or updated. A replace happens if
|
||||
// two nodes are different types - in this case, we check their tag values. This is also a case
|
||||
// where, for instance, if the RSX tag is `::None` or `::VirtualText`, we'll treat it as
|
||||
|
|
@ -224,7 +224,7 @@ fn mount_component_tree(
|
|||
tree: VirtualNode,
|
||||
component_store: &mut ComponentStore,
|
||||
layout_store: &mut LayoutStore
|
||||
) -> Result<ComponentKey, Box<Error>> {
|
||||
) -> Result<ComponentKey, Box<dyn Error>> {
|
||||
let key = component_store.new_key();
|
||||
let component = (tree.create_component_fn)(key);
|
||||
let is_native_backed = component.has_native_backing_node();
|
||||
|
|
@ -298,7 +298,7 @@ fn unmount_component_tree(
|
|||
key: ComponentKey,
|
||||
component_store: &mut ComponentStore,
|
||||
layout_store: &mut LayoutStore
|
||||
) -> Result<Vec<LayoutNode>, Box<Error>> {
|
||||
) -> Result<Vec<LayoutNode>, Box<dyn Error>> {
|
||||
let mut instance = component_store.remove(key)?;
|
||||
instance.component.component_will_unmount();
|
||||
|
||||
|
|
@ -337,7 +337,7 @@ fn link_layout_nodess(
|
|||
child: ComponentKey,
|
||||
components: &mut ComponentStore,
|
||||
layouts: &mut LayoutStore
|
||||
) -> Result<(), Box<Error>> {
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
if let (Ok(parent_instance), Ok(child_instance)) = (components.get(parent), components.get(child)) {
|
||||
if let (Some(parent_layout), Some(child_layout)) = (parent_instance.layout, child_instance.layout) {
|
||||
layouts.add_child(parent_layout, child_layout)?;
|
||||
|
|
@ -364,7 +364,7 @@ fn walk_and_apply_styles(
|
|||
key: ComponentKey,
|
||||
components: &mut ComponentStore,
|
||||
layouts: &mut LayoutStore
|
||||
) -> Result<(), Box<Error>> {
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let instance = components.get_mut(key)?;
|
||||
|
||||
if let Some(layout_key) = instance.layout {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ impl RSX {
|
|||
pub fn node<P: Any + 'static>(
|
||||
tag: &'static str,
|
||||
styles: StylesList,
|
||||
create_fn: fn(key: ComponentKey) -> Box<Component>,
|
||||
create_fn: fn(key: ComponentKey) -> Box<dyn Component>,
|
||||
props: P,
|
||||
children: Vec<RSX>
|
||||
) -> RSX {
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ pub struct VirtualNode {
|
|||
|
||||
/// `Component` instances are created on-demand, if the reconciler deems it be so. This
|
||||
/// is a closure that should return an instance of the correct type.
|
||||
pub create_component_fn: fn(key: ComponentKey) -> Box<Component>,
|
||||
pub create_component_fn: fn(key: ComponentKey) -> Box<dyn Component>,
|
||||
|
||||
/// When some RSX is returned, we scoop up the props inside a special block, and then shove
|
||||
/// them in here as an `Any` object. When you `derive(Props)` on a `Component` struct, it
|
||||
/// creates a setter that specifically handles downcasting and persisting props for you.
|
||||
pub props: Box<Any>,
|
||||
pub props: Box<dyn Any>,
|
||||
|
||||
/// Child components for this node.
|
||||
pub children: Vec<RSX>
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ pub trait WindowDelegate: Send + Sync {
|
|||
}
|
||||
|
||||
pub trait Props {
|
||||
fn set_props(&mut self, new_props: &mut Any);
|
||||
fn set_props(&mut self, new_props: &mut dyn Any);
|
||||
}
|
||||
|
||||
/// The `Component` lifecycle, mostly inspired from React, with a few extra methods for views that
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
1.35.0
|
||||
|
|
@ -51,10 +51,10 @@ impl Color {
|
|||
#[inline]
|
||||
pub fn new(red: u8, green: u8, blue: u8, alpha: u8) -> Self {
|
||||
Color {
|
||||
red: red,
|
||||
green: green,
|
||||
blue: blue,
|
||||
alpha: alpha,
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
alpha,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -501,9 +501,9 @@ pub fn parse_color_keyword(ident: &str) -> Result<Color, ()> {
|
|||
#[inline]
|
||||
fn from_hex(c: u8) -> Result<u8, ()> {
|
||||
match c {
|
||||
b'0'...b'9' => Ok(c - b'0'),
|
||||
b'a'...b'f' => Ok(c - b'a' + 10),
|
||||
b'A'...b'F' => Ok(c - b'A' + 10),
|
||||
b'0'..=b'9' => Ok(c - b'0'),
|
||||
b'a'..=b'f' => Ok(c - b'a' + 10),
|
||||
b'A'..=b'F' => Ok(c - b'A' + 10),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
|
@ -663,5 +663,5 @@ where
|
|||
let red = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3 + 1.));
|
||||
let green = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3));
|
||||
let blue = clamp_unit_f32(hue_to_rgb(m1, m2, hue_times_3 - 1.));
|
||||
return Ok((red, green, blue, uses_commas));
|
||||
Ok((red, green, blue, uses_commas))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ struct FlexLine {
|
|||
}
|
||||
|
||||
impl Stretch {
|
||||
pub(crate) fn compute(&mut self, root: Node, size: Size<Number>) -> Result<(), Box<Any>> {
|
||||
pub(crate) fn compute(&mut self, root: Node, size: Size<Number>) -> Result<(), Box<dyn Any>> {
|
||||
let style = self.style[&root];
|
||||
let has_root_min_max = style.min_size.width.is_defined()
|
||||
|| style.min_size.height.is_defined()
|
||||
|
|
@ -133,7 +133,7 @@ impl Stretch {
|
|||
node_size: Size<Number>,
|
||||
parent_size: Size<Number>,
|
||||
perform_layout: bool,
|
||||
) -> Result<ComputeResult, Box<Any>> {
|
||||
) -> Result<ComputeResult, Box<dyn Any>> {
|
||||
*self.is_dirty.get_mut(node).unwrap() = false;
|
||||
|
||||
// First we check if we have a result for the given input
|
||||
|
|
@ -277,7 +277,7 @@ impl Stretch {
|
|||
|
||||
// TODO - this does not follow spec. See commented out code below
|
||||
// 3. Determine the flex base size and hypothetical main size of each item:
|
||||
flex_items.iter_mut().try_for_each(|child| -> Result<(), Box<Any>> {
|
||||
flex_items.iter_mut().try_for_each(|child| -> Result<(), Box<dyn Any>> {
|
||||
let child_style = self.style[&child.node];
|
||||
|
||||
// A. If the item has a definite used flex basis, that’s the flex base size.
|
||||
|
|
@ -364,7 +364,7 @@ impl Stretch {
|
|||
// The hypothetical main size is the item’s flex base size clamped according to its
|
||||
// used min and max main sizes (and flooring the content box size at zero).
|
||||
|
||||
flex_items.iter_mut().try_for_each(|child| -> Result<(), Box<Any>> {
|
||||
flex_items.iter_mut().try_for_each(|child| -> Result<(), Box<dyn Any>> {
|
||||
child.inner_flex_basis = child.flex_basis - child.padding.main(dir) - child.border.main(dir);
|
||||
|
||||
// TODO - not really spec abiding but needs to be done somewhere. probably somewhere else though.
|
||||
|
|
@ -441,7 +441,7 @@ impl Stretch {
|
|||
//
|
||||
// 9.7. Resolving Flexible Lengths
|
||||
|
||||
flex_lines.iter_mut().try_for_each(|line| -> Result<(), Box<Any>> {
|
||||
flex_lines.iter_mut().try_for_each(|line| -> Result<(), Box<dyn Any>> {
|
||||
// 1. Determine the used flex factor. Sum the outer hypothetical main sizes of all
|
||||
// items on the line. If the sum is less than the flex container’s inner main size,
|
||||
// use the flex grow factor for the rest of this algorithm; otherwise, use the
|
||||
|
|
@ -458,7 +458,7 @@ impl Stretch {
|
|||
// - If using the flex shrink factor: any item that has a flex base size
|
||||
// smaller than its hypothetical main size
|
||||
|
||||
line.items.iter_mut().try_for_each(|child| -> Result<(), Box<Any>> {
|
||||
line.items.iter_mut().try_for_each(|child| -> Result<(), Box<dyn Any>> {
|
||||
// TODO - This is not found by reading the spec. Maybe this can be done in some other place
|
||||
// instead. This was found by trail and error fixing tests to align with webkit output.
|
||||
if node_inner_size.main(dir).is_undefined() && is_row {
|
||||
|
|
@ -614,7 +614,7 @@ impl Stretch {
|
|||
// item’s target main size was made smaller by this, it’s a max violation.
|
||||
// If the item’s target main size was made larger by this, it’s a min violation.
|
||||
|
||||
let total_violation = unfrozen.iter_mut().try_fold(0.0, |acc, child| -> Result<f32, Box<Any>> {
|
||||
let total_violation = unfrozen.iter_mut().try_fold(0.0, |acc, child| -> Result<f32, Box<dyn Any>> {
|
||||
// TODO - not really spec abiding but needs to be done somewhere. probably somewhere else though.
|
||||
// The following logic was developed not from the spec but by trail and error looking into how
|
||||
// webkit handled various scenarios. Can probably be solved better by passing in
|
||||
|
|
@ -691,7 +691,7 @@ impl Stretch {
|
|||
// used main size and the available space, treating auto as fit-content.
|
||||
|
||||
flex_lines.iter_mut().try_for_each(|line| {
|
||||
line.items.iter_mut().try_for_each(|child| -> Result<(), Box<Any>> {
|
||||
line.items.iter_mut().try_for_each(|child| -> Result<(), Box<dyn Any>> {
|
||||
let child_cross =
|
||||
child.size.cross(dir).maybe_max(child.min_size.cross(dir)).maybe_min(child.max_size.cross(dir));
|
||||
|
||||
|
|
@ -737,7 +737,7 @@ impl Stretch {
|
|||
|
||||
if has_baseline_child {
|
||||
flex_lines.iter_mut().try_for_each(|line| {
|
||||
line.items.iter_mut().try_for_each(|child| -> Result<(), Box<Any>> {
|
||||
line.items.iter_mut().try_for_each(|child| -> Result<(), Box<dyn Any>> {
|
||||
let result = self.compute_internal(
|
||||
child.node,
|
||||
Size {
|
||||
|
|
@ -1148,12 +1148,12 @@ impl Stretch {
|
|||
let mut lines: Vec<Vec<result::Layout>> = vec![];
|
||||
let mut total_offset_cross = padding_border.cross_start(dir);
|
||||
|
||||
let layout_line = |line: &mut FlexLine| -> Result<(), Box<Any>> {
|
||||
let layout_line = |line: &mut FlexLine| -> Result<(), Box<dyn Any>> {
|
||||
let mut children: Vec<result::Layout> = vec![];
|
||||
let mut total_offset_main = padding_border.main_start(dir);
|
||||
let line_offset_cross = line.offset_cross;
|
||||
|
||||
let layout_item = |child: &mut FlexItem| -> Result<(), Box<Any>> {
|
||||
let layout_item = |child: &mut FlexItem| -> Result<(), Box<dyn Any>> {
|
||||
let result = self.compute_internal(
|
||||
child.node,
|
||||
child.target_size.map(|s| s.to_number()),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use core::any::Any;
|
|||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
InvalidNode(node::Node),
|
||||
Measure(Box<Any>),
|
||||
Measure(Box<dyn Any>),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use crate::stretch::result::{Cache, Layout};
|
|||
use crate::stretch::style::*;
|
||||
use crate::stretch::Error;
|
||||
|
||||
type MeasureFunc = Box<Fn(Size<Number>) -> Result<Size<f32>, Box<Any>> + Send + Sync + 'static>;
|
||||
type MeasureFunc = Box<dyn Fn(Size<Number>) -> Result<Size<f32>, Box<dyn Any>> + Send + Sync + 'static>;
|
||||
|
||||
lazy_static! {
|
||||
/// Global stretch instance id allocator.
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ impl<'i> QualifiedRuleParser<'i> for RuleParser {
|
|||
let styles = DeclarationListParser::new(input, StyleParser {}).collect::<Vec<_>>();
|
||||
|
||||
Ok(Rule {
|
||||
key: key,
|
||||
key,
|
||||
styles: styles.into_iter().filter_map(|decl| {
|
||||
if !decl.is_ok() {
|
||||
eprintln!("{:?}", decl);
|
||||
|
|
|
|||
Reference in a new issue