mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 21:04:47 +00:00
Add a TouchArea builtin item (currently does nothing)
This commit is contained in:
parent
f27a715b30
commit
6b3765857a
7 changed files with 119 additions and 9 deletions
|
@ -27,6 +27,11 @@ using internal::Image;
|
||||||
using internal::ImageVTable;
|
using internal::ImageVTable;
|
||||||
using internal::Rectangle;
|
using internal::Rectangle;
|
||||||
using internal::RectangleVTable;
|
using internal::RectangleVTable;
|
||||||
|
using internal::Text;
|
||||||
|
using internal::TextVTable;
|
||||||
|
using internal::TouchArea;
|
||||||
|
using internal::TouchAreaVTable;
|
||||||
|
|
||||||
|
|
||||||
// the component has static lifetime so it does not need to be destroyed
|
// the component has static lifetime so it does not need to be destroyed
|
||||||
// FIXME: we probably need some kind of way to dinstinguish static component and
|
// FIXME: we probably need some kind of way to dinstinguish static component and
|
||||||
|
|
|
@ -7,6 +7,12 @@ component TwoRectangle = Rectangle {
|
||||||
width: 25;
|
width: 25;
|
||||||
height: 25;
|
height: 25;
|
||||||
color: red;
|
color: red;
|
||||||
|
|
||||||
|
my_area = TouchArea {
|
||||||
|
width: 25;
|
||||||
|
height: 25;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ pub struct TypeRegister {
|
||||||
impl TypeRegister {
|
impl TypeRegister {
|
||||||
pub fn builtin() -> Self {
|
pub fn builtin() -> Self {
|
||||||
let mut r = TypeRegister::default();
|
let mut r = TypeRegister::default();
|
||||||
|
|
||||||
let mut rectangle = BuiltinElement::default();
|
let mut rectangle = BuiltinElement::default();
|
||||||
rectangle.properties.insert("color".to_owned(), Type::Color);
|
rectangle.properties.insert("color".to_owned(), Type::Color);
|
||||||
rectangle.properties.insert("x".to_owned(), Type::Number);
|
rectangle.properties.insert("x".to_owned(), Type::Number);
|
||||||
|
@ -57,6 +58,7 @@ impl TypeRegister {
|
||||||
rectangle.properties.insert("width".to_owned(), Type::Number);
|
rectangle.properties.insert("width".to_owned(), Type::Number);
|
||||||
rectangle.properties.insert("height".to_owned(), Type::Number);
|
rectangle.properties.insert("height".to_owned(), Type::Number);
|
||||||
r.types.insert("Rectangle".to_owned(), Type::Builtin(Rc::new(rectangle)));
|
r.types.insert("Rectangle".to_owned(), Type::Builtin(Rc::new(rectangle)));
|
||||||
|
|
||||||
let mut image = BuiltinElement::default();
|
let mut image = BuiltinElement::default();
|
||||||
image.properties.insert("source".to_owned(), Type::Image);
|
image.properties.insert("source".to_owned(), Type::Image);
|
||||||
image.properties.insert("x".to_owned(), Type::Number);
|
image.properties.insert("x".to_owned(), Type::Number);
|
||||||
|
@ -64,6 +66,7 @@ impl TypeRegister {
|
||||||
image.properties.insert("width".to_owned(), Type::Number);
|
image.properties.insert("width".to_owned(), Type::Number);
|
||||||
image.properties.insert("height".to_owned(), Type::Number);
|
image.properties.insert("height".to_owned(), Type::Number);
|
||||||
r.types.insert("Image".to_owned(), Type::Builtin(Rc::new(image)));
|
r.types.insert("Image".to_owned(), Type::Builtin(Rc::new(image)));
|
||||||
|
|
||||||
let mut text = BuiltinElement::default();
|
let mut text = BuiltinElement::default();
|
||||||
text.properties.insert("text".to_owned(), Type::String);
|
text.properties.insert("text".to_owned(), Type::String);
|
||||||
text.properties.insert("color".to_owned(), Type::Color);
|
text.properties.insert("color".to_owned(), Type::Color);
|
||||||
|
@ -71,6 +74,13 @@ impl TypeRegister {
|
||||||
text.properties.insert("y".to_owned(), Type::Number);
|
text.properties.insert("y".to_owned(), Type::Number);
|
||||||
r.types.insert("Text".to_owned(), Type::Builtin(Rc::new(text)));
|
r.types.insert("Text".to_owned(), Type::Builtin(Rc::new(text)));
|
||||||
|
|
||||||
|
let mut touch_area = BuiltinElement::default();
|
||||||
|
touch_area.properties.insert("x".to_owned(), Type::Number);
|
||||||
|
touch_area.properties.insert("y".to_owned(), Type::Number);
|
||||||
|
touch_area.properties.insert("width".to_owned(), Type::Number);
|
||||||
|
touch_area.properties.insert("height".to_owned(), Type::Number);
|
||||||
|
r.types.insert("TouchArea".to_owned(), Type::Builtin(Rc::new(touch_area)));
|
||||||
|
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -273,6 +273,8 @@ pub static QT_BUTTON_VTABLE: ItemVTable = ItemVTable {
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// This is here because for some reason (rust bug?) the ItemVTable_static is not accessible in the other modules
|
||||||
ItemVTable_static!(crate::abi::primitives::Image);
|
ItemVTable_static!(crate::abi::primitives::Image);
|
||||||
ItemVTable_static!(crate::abi::primitives::Rectangle);
|
ItemVTable_static!(crate::abi::primitives::Rectangle);
|
||||||
ItemVTable_static!(crate::abi::primitives::Text);
|
ItemVTable_static!(crate::abi::primitives::Text);
|
||||||
|
ItemVTable_static!(crate::abi::primitives::TouchArea);
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
/*!
|
||||||
|
This module contains the list of builtin items.
|
||||||
|
|
||||||
|
When adding an item or a property, it needs to be kept in sync with different place.
|
||||||
|
(This is less than ideal and maybe we can have some automation later)
|
||||||
|
|
||||||
|
- It needs to be changed in this module
|
||||||
|
- The ItemVTable_static at the end of datastructures.rs (new items only)
|
||||||
|
- In the compiler: typeregister.rs
|
||||||
|
- In the vewer: main.rs
|
||||||
|
- For the C++ code (new item only): the build.rs to export the new item, and the `using` declaration in sixtyfps.h
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
|
|
||||||
use super::datastructures::{
|
use super::datastructures::{
|
||||||
|
@ -6,7 +20,6 @@ use super::datastructures::{
|
||||||
use crate::{Property, SharedString};
|
use crate::{Property, SharedString};
|
||||||
use vtable::HasStaticVTable;
|
use vtable::HasStaticVTable;
|
||||||
|
|
||||||
/// FIXME: more properties
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(const_field_offset::FieldOffsets, Default)]
|
#[derive(const_field_offset::FieldOffsets, Default)]
|
||||||
pub struct Rectangle {
|
pub struct Rectangle {
|
||||||
|
@ -45,6 +58,9 @@ impl ItemConsts for Rectangle {
|
||||||
> = Rectangle::field_offsets().cached_rendering_data;
|
> = Rectangle::field_offsets().cached_rendering_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub static RectangleVTable: ItemVTable = Rectangle::VTABLE;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(const_field_offset::FieldOffsets, Default)]
|
#[derive(const_field_offset::FieldOffsets, Default)]
|
||||||
pub struct Image {
|
pub struct Image {
|
||||||
|
@ -77,6 +93,9 @@ impl ItemConsts for Image {
|
||||||
> = Image::field_offsets().cached_rendering_data;
|
> = Image::field_offsets().cached_rendering_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub static ImageVTable: ItemVTable = Image::VTABLE;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(const_field_offset::FieldOffsets, Default)]
|
#[derive(const_field_offset::FieldOffsets, Default)]
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
|
@ -105,11 +124,38 @@ impl ItemConsts for Text {
|
||||||
Text::field_offsets().cached_rendering_data;
|
Text::field_offsets().cached_rendering_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub static RectangleVTable: ItemVTable = Rectangle::VTABLE;
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub static ImageVTable: ItemVTable = Image::VTABLE;
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub static TextVTable: ItemVTable = Text::VTABLE;
|
pub static TextVTable: ItemVTable = Text::VTABLE;
|
||||||
|
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(const_field_offset::FieldOffsets, Default)]
|
||||||
|
pub struct TouchArea {
|
||||||
|
pub x: Property<f32>,
|
||||||
|
pub y: Property<f32>,
|
||||||
|
pub width: Property<f32>,
|
||||||
|
pub height: Property<f32>,
|
||||||
|
// FIXME: remove this
|
||||||
|
pub cached_rendering_data: CachedRenderingData,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Item for TouchArea {
|
||||||
|
fn geometry(&self) {}
|
||||||
|
fn rendering_info(&self) -> RenderingInfo {
|
||||||
|
RenderingInfo::NoContents
|
||||||
|
}
|
||||||
|
|
||||||
|
fn layouting_info(&self) -> LayoutInfo {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input_event(&self, _: super::datastructures::MouseEvent) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ItemConsts for TouchArea {
|
||||||
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<TouchArea, CachedRenderingData> =
|
||||||
|
TouchArea::field_offsets().cached_rendering_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub static TouchAreaVTable: ItemVTable = TouchArea::VTABLE;
|
||||||
|
|
|
@ -3,7 +3,7 @@ extern crate cbindgen;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let include = ["Rectangle", "Image", "ComponentVTable"]
|
let include = ["Rectangle", "Image", "TouchArea", "Text", "ComponentVTable"]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_string())
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
|
@ -93,10 +93,11 @@ fn main() -> std::io::Result<()> {
|
||||||
std::process::exit(-1);
|
std::process::exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
use corelib::abi::primitives::{Image, Rectangle};
|
use corelib::abi::primitives::{Image, Rectangle, Text, TouchArea};
|
||||||
|
|
||||||
// FIXME: thus obviously is unsafe and not great
|
// FIXME: thus obviously is unsafe and not great
|
||||||
let mut rtti = HashMap::new();
|
let mut rtti = HashMap::new();
|
||||||
|
|
||||||
let offsets = Rectangle::field_offsets();
|
let offsets = Rectangle::field_offsets();
|
||||||
rtti.insert(
|
rtti.insert(
|
||||||
"Rectangle",
|
"Rectangle",
|
||||||
|
@ -116,6 +117,7 @@ fn main() -> std::io::Result<()> {
|
||||||
size: std::mem::size_of::<Rectangle>(),
|
size: std::mem::size_of::<Rectangle>(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let offsets = Image::field_offsets();
|
let offsets = Image::field_offsets();
|
||||||
rtti.insert(
|
rtti.insert(
|
||||||
"Image",
|
"Image",
|
||||||
|
@ -136,6 +138,45 @@ fn main() -> std::io::Result<()> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let offsets = Text::field_offsets();
|
||||||
|
rtti.insert(
|
||||||
|
"Text",
|
||||||
|
RuntimeTypeInfo {
|
||||||
|
vtable: &corelib::abi::primitives::ImageVTable as _,
|
||||||
|
construct: construct::<Text>,
|
||||||
|
properties: [
|
||||||
|
("x", (offsets.x.get_byte_offset(), set_property::<f32> as _)),
|
||||||
|
("y", (offsets.y.get_byte_offset(), set_property::<f32> as _)),
|
||||||
|
("text", (offsets.text.get_byte_offset(), set_property::<SharedString> as _)),
|
||||||
|
("color", (offsets.color.get_byte_offset(), set_property::<u32> as _)),
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.collect(),
|
||||||
|
size: std::mem::size_of::<Text>(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
let offsets = TouchArea::field_offsets();
|
||||||
|
rtti.insert(
|
||||||
|
"TouchArea",
|
||||||
|
RuntimeTypeInfo {
|
||||||
|
vtable: &corelib::abi::primitives::TouchAreaVTable as _,
|
||||||
|
construct: construct::<TouchArea>,
|
||||||
|
properties: [
|
||||||
|
("x", (offsets.x.get_byte_offset(), set_property::<f32> as _)),
|
||||||
|
("y", (offsets.y.get_byte_offset(), set_property::<f32> as _)),
|
||||||
|
("width", (offsets.width.get_byte_offset(), set_property::<f32> as _)),
|
||||||
|
("height", (offsets.height.get_byte_offset(), set_property::<f32> as _)),
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.collect(),
|
||||||
|
size: std::mem::size_of::<TouchArea>(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
let l = lower::LoweredComponent::lower(&*tree.root_component);
|
let l = lower::LoweredComponent::lower(&*tree.root_component);
|
||||||
|
|
||||||
let mut tree_array = vec![];
|
let mut tree_array = vec![];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue