mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 22:54:36 +00:00
Move ItemVTable and frieds to corelib::items
To avoid ambiguities regarding the use of FieldOffset, the BuiltinItem proc-macro uses fully-qualified type names now.
This commit is contained in:
parent
aafb96cb93
commit
62a8b15f09
11 changed files with 104 additions and 107 deletions
|
@ -2,11 +2,9 @@
|
|||
|
||||
use vtable::*;
|
||||
|
||||
use crate::graphics::{HighLevelRenderingPrimitive, Rect, RenderingVariable};
|
||||
use crate::input::{InputEventResult, MouseEvent};
|
||||
use crate::item_rendering::CachedRenderingData;
|
||||
use crate::item_tree::{ItemVisitorVTable, TraversalOrder, VisitChildrenResult};
|
||||
use crate::{layout::LayoutInfo, SharedArray};
|
||||
use crate::layout::LayoutInfo;
|
||||
|
||||
/// A Component is representing an unit that is allocated together
|
||||
#[vtable]
|
||||
|
@ -36,84 +34,3 @@ pub struct ComponentVTable {
|
|||
/// Alias for `vtable::VRef<ComponentVTable>` which represent a pointer to a `dyn Component` with
|
||||
/// the associated vtable
|
||||
pub type ComponentRef<'a> = vtable::VRef<'a, ComponentVTable>;
|
||||
|
||||
/// Items are the nodes in the render tree.
|
||||
#[vtable]
|
||||
#[repr(C)]
|
||||
pub struct ItemVTable {
|
||||
/// Returns the geometry of this item (relative to its parent item)
|
||||
pub geometry: extern "C" fn(core::pin::Pin<VRef<ItemVTable>>) -> Rect,
|
||||
|
||||
/// offset in bytes fromthe *const ItemImpl.
|
||||
/// isize::MAX means None
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[field_offset(CachedRenderingData)]
|
||||
pub cached_rendering_data_offset: usize,
|
||||
|
||||
/// Return the rendering primitive used to display this item. This should depend on only
|
||||
/// rarely changed properties as it typically contains data uploaded to the GPU.
|
||||
pub rendering_primitive:
|
||||
extern "C" fn(core::pin::Pin<VRef<ItemVTable>>) -> HighLevelRenderingPrimitive,
|
||||
|
||||
/// Return the variables needed to render the graphical primitives of this item. These
|
||||
/// are typically variables that do not require uploading any data sets to the GPU and
|
||||
/// can instead be represented using uniforms.
|
||||
pub rendering_variables:
|
||||
extern "C" fn(core::pin::Pin<VRef<ItemVTable>>) -> SharedArray<RenderingVariable>,
|
||||
|
||||
/// We would need max/min/preferred size, and all layout info
|
||||
pub layouting_info: extern "C" fn(core::pin::Pin<VRef<ItemVTable>>) -> LayoutInfo,
|
||||
|
||||
/// input event
|
||||
pub input_event:
|
||||
extern "C" fn(core::pin::Pin<VRef<ItemVTable>>, MouseEvent) -> InputEventResult,
|
||||
}
|
||||
|
||||
/// Alias for `vtable::VRef<ItemVTable>` which represent a pointer to a `dyn Item` with
|
||||
/// the associated vtable
|
||||
pub type ItemRef<'a> = vtable::VRef<'a, ItemVTable>;
|
||||
|
||||
// This is here because for some reason (rust bug?) the ItemVTable_static is not accessible in the other modules
|
||||
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Image`
|
||||
#[no_mangle]
|
||||
pub static ImageVTable for crate::items::Image
|
||||
}
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Rectangle`
|
||||
#[no_mangle]
|
||||
pub static RectangleVTable for crate::items::Rectangle
|
||||
}
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `BorderRectangle`
|
||||
#[no_mangle]
|
||||
pub static BorderRectangleVTable for crate::items::BorderRectangle
|
||||
}
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Text`
|
||||
#[no_mangle]
|
||||
pub static TextVTable for crate::items::Text
|
||||
}
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `TouchArea`
|
||||
#[no_mangle]
|
||||
pub static TouchAreaVTable for crate::items::TouchArea
|
||||
}
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Path`
|
||||
#[no_mangle]
|
||||
pub static PathVTable for crate::items::Path
|
||||
}
|
||||
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Flickable`
|
||||
#[no_mangle]
|
||||
pub static FlickableVTable for crate::items::Flickable
|
||||
}
|
||||
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Window`
|
||||
#[no_mangle]
|
||||
pub static WindowVTable for crate::items::Window
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::abi::datastructures::{ComponentVTable, ItemRef};
|
||||
use crate::abi::datastructures::ComponentVTable;
|
||||
use crate::items::ItemRef;
|
||||
use std::cell::RefCell;
|
||||
use std::{
|
||||
pin::Pin,
|
||||
|
@ -269,7 +270,7 @@ pub mod ffi {
|
|||
#![allow(unsafe_code)]
|
||||
|
||||
use super::*;
|
||||
use crate::abi::datastructures::ItemVTable;
|
||||
use crate::items::ItemVTable;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
type c_void = ();
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
extern crate alloc;
|
||||
use crate::input::{MouseEvent, MouseEventType};
|
||||
use crate::items::ItemRef;
|
||||
use crate::properties::{InterpolatedPropertyValue, Property};
|
||||
#[cfg(feature = "rtti")]
|
||||
use crate::rtti::{BuiltinItem, FieldInfo, FieldOffset, PropertyInfo, ValueType};
|
||||
use crate::{abi::datastructures::ItemRef, SharedArray};
|
||||
use crate::rtti::{BuiltinItem, FieldInfo, PropertyInfo, ValueType};
|
||||
use crate::SharedArray;
|
||||
|
||||
use cgmath::Matrix4;
|
||||
use const_field_offset::FieldOffsets;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::abi::datastructures::ItemRef;
|
||||
use super::graphics::{Frame, GraphicsBackend, RenderingCache, RenderingPrimitivesBuilder};
|
||||
use super::items::ItemRef;
|
||||
use crate::item_tree::ItemVisitorResult;
|
||||
use cgmath::{Matrix4, SquareMatrix, Vector3};
|
||||
use std::cell::Cell;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::abi::datastructures::{ComponentVTable, ItemRef, ItemVTable};
|
||||
use crate::abi::datastructures::ComponentVTable;
|
||||
use crate::items::{ItemRef, ItemVTable};
|
||||
use crate::ComponentRefPin;
|
||||
use core::pin::Pin;
|
||||
use vtable::*;
|
||||
|
|
|
@ -16,7 +16,6 @@ When adding an item or a property, it needs to be kept in sync with different pl
|
|||
#![allow(non_upper_case_globals)]
|
||||
#![allow(missing_docs)] // because documenting each property of items is redundent
|
||||
|
||||
use super::abi::datastructures::{Item, ItemConsts};
|
||||
use super::graphics::{Color, HighLevelRenderingPrimitive, PathData, Rect, Resource};
|
||||
use super::input::{InputEventResult, MouseEvent, MouseEventType};
|
||||
use super::item_rendering::CachedRenderingData;
|
||||
|
@ -27,6 +26,43 @@ use crate::{Property, SharedString, Signal};
|
|||
use const_field_offset::FieldOffsets;
|
||||
use core::pin::Pin;
|
||||
use sixtyfps_corelib_macros::*;
|
||||
use vtable::*;
|
||||
|
||||
/// Items are the nodes in the render tree.
|
||||
#[vtable]
|
||||
#[repr(C)]
|
||||
pub struct ItemVTable {
|
||||
/// Returns the geometry of this item (relative to its parent item)
|
||||
pub geometry: extern "C" fn(core::pin::Pin<VRef<ItemVTable>>) -> Rect,
|
||||
|
||||
/// offset in bytes fromthe *const ItemImpl.
|
||||
/// isize::MAX means None
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[field_offset(CachedRenderingData)]
|
||||
pub cached_rendering_data_offset: usize,
|
||||
|
||||
/// Return the rendering primitive used to display this item. This should depend on only
|
||||
/// rarely changed properties as it typically contains data uploaded to the GPU.
|
||||
pub rendering_primitive:
|
||||
extern "C" fn(core::pin::Pin<VRef<ItemVTable>>) -> HighLevelRenderingPrimitive,
|
||||
|
||||
/// Return the variables needed to render the graphical primitives of this item. These
|
||||
/// are typically variables that do not require uploading any data sets to the GPU and
|
||||
/// can instead be represented using uniforms.
|
||||
pub rendering_variables:
|
||||
extern "C" fn(core::pin::Pin<VRef<ItemVTable>>) -> SharedArray<RenderingVariable>,
|
||||
|
||||
/// We would need max/min/preferred size, and all layout info
|
||||
pub layouting_info: extern "C" fn(core::pin::Pin<VRef<ItemVTable>>) -> LayoutInfo,
|
||||
|
||||
/// input event
|
||||
pub input_event:
|
||||
extern "C" fn(core::pin::Pin<VRef<ItemVTable>>, MouseEvent) -> InputEventResult,
|
||||
}
|
||||
|
||||
/// Alias for `vtable::VRef<ItemVTable>` which represent a pointer to a `dyn Item` with
|
||||
/// the associated vtable
|
||||
pub type ItemRef<'a> = vtable::VRef<'a, ItemVTable>;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(FieldOffsets, Default, BuiltinItem)]
|
||||
|
@ -82,7 +118,11 @@ impl ItemConsts for Rectangle {
|
|||
> = Rectangle::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||
}
|
||||
|
||||
pub use crate::abi::datastructures::RectangleVTable;
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Rectangle`
|
||||
#[no_mangle]
|
||||
pub static RectangleVTable for Rectangle
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(FieldOffsets, Default, BuiltinItem)]
|
||||
|
@ -147,7 +187,11 @@ impl ItemConsts for BorderRectangle {
|
|||
> = BorderRectangle::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||
}
|
||||
|
||||
pub use crate::abi::datastructures::BorderRectangleVTable;
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `BorderRectangle`
|
||||
#[no_mangle]
|
||||
pub static BorderRectangleVTable for BorderRectangle
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(FieldOffsets, Default, BuiltinItem)]
|
||||
|
@ -210,7 +254,11 @@ impl ItemConsts for Image {
|
|||
> = Image::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||
}
|
||||
|
||||
pub use crate::abi::datastructures::ImageVTable;
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Image`
|
||||
#[no_mangle]
|
||||
pub static ImageVTable for Image
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, strum_macros::EnumString, strum_macros::Display)]
|
||||
#[repr(C)]
|
||||
|
@ -328,7 +376,11 @@ impl ItemConsts for Text {
|
|||
Text::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||
}
|
||||
|
||||
pub use crate::abi::datastructures::TextVTable;
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Text`
|
||||
#[no_mangle]
|
||||
pub static TextVTable for Text
|
||||
}
|
||||
|
||||
/// The implementation of the `TouchArea` element
|
||||
#[repr(C)]
|
||||
|
@ -411,7 +463,12 @@ impl ItemConsts for TouchArea {
|
|||
CachedRenderingData,
|
||||
> = TouchArea::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||
}
|
||||
pub use crate::abi::datastructures::TouchAreaVTable;
|
||||
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `TouchArea`
|
||||
#[no_mangle]
|
||||
pub static TouchAreaVTable for TouchArea
|
||||
}
|
||||
|
||||
/// The implementation of the `Path` element
|
||||
#[repr(C)]
|
||||
|
@ -468,7 +525,11 @@ impl ItemConsts for Path {
|
|||
Path::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||
}
|
||||
|
||||
pub use crate::abi::datastructures::PathVTable;
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Path`
|
||||
#[no_mangle]
|
||||
pub static PathVTable for Path
|
||||
}
|
||||
|
||||
/// The implementation of the `Flickable` element
|
||||
#[repr(C)]
|
||||
|
@ -518,7 +579,14 @@ impl ItemConsts for Flickable {
|
|||
const cached_rendering_data_offset: const_field_offset::FieldOffset<Self, CachedRenderingData> =
|
||||
Self::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||
}
|
||||
pub use crate::{abi::datastructures::FlickableVTable, graphics::RenderingVariable, SharedArray};
|
||||
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Flickable`
|
||||
#[no_mangle]
|
||||
pub static FlickableVTable for Flickable
|
||||
}
|
||||
|
||||
pub use crate::{graphics::RenderingVariable, SharedArray};
|
||||
|
||||
#[repr(C)]
|
||||
/// Wraps the internal datastructure for the Flickable
|
||||
|
@ -607,3 +675,9 @@ impl ItemConsts for Window {
|
|||
const cached_rendering_data_offset: const_field_offset::FieldOffset<Self, CachedRenderingData> =
|
||||
Self::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||
}
|
||||
|
||||
ItemVTable_static! {
|
||||
/// The VTable for `Window`
|
||||
#[no_mangle]
|
||||
pub static WindowVTable for Window
|
||||
}
|
||||
|
|
|
@ -171,5 +171,8 @@ pub trait BuiltinItem: Sized {
|
|||
fn name() -> &'static str;
|
||||
fn properties<Value: ValueType>() -> Vec<(&'static str, &'static dyn PropertyInfo<Self, Value>)>;
|
||||
fn fields<Value: ValueType>() -> Vec<(&'static str, &'static dyn FieldInfo<Self, Value>)>;
|
||||
fn signals() -> Vec<(&'static str, FieldOffset<Self, crate::Signal<()>>)>;
|
||||
fn signals() -> Vec<(
|
||||
&'static str,
|
||||
const_field_offset::FieldOffset<Self, crate::Signal<()>, const_field_offset::PinnedFlag>,
|
||||
)>;
|
||||
}
|
||||
|
|
|
@ -71,12 +71,12 @@ pub fn builtin_item(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
fn fields<Value: ValueType>() -> Vec<(&'static str, &'static dyn FieldInfo<Self, Value>)> {
|
||||
vec![#( {
|
||||
const O : FieldOffset<#item_name, #plain_field_types> =
|
||||
const O : const_field_offset::FieldOffset<#item_name, #plain_field_types, const_field_offset::PinnedFlag> =
|
||||
#item_name::FIELD_OFFSETS.#plain_field_names;
|
||||
(stringify!(#plain_field_names), &O as &'static dyn FieldInfo<Self, Value> )
|
||||
} ),*]
|
||||
}
|
||||
fn signals() -> Vec<(&'static str, FieldOffset<Self, crate::Signal<()>>)> {
|
||||
fn signals() -> Vec<(&'static str, const_field_offset::FieldOffset<Self, crate::Signal<()>, const_field_offset::PinnedFlag>)> {
|
||||
vec![#(
|
||||
(stringify!(#signal_field_names),#item_name::FIELD_OFFSETS.#signal_field_names)
|
||||
),*]
|
||||
|
|
|
@ -7,12 +7,12 @@ use object_tree::{Element, ElementRc};
|
|||
use sixtyfps_compilerlib::layout::{GridLayout, Layout, LayoutItem, PathLayout};
|
||||
use sixtyfps_compilerlib::typeregister::Type;
|
||||
use sixtyfps_compilerlib::*;
|
||||
use sixtyfps_corelib::abi::datastructures::{ComponentVTable, ItemRef, ItemVTable};
|
||||
use sixtyfps_corelib::abi::datastructures::ComponentVTable;
|
||||
use sixtyfps_corelib::graphics::Resource;
|
||||
use sixtyfps_corelib::item_tree::{
|
||||
ItemTreeNode, ItemVisitorRefMut, TraversalOrder, VisitChildrenResult,
|
||||
};
|
||||
use sixtyfps_corelib::items::{Flickable, PropertyAnimation, Rectangle};
|
||||
use sixtyfps_corelib::items::{Flickable, ItemRef, ItemVTable, PropertyAnimation, Rectangle};
|
||||
use sixtyfps_corelib::layout::LayoutInfo;
|
||||
use sixtyfps_corelib::properties::{InterpolatedPropertyValue, PropertyListenerScope};
|
||||
use sixtyfps_corelib::rtti::{self, FieldOffset, PropertyInfo};
|
||||
|
|
|
@ -8,8 +8,8 @@ use sixtyfps_compilerlib::expression_tree::{
|
|||
use sixtyfps_compilerlib::{object_tree::ElementRc, typeregister::Type};
|
||||
use sixtyfps_corelib as corelib;
|
||||
use sixtyfps_corelib::{
|
||||
abi::datastructures::ItemRef, graphics::PathElement, items::PropertyAnimation, Color, PathData,
|
||||
Resource, SharedArray, SharedString,
|
||||
graphics::PathElement, items::ItemRef, items::PropertyAnimation, Color, PathData, Resource,
|
||||
SharedArray, SharedString,
|
||||
};
|
||||
use std::{collections::HashMap, rc::Rc};
|
||||
|
||||
|
@ -25,7 +25,7 @@ pub trait ErasedPropertyInfo {
|
|||
fn offset(&self) -> usize;
|
||||
}
|
||||
|
||||
impl<Item: vtable::HasStaticVTable<corelib::abi::datastructures::ItemVTable>> ErasedPropertyInfo
|
||||
impl<Item: vtable::HasStaticVTable<corelib::items::ItemVTable>> ErasedPropertyInfo
|
||||
for &'static dyn corelib::rtti::PropertyInfo<Item, Value>
|
||||
{
|
||||
fn get(&self, item: Pin<ItemRef>) -> Value {
|
||||
|
|
|
@ -5,10 +5,10 @@ use const_field_offset::FieldOffsets;
|
|||
use core::pin::Pin;
|
||||
#[cfg(have_qt)]
|
||||
use cpp::cpp;
|
||||
use sixtyfps_corelib::abi::datastructures::{Item, ItemConsts, ItemVTable};
|
||||
use sixtyfps_corelib::graphics::{HighLevelRenderingPrimitive, Rect, RenderingVariable, Resource};
|
||||
use sixtyfps_corelib::input::{InputEventResult, MouseEvent, MouseEventType};
|
||||
use sixtyfps_corelib::item_rendering::CachedRenderingData;
|
||||
use sixtyfps_corelib::items::{Item, ItemConsts, ItemVTable};
|
||||
use sixtyfps_corelib::layout::LayoutInfo;
|
||||
#[cfg(feature = "rtti")]
|
||||
use sixtyfps_corelib::rtti::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue