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 (seeMarkupType::handles). For astruct(and an enumeration) the nullable formOption<T>is recorded automatically asMarkupType::nullable.this: T— the type instance members receive (&T); by default the declared type itself. May be written anywhere in the list. A callable writtenType::methodworks for any handle that dereferences toType.base: Tandinterfaces: [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 functionfn(&str) -> Result<T, E>: theParse(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(..), ..], ..]—getis called with(&this),setwith(&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[..]):getis called with(&this, index..),setwith(&this, index.., value: T); either may be omitted, an attribute list may follow. Binding paths use them forPath[0]andPath[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:Tis the Rust type of its untyped form (the first handle) and implementsINotifyPropertyChanged. Bindings resolved through metadata subscribe through it, for a value held asT(the box is the shared object) or asRc<T>.type_info: X— for astatictype declared withferro_static_type!: links the metadata to its runtime type (found withMarkupType::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/constof the managed original), read with().static_properties: [Name: T { get: callable, set: callable } [Attribute(..)], ..]— static PROPERTIES (static T Name { get; set; }):getis called with(),setwith(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 anEventHandler<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; seeIntoMarkupSubscriptionandMarkupEvent::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.
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.