FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    ferro_markup_type

    macro · ferroui-base · v0.5.0

    macro_rules! ferro_markup_type
    

    Declares the markup metadata of a type that is not a class of the object model: a value type, a plain shared (reference) type, a contract, or a type of another crate. (Classes state theirs in the markup part of ferro_class_info!; enumerations use ferro_markup_enum!.)

    ferro_markup_type!(struct Thickness {
        handles: [Thickness],
        parse: Thickness::parse,
        constructors: [
            (f64) => Thickness::uniform,
            (f64, f64, f64, f64) => Thickness::new,
        ],
        properties: [
            Left: f64 { get: |t: &Thickness| t.left },
        ],
    });
    
    ferro_markup_type!(class Setter {
        handles: [Setter, Rc<Setter>, Option<Rc<Setter>>],
        this: Rc<Setter>,
        interfaces: [Rc<dyn ISetter>],
        constructors: [() => Setter::empty],
        content: Value,
        properties: [
            Property: Option<&'static FerroProperty> { get: Setter::property, set: Setter::set_property },
            Value: Option<BoxedValue> { get: Setter::value, set: Setter::set_value }
                [AssignBinding, DependsOn("Property")],
        ],
    });
    
    ferro_markup_type!(interface dyn IBrush as "IBrush" {
        handles: [Rc<dyn IBrush>, Option<Rc<dyn IBrush>>],
    });
    

    The head is class, struct, interface or static, the Rust type and, when the markup name is not the identifier of the type, as "Name". It implements MarkupTyped for the type. The body is a list of the parts below, each optional, in any order:

    • namespace: "System" — the dotted namespace, when it differs from the one registered for the declaring module.
    • handles: [T, ..] — the Rust types that hold values of the type, the untyped form first (see MarkupType::handles). For a struct (and an enumeration) the nullable form Option<T> is recorded automatically as MarkupType::nullable.
    • this: T — the type instance members receive (&T); by default the declared type itself. May be written anywhere in the list. A callable written Type::method works for any handle that dereferences to Type.
    • base: T and interfaces: [T, ..] — the base type and the contracts, by handle.
    • generic: "FerroList1" [T]` — the generic definition this type instantiates and its arguments.
    • content: Name — the content property.
    • parse: path — a function fn(&str) -> Result<T, E>: the Parse(string) of the type.
    • constructors: [(A, B) => callable, ..] — the positional form; a constructor whose parameters carry names or attributes in the managed original names them all: (property: &'static FerroProperty [InheritDataTypeFrom(2)], mode: BindingMode) => callable (MarkupConstructor::parameter_info).
    • properties: [Name: T { get: callable, set: callable } [Attribute(..), ..], ..] — get is called with (&this), set with (&this, value: T); either may be omitted, the attribute list too.
    • indexers: [(i32) -> T { get: callable, set: callable }, (String) -> T { get: callable }] — the indexers (this[..]): get is called with (&this, index..), set with (&this, index.., value: T); either may be omitted, an attribute list may follow. Binding paths use them for Path[0] and Path[key].
    • property_attributes: [Name: [Attribute(..), ..], ..] — attributes of REGISTERED properties (which are otherwise not declared at all).
    • notify_property_changed: T — the type raises property change notifications: T is the Rust type of its untyped form (the first handle) and implements INotifyPropertyChanged. Bindings resolved through metadata subscribe through it, for a value held as T (the box is the shared object) or as Rc<T>.
    • type_info: X — for a static type declared with ferro_static_type!: links the metadata to its runtime type (found with MarkupType::find_by_type_info).
    • methods: [fn Name(A, B) -> R => callable, static fn Name(A) => callable, ..] — an instance method is called with (&this, a, b). An attribute list may follow the callable (fn CanSave(Option<BoxedValue>) -> bool => Vm::can_save [DependsOn("Name")]); the callable is then a plain path (Type::method), or any expression in parentheses (=> (|this: &Rc<Vm>, p| this.can_save(p)) [DependsOn("Name")]). A callable that is a path is never an index expression.
    • fields: [Name: T => callable, ..] — static FIELDS and constants (static readonly / const of the managed original), read with ().
    • static_properties: [Name: T { get: callable, set: callable } [Attribute(..)], ..] — static PROPERTIES (static T Name { get; set; }): get is called with (), set with (value: T); try_get: / try_set: as for instance properties.
    • events: [Name(A, B) => callable, ..] — the callable subscribes a handler: it is called with (&this, MarkupDelegate). The listed types are the parameters of the handler as the managed original declares them and the delegate is invoked with exactly that many untyped values: Name(Option<BoxedValue>, EventArgs) for an EventHandler<EventArgs> (the adapter passes the instance as sender when the Rust event has none), Name() for an event without arguments. The callable returns the subscription (Rc<dyn IDisposable>, the form the events of the port return) or () when the handler cannot be removed; see IntoMarkupSubscription and MarkupEvent::subscribe.
    • attributes: [Name, Name("text", 1, true, type(T), Key = value), ..] — type attributes; arguments are literals (text, integers, floating point numbers, booleans, characters), null, type(T) or an array of those (Name(["a", "b"]), Separators = [",", " "]; arrays nest).

    Fallible members. A member whose callable returns Result<T, E> (E: Display) is declared with try: try fn Name(A) -> T => callable, static try fn .., try (A) => callable for a constructor, try_get: / try_set: for property and indexer accessors and try Name(A) => callable for an event subscription. Err becomes MarkupInvokeError::Failed (the exception of the managed original); the declared types are the Ok types.

    Callables are paths or closures; parameter and property types are the exact Rust types the callable takes and returns.

    View source

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.