Commit 1683e4a4 authored by Florian Blasius's avatar Florian Blasius 🤘

[api update] refactoring, fixes, scrollviewer,

cursor, switch.
parent c62a3dfe
image: 'rust:latest'
stages:
- build
- test
- build
- test
variables:
CARGO_HOME: $CI_PROJECT_DIR/cargo
CARGO_HOME: $CI_PROJECT_DIR/cargo
before_script:
- apt-get update -qq
- apt-get install -qq build-essential curl git
......@@ -41,12 +41,12 @@ build:redox:
- target/
test:linux:
stage: test
before_script:
stage: test
before_script:
- apt-get update && apt-get -y install cmake
- apt-get install libsdl2-dev -y
dependencies:
- build:linux
script:
- rustup default nightly
- cargo test
dependencies:
- build:linux
script:
- rustup default nightly
- cargo test
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug widgets",
"program": "${workspaceFolder}/target/debug/examples/widgets",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug canvas",
"program": "${workspaceFolder}/target/debug/examples/canvas",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug image",
"program": "${workspaceFolder}/target/debug/examples/image",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug light theme",
"program": "${workspaceFolder}/target/debug/examples/light-theme",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug messages",
"program": "${workspaceFolder}/target/debug/examples/messages",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug grid",
"program": "${workspaceFolder}/target/debug/examples/grid",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug minimal",
"program": "${workspaceFolder}/target/debug/examples/minimal",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug tests",
"cargo": {
"args": [
"test",
"--no-run",
"--lib"
]
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug widgets",
"program": "${workspaceFolder}/target/debug/examples/widgets",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug canvas",
"program": "${workspaceFolder}/target/debug/examples/canvas",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug image",
"program": "${workspaceFolder}/target/debug/examples/image",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug light theme",
"program": "${workspaceFolder}/target/debug/examples/light-theme",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug messages",
"program": "${workspaceFolder}/target/debug/examples/messages",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug grid",
"program": "${workspaceFolder}/target/debug/examples/grid",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug minimal",
"program": "${workspaceFolder}/target/debug/examples/minimal",
"cwd": "${workspaceFolder}",
"preLaunchTask": "build",
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug tests",
"cargo": {
"args": [
"test",
"--no-run",
"--lib"
]
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
\ No newline at end of file
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "cargo",
"type": "shell",
"args": [
"build",
"--examples=minimal"
],
"presentation": {
"reveal": "always",
"panel": "new",
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "cargo",
"type": "shell",
"args": [
"build",
"--examples=minimal"
],
"presentation": {
"reveal": "always",
"panel": "new"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
\ No newline at end of file
......@@ -20,7 +20,6 @@ use orbtk::*;
// }
// widget!(MainView);
// impl Widget for MainView {
......
......@@ -11,14 +11,14 @@ use crate::{
backend::{target_backend, BackendRunner},
event::EventHandler,
layout::Layout,
properties::{Bounds, Constraint},
properties::*,
render_object::RenderObject,
structs::{Size, Rect},
systems::{
EventSystem, InitSystem, LayoutSystem, PostLayoutStateSystem, RenderSystem, StateSystem,
},
theme::Theme,
widget::{PropertyResult, State, BuildContext, Widget},
widget::{State, BuildContext, Widget},
Global,
};
......@@ -97,6 +97,7 @@ impl<'a> WindowBuilder<'a> {
let window = world
.create_entity()
.with(Global::default())
.with(Name::from("Window"))
.with(Bounds::from(Rect::new(
0.0,
0.0,
......@@ -117,14 +118,6 @@ impl<'a> WindowBuilder<'a> {
let running = Rc::new(Cell::new(true));
let debug_flag = Rc::new(Cell::new(self.debug_flag));
if debug_flag.get() {
println!("------ Start build tree ------\n");
}
if debug_flag.get() {
println!("Window (id = {}, children_len = 1)", window, );
}
let mut context = BuildContext::new(
&mut world,
render_objects.clone(),
......@@ -139,6 +132,8 @@ impl<'a> WindowBuilder<'a> {
world.register_init_system(InitSystem {
backend: backend.clone(),
states: states.clone(),
debug_flag: debug_flag.clone(),
});
world
......@@ -207,244 +202,4 @@ impl<'a> WindowBuilder<'a> {
debug_flag,
})
}
// /// Creates the window with the given properties and builds its widget tree.
// pub fn build(self) {
// let (mut runner, backend) =
// target_backend(&self.title, self.bounds, self.resizable, self.theme);
// let mut world = World::from_container(Tree::default());
// let render_objects = Rc::new(RefCell::new(BTreeMap::new()));
// let layouts = Rc::new(RefCell::new(BTreeMap::new()));
// let handlers = Rc::new(RefCell::new(BTreeMap::new()));
// let states = Rc::new(RefCell::new(BTreeMap::new()));
// let update = Rc::new(Cell::new(true));
// let running = Rc::new(Cell::new(true));
// let debug_flag = Rc::new(Cell::new(self.debug_flag));
// if debug_flag.get() {
// println!("------ Start build tree ------\n");
// }
// // register window as entity with global properties
// if world.entity_container().is_empty() {
// let window = world
// .create_entity()
// .with(Global::default())
// .with(Bounds::from(Rect::new(
// 0.0,
// 0.0,
// self.bounds.width(),
// self.bounds.height(),
// )))
// .with(Constraint::default())
// .build();
// if debug_flag.get() {
// println!("Window (id = {}, children_len = 1)", window,);
// }
// }
// // if let Some(root) = self.root {
// // build_tree(
// // root,
// // &mut world,
// // &render_objects,
// // &layouts,
// // &handlers,
// // &states,
// // &debug_flag,
// // );
// // }
// world.register_init_system(InitSystem {
// backend: backend.clone(),
// });
// world
// .create_system(EventSystem {
// backend: backend.clone(),
// handlers: handlers.clone(),
// update: update.clone(),
// running: running.clone(),
// })
// .with_priority(0)
// .build();
// world
// .create_system(StateSystem {
// backend: backend.clone(),
// states: states.clone(),
// update: update.clone(),
// running: running.clone(),
// })
// .with_priority(1)
// .build();
// world
// .create_system(LayoutSystem {
// backend: backend.clone(),
// layouts: layouts.clone(),
// update: update.clone(),
// debug_flag: debug_flag.clone(),
// running: running.clone(),
// })
// .with_priority(2)
// .build();
// world
// .create_system(PostLayoutStateSystem {
// backend: backend.clone(),
// states: states.clone(),
// update: update.clone(),
// running: running.clone(),
// })
// .with_priority(3)
// .build();
// world
// .create_system(RenderSystem {
// backend: backend.clone(),
// render_objects: render_objects.clone(),
// update: update.clone(),
// debug_flag: debug_flag.clone(),
// running: running.clone(),
// })
// .with_priority(4)
// .build();
// runner.world(world);
// self.application.windows.push(Window {
// backend_runner: runner,
// render_objects,
// layouts,
// handlers,
// states,
// update,
// running,
// resizable: self.resizable,
// debug_flag,
// })
// }
}
// Builds the widget tree.
// fn build_tree(
// root: Template,
// world: &mut World<Tree>,
// render_objects: &Rc<RefCell<BTreeMap<Entity, Box<dyn RenderObject>>>>,
// layouts: &Rc<RefCell<BTreeMap<Entity, Box<dyn Layout>>>>,
// handlers: &Rc<RefCell<BTreeMap<Entity, Vec<Rc<dyn EventHandler>>>>>,
// states: &Rc<RefCell<BTreeMap<Entity, Rc<dyn State>>>>,
// debug_flag: &Rc<Cell<bool>>,
// ) {
// fn expand(
// world: &mut World<Tree>,
// render_objects: &Rc<RefCell<BTreeMap<Entity, Box<dyn RenderObject>>>>,
// layouts: &Rc<RefCell<BTreeMap<Entity, Box<dyn Layout>>>>,
// handlers: &Rc<RefCell<BTreeMap<Entity, Vec<Rc<dyn EventHandler>>>>>,
// states: &Rc<RefCell<BTreeMap<Entity, Rc<dyn State>>>>,
// template: Template,
// debug_flag: &Rc<Cell<bool>>,
// depth: usize,
// ) -> Entity {
// let mut template = template;
// let entity = {
// let mut entity_builder = world.create_entity();
// // normal properties
// // for (_, value) in template.properties.drain() {
// // entity_builder = entity_builder.with_box(value);
// // }
// // shared property
// for (_, value) in template.shared_properties {
// match value.build() {
// PropertyResult::Property(property, source) => {
// entity_builder = entity_builder.with_box(property);
// source.set(Some(entity_builder.entity));
// }
// PropertyResult::Source(source) => {
// entity_builder = entity_builder.with_shared_box(source);
// }
// PropertyResult::PropertyNotFound => {}
// }
// }
// // constraint
// entity_builder = entity_builder.with(template.constraint);
// let entity = entity_builder.build();
// if let Some(render_object) = template.render_object {
// render_objects.borrow_mut().insert(entity, render_object);
// }
// layouts.borrow_mut().insert(entity, template.layout);
// let widget_handlers = template.event_handlers;
// if !widget_handlers.is_empty() {
// let mut event_handlers = vec![];
// for handler in widget_handlers {
// event_handlers.push(handler.clone());
// }
// handlers.borrow_mut().insert(entity, event_handlers);
// }
// if let Some(state) = template.state {
// states.borrow_mut().insert(entity, state.clone());
// }
// entity
// };
// if debug_flag.get() {
// println!(
// "{}{} (id = {}, children_len = {})",
// "| ".repeat(depth),
// template.debug_name,
// entity,
// template.children.len()
// );
// }
// if world.entity_container().len() == 2 {
// let root = world.entity_container().root;
// let _result = world.entity_container().append_child(root, entity);
// }
// for child in template.children.drain(0..) {
// let child = expand(
// world,
// render_objects,
// layouts,
// handlers,
// states,
// child,
// debug_flag,
// depth + 1,
// );
// let _result = world.entity_container().append_child(entity, child);
// }
// entity
// }
// expand(
// world,
// render_objects,
// layouts,
// handlers,
// states,
// root,
// debug_flag,
// 1,
// );
// if debug_flag.get() {
// println!("\n------ End build tree ------ ");
// }
// }
......@@ -71,9 +71,9 @@ impl Layout for FixedSizeLayout {
None
}
} else if widget.has_property::<Text>() {
let text = widget.get_property::<Text>();
let font = widget.get_property::<Font>();
let font_size = widget.get_property::<FontSize>();
let text = widget.property::<Text>();
let font = widget.property::<Font>();
let font_size = widget.property::<FontSize>();
if text.0.is_empty() {
if let Ok(water_mark) = ecm.borrow_component::<WaterMark>(entity) {
......@@ -94,14 +94,14 @@ impl Layout for FixedSizeLayout {
Some(size)
}
} else if widget.has_property::<FontIcon>() {
let font_icon = widget.get_property::<FontIcon>();
let font_icon = widget.property::<FontIcon>();
if font_icon.0.is_empty() {
None
} else {
Some(FONT_MEASURE.measure(
&font_icon.0,
&(widget.get_property::<IconFont>().0).0,
widget.get_property::<IconSize>().0 as u32,
&(widget.property::<IconFont>().0).0,
widget.property::<IconSize>().0 as u32,
))
}
} else {
......
This diff is collapsed.
This diff is collapsed.
......@@ -3,7 +3,7 @@
macro_rules! property {
($(#[$property_doc:meta])* $property:ident($type:ty)) => {
use dces::prelude::{Entity, EntityComponentManager};
use crate::widget::{PropertySource, get_property};
use crate::properties::{PropertySource, get_property};
#[derive(Default, Debug, Clone, PartialEq)]
$(#[$property_doc])*
......@@ -57,8 +57,8 @@ macro_rules! widget {
use dces::prelude::{Component, ComponentBox, SharedComponentBox };
use crate::{event::EventHandler,
properties::{Bounds, Constraint, VerticalAlignment, HorizontalAlignment, Visibility, Name},
widget::{PropertySource, Widget, BuildContext},
properties::{PropertySource, Bounds, Constraint, VerticalAlignment, HorizontalAlignment, Visibility, Name},
widget::{Widget, BuildContext},
structs::Point};
$(#[$widget_doc])*
......@@ -96,6 +96,12 @@ macro_rules! widget {
self
}
/// Shares an attached property.
pub fn attach_by_source<P: Component>(mut self, source: Entity) -> Self {
self.shared_attached_properties.insert(TypeId::of::<P>(), SharedComponentBox::new(TypeId::of::<P>(), source));
self
}
/// Sets or shares the constraint property.
pub fn constraint<P: Into<PropertySource<Constraint>>>(self, constraint: P) -> Self {
self.attach(constraint)
......@@ -223,7 +229,7 @@ macro_rules! widget {
vertical_alignment: VerticalAlignment::default(),
visibility: Visibility::default(),
margin: Margin::default(),
enabled: Enabled(false),
enabled: Enabled(true),
$(
$(
$property: None,
......@@ -244,8 +250,8 @@ macro_rules! widget {
}
$(
fn state(self) -> Option<Rc<State>> {
Rc::new($state::new())
fn state(&self) -> Option<Rc<State>> {
Some(Rc::new($state::default()))
}
)*
......@@ -260,6 +266,11 @@ macro_rules! widget {
context.register_layout(entity, this.layout());
// register state
if let Some(state) = this.state() {
context.register_state(entity, state);
}
// register default set of properties
context.register_property(entity, this.bounds);
context.register_property(entity, this.constraint);
......@@ -267,6 +278,7 @@ macro_rules! widget {
context.register_property(entity, this.horizontal_alignment);
context.register_property(entity, this.visibility);
context.register_property(entity, this.margin);
context.register_property(entity, this.enabled);
// register helpers
context.register_property(entity, Point::default());
......@@ -299,11 +311,10 @@ macro_rules! widget {
// register event handlers
for handler in this.event_handlers {
context.register_handler(entity, handler);
}
}
// register name
if let Some(name) = this.name {
println!("{} (id = {}, children_len = {})", name.0, entity, this.children.len());
context.register_property(entity, name);
}
......
// /// `Offset` is used to move an widget along the x- and y-axis.
// #[derive(Default, Clone, Copy)]
// pub struct Offset(pub f64, pub f64);
property!(
/// `Offset` describes the x- and y-axis offset of a widget.
Offset((f64, f64))
);
// property!(Offset, OffsetProperty, offset, shared_offset);
impl From<f64> for Offset {
fn from(t: f64) -> Self {
Offset((t, t))
}
}
// impl From<(f64, f64)> for Offset {
// fn from(t: (f64, f64)) -> Self {
// Offset(t.0, t.1)
// }
// }
// impl From<f64> for Offset {
// fn from(t: f64) -> Self {
// Offset(t, t)
// }
// }
impl Into<PropertySource<Offset>> for f64 {
fn into(self) -> PropertySource<Offset> {
PropertySource::Value(Offset::from(self))