Commit ed4136e5 authored by Florian Blasius's avatar Florian Blasius 🤘

[update] documentation and tests.

parent 707bd5f2
......@@ -153,7 +153,6 @@ impl Renderer for OrbWindow {
color: Color,
font: &str,
) {
// todo handle alpha by orbfong
let alpha = (color.data >> 24) & 0xFF;
if alpha == 0 {
......
......@@ -2,6 +2,7 @@ use std::rc::Rc;
use crate::{Event, EventBox, EventHandler, Template};
/// Represents a keyboard key.
#[derive(Copy, Clone, Debug, Hash, PartialEq)]
pub enum Key {
Unknown,
......@@ -295,6 +296,7 @@ impl Event for KeyUpEvent {}
pub type KeyHandler = Fn(Key) -> bool + 'static;
/// Used to handle key down events. Could be attached to a widget.
pub struct KeyDownEventHandler {
handler: Rc<KeyHandler>,
}
......
......@@ -58,6 +58,7 @@ pub type MouseHandler = Fn(Point) -> bool + 'static;
use crate::Template;
/// Used to handle click events. Could be attached to a widget.
pub struct ClickEventHandler {
handler: Rc<MouseHandler>,
}
......
......@@ -87,7 +87,7 @@ impl Layout for FixedSizeLayout {
} else {
Some(FONT_MEASURE.measure(
&font_icon.0,
&theme.string("icon-font-family", selector),
&theme.string("icon-familiy", selector),
theme.uint("icon-size", selector),
))
}
......
......@@ -21,6 +21,8 @@ use super::{
Layout,
};
/// Orders its children in a grid layout with columns and rows. If now columns and rows are defined
/// the gird layout could also be used as alignment layout.
#[derive(Default)]
pub struct GridLayout {
desired_size: Cell<(f64, f64)>,
......
......@@ -92,8 +92,8 @@ pub fn get_constraint(entity: Entity, ecm: &EntityComponentManager) -> Constrain
}
pub fn get_visibility(entity: Entity, ecm: &EntityComponentManager) -> Visibility {
if let Ok(visiblity) = ecm.borrow_component::<Visibility>(entity) {
return *visiblity;
if let Ok(visibility) = ecm.borrow_component::<Visibility>(entity) {
return *visibility;
}
Visibility::Collapsed
......
......@@ -18,6 +18,7 @@ use super::{
get_visibility, Layout,
};
/// Add padding to the widget.
#[derive(Default)]
pub struct PaddingLayout {
desired_size: Cell<(f64, f64)>,
......
......@@ -18,6 +18,7 @@ use super::{
Layout,
};
/// Stacks visual the children widgets vertical or horizontal.
#[derive(Default)]
pub struct StackLayout {
desired_size: Cell<(f64, f64)>,
......
......@@ -10,7 +10,7 @@ use crate::{
application::Tree,
backend::{FontMeasure, FONT_MEASURE},
properties::{Bounds, Margin, Offset, Text, TextSelection, Visibility},
structs::{Position, Size, Spacer},
structs::{Size, Spacer},
theme::{Selector, Theme},
};
......
use std::f64;
// todo: unit test for builder
/// Used to build a constraint, specifying additional details.
#[derive(Default)]
pub struct ConstraintBuilder {
......
......@@ -15,5 +15,3 @@ impl From<f64> for Offset {
Offset(t, t)
}
}
// todo tests
// todo: write tests.
use super::*;
#[test]
......@@ -54,8 +53,6 @@ fn test_set_current_width() {
#[test]
fn test_column() {
let width = ColumnWidth::Width(64.0);
let builder = ColumnsBuilder::new();
let columns = builder.build();
......
use super::*;
#[test]
fn test_builder_width() {
let width = 12.0;
let constraint = Constraint::create().width(width).build();
assert_eq!(constraint.width(), width);
}
#[test]
fn test_builder_height() {
let height = 12.0;
let constraint = Constraint::create().height(height).build();
assert_eq!(constraint.height(), height);
}
#[test]
fn test_builder_min_width() {
let width = 12.0;
let constraint = Constraint::create().min_width(width).build();
assert_eq!(constraint.min_width(), width);
}
#[test]
fn test_builder_min_height() {
let height = 12.0;
let constraint = Constraint::create().min_height(height).build();
assert_eq!(constraint.min_height(), height);
}
#[test]
fn test_builder_max_width() {
let width = 12.0;
let constraint = Constraint::create().max_width(width).build();
assert_eq!(constraint.max_width(), width);
}
#[test]
fn test_builder_max_height() {
let height = 12.0;
let constraint = Constraint::create().max_height(height).build();
assert_eq!(constraint.max_height(), height);
}
#[test]
fn test_set_width() {
let width = 12.0;
......
......@@ -5,6 +5,7 @@ mod column;
mod constraint;
mod horizontal_alignment;
mod margin;
mod offset;
mod orientation;
mod padding;
mod point;
......
use super::*;
#[test]
fn test_into() {
let offset: Offset = 14.0.into();
assert_eq!(offset.0, 14.0);
assert_eq!(offset.1, 14.0);
let offset: Offset = (14.0, 16.0).into();
assert_eq!(offset.0, 14.0);
assert_eq!(offset.1, 16.0);
}
\ No newline at end of file
......@@ -11,3 +11,6 @@ mod image;
mod text;
mod text_selection;
mod water_mark;
#[cfg(test)]
mod tests;
use super::*;
mod text_selection;
mod water_mark;
\ No newline at end of file
use super::*;
#[test]
fn test_into() {
let offset: TextSelection = (14, 16).into();
assert_eq!(offset.start_index, 14);
assert_eq!(offset.length, 16);
}
\ No newline at end of file
use super::*;
#[test]
fn test_into() {
let water_mark: WaterMark = "test".into();
assert_eq!(water_mark.0, "test");
assert_eq!(water_mark.0, "test");
}
\ No newline at end of file
......@@ -12,7 +12,6 @@ property!(
shared_text_selection
);
// todo write test
impl From<(usize, usize)> for TextSelection {
fn from(t: (usize, usize)) -> Self {
TextSelection {
......
......@@ -55,7 +55,7 @@ impl RenderObject for FontIconRenderObject {
global_position,
theme.uint("icon-size", selector),
theme.color("icon-color", selector),
&theme.string("icon-font-family", selector),
&theme.string("icon-familiy", selector),
);
}
}
......
......@@ -7,7 +7,7 @@
font-family: "Roboto Regular";
icon-size: 16;
icon-color: #dfebf5;
icon-font-family: "Material Icons Regular";
icon-familiy: "Material Icons Regular";
}
checkbox {
......@@ -46,8 +46,6 @@ switchtoggle:selected {
}
button, togglebutton {
min-width: 80;
height: 32;
background: #647b91;
border-radius: 2;
}
......
......@@ -10,6 +10,7 @@ use crate::{
theme::{Selector, Theme},
};
/// This system is used to initializes the widgets.
pub struct InitSystem {
pub backend: Rc<RefCell<dyn Backend>>,
......@@ -36,10 +37,8 @@ impl InitSystem {
}
}
// todo: read properties from theme!!!
// Read all initial data from css
fn read_init_from_theme(&self, node: Entity, ecm: &mut EntityComponentManager, theme: &Theme) {
fn _read_init_from_theme(&self, node: Entity, ecm: &mut EntityComponentManager, theme: &Theme) {
let mut margin = Thickness::default();
let mut padding = Thickness::default();
let (mut width, mut height, mut min_width, mut min_height, mut max_width, mut max_height) =
......@@ -129,7 +128,7 @@ impl InitSystem {
impl System<Tree> for InitSystem {
fn run(&self, tree: &Tree, ecm: &mut EntityComponentManager) {
let mut backend = self.backend.borrow_mut();
let context = backend.state_context();
// let context = backend.state_context();
// init css ids
for node in tree.into_iter() {
......
......@@ -465,7 +465,7 @@ impl<'i> cssparser::DeclarationParser<'i> for DeclarationParser {
"background" | "foreground" => Value::Color(parse_basic_color(input)?),
"font-family" | "icon-font-family" => Value::Str(parse_string(input)?),
"font-family" | "icon-familiy" => Value::Str(parse_string(input)?),
"border-radius" | "border-width" | "font-size" | "icon-size" | "icon-margin" => {
match input.next()? {
......
......@@ -10,19 +10,12 @@ use crate::{
/// The `Button` widget can be clicked by user. It's used to perform an action.
///
/// # Shared Properties
///
/// * `Text` - String used to display the text of the button.
/// * `FontIcon` - String used to display the font icon of the button.
/// * `Selector` - CSS selector with element name `button`, used to request the theme of the widget.
///
/// # Properties
///
/// * `Pressed` - Bool value represents the pressed state of the button.
///
/// # Others
///
/// * `ParentType`- Single.
/// * `text` - String used to display the text of the button.
/// * `font_icon` - String used to display the font icon of the button.
/// * `selector` - CSS selector with element name `button`, used to request the theme of the widget.
/// * `pressed` - Bool value represents the pressed state of the button.
pub struct Button;
impl Widget for Button {
......
......@@ -5,6 +5,8 @@ use crate::{
widget::{Template, Widget},
};
// Unused at the moment!!!
/// The `CanvasWidget` widget is used to provide custom drawing by handling the `Canvas` struct from `OrbGl` as property.
///
/// # Properties
......
use crate::{
material_font_icons,
properties::{
Constraint, ConstraintBuilder, FontIcon, FontIconProperty, OrientationProperty,
Constraint, FontIcon, FontIconProperty, OrientationProperty,
PressedProperty, SelectedProperty, Text, TextProperty,
},
theme::Selector,
......@@ -9,19 +9,12 @@ use crate::{
};
/// The `Checkbox` widget can be switch its selected state. It contains a selection box and a text.
///
/// # Shared Properties
///
/// * `Text` - String used to display the text of the check box.
/// * `FontIcon` - String used to display the font icon of the check box.
/// * `Selector` - CSS selector with element name `checkbox`, used to request the theme of the widget.
///
/// # Properties
///
/// * `Selected` - Bool value represents the selected state of the widget.
///
/// # Others
///
/// * `ParentType`- Single.
/// * `text` - String used to display the text of the check box.
/// * `font_icon` - String used to display the font icon of the check box.
/// * `selector` - CSS selector with element name `checkbox`, used to request the theme of the widget.
/// * `selected` - Bool value represents the selected state of the widget.
pub struct CheckBox;
impl Widget for CheckBox {
......@@ -74,5 +67,3 @@ template!(
SelectedProperty
]
);
// todo attach event handler
......@@ -9,11 +9,10 @@ use crate::{
///
/// # Properties
///
/// * `Selector` - CSS selector with element name `container`, used to request the theme of the widget.
/// * `selector` - CSS selector with element name `container`, used to request the theme of the widget.
///
/// # Others
///
/// * `ParentType`- Single.
/// * `PaddingLayout` - Used to layout the widget.
/// * `RectangleRenderObject` - Used to draw the widget.
pub struct Container;
......
use dces::prelude::{Component, Entity, EntityComponentManager, NotFound};
/// The `WidgetContainer` wraps the entity of a widget and provides access to its propeties, its children properties and its parent properties.
/// The `WidgetContainer` wraps the entity of a widget and provides access to its properties, its children properties and its parent properties.
pub struct WidgetContainer<'a> {
ecm: &'a mut EntityComponentManager,
current_node: Entity,
......@@ -16,13 +16,13 @@ impl<'a> WidgetContainer<'a> {
}
/// Returns a reference of a property of type `P` from the given widget entity. If the entity does
/// not exists or it dosen't have a component of type `P` `NotFound` will be returned.
/// not exists or it doesn't have a component of type `P` `NotFound` will be returned.
pub fn borrow_property<P: Component>(&self) -> Result<&P, NotFound> {
self.ecm.borrow_component::<P>(self.current_node)
}
/// Returns a mutable reference of a property of type `P` from the given widget entity. If the entity does
/// not exists or it dosen't have a component of type `P` `NotFound` will be returned.
/// not exists or it doesn't have a component of type `P` `NotFound` will be returned.
pub fn borrow_mut_property<P: Component>(&mut self) -> Result<&mut P, NotFound> {
self.ecm.borrow_mut_component::<P>(self.current_node)
}
......
......@@ -36,7 +36,8 @@ impl State for CursorState {
///
/// # Properties
///
/// * `TextSelection` - Represents the current selection of the text used by the cursor.
/// * `text_selection` - Represents the current selection of the text used by the cursor.
/// * `text` - Used to set the text of the cursor.
///
/// # Others
///
......
......@@ -9,11 +9,10 @@ use crate::{
///
/// # Properties
///
/// * `Selector` - CSS selector with element name `fonticon`, used to request the theme of the font icon block.
/// * `selector` - CSS selector with element name `fonticon`, used to request the theme of the font icon block.
///
/// # Others
///
/// * `ParentType`- None.
/// * `FixedSizeLayout` - Used to layout the widget.
/// * `FontIconRenderObject` - Used to draw the text of the widget.
pub struct FontIconBlock;
......
......@@ -10,14 +10,9 @@ use crate::{
///
/// # Properties
///
/// * `Background` - stores the css background.
/// * `Columns` - used to define the columns of the grid.
/// * `Rows` - used to define the rows of the grid.
/// * `Selector` - css selector with element `grid`.
///
/// # CSS properties
///
/// * `background` - defines the background of the widget.
/// * `columns` - used to define the columns of the grid.
/// * `rows` - used to define the rows of the grid.
/// * `selector` - css selector with element `grid`.
///
/// # Others
///
......
......@@ -9,11 +9,10 @@ use crate::{
///
/// # Properties
///
/// * `Selector` - CSS selector with element name `image`, used to request the theme of the image widget.
/// * `selector` - CSS selector with element name `image`, used to request the theme of the image widget.
///
/// # Others
///
/// * `ParentType`- None.
/// * `ImageSizeLayout` - Used to layout the widget.
/// * `ImageRenderObject` - Used to draw the image of the widget.
pub struct ImageWidget;
......
......@@ -4,17 +4,16 @@ use crate::{
widget::{Template, Widget},
};
/// The `ScrollViewer` represents a layout widget that adds vertical and horizontal offset to its parent.
/// The `ScrollViewer` (wip) represents a layout widget that adds vertical and horizontal offset to its parent.
/// It is used to scroll the content if the content's width or height is greater than the ScrollViewers width or height.
///
/// # Properties
///
/// * `Offset` - Represents the vertical and horizontal scroll offset.
/// * `ScrollMode` - Scroll mode vertical / horizontal off the scroll viewer.
/// * `offset` - Represents the vertical and horizontal scroll offset.
/// * `scroll_viewer_mode` - Scroll mode vertical / horizontal off the scroll viewer.
///
/// # Others
///
/// * `ParentType`- Single.
/// * `ScrollLayout` - Used to layout the widget.
pub struct ScrollViewer;
......
......@@ -7,6 +7,10 @@ use crate::{
/// The `Stack` represents a layout widget that is used to stack its children on the z-axis.
///
/// # Properties
///
/// * `orientation` - used to define the orientation of the stack layout vertical (default) of horizontal.
///
/// # Others
///
/// * `ParentType`- Mutli.
......
......@@ -34,13 +34,10 @@ impl State for SwitchState {
/// The `Switch` widget can be switch between `on` and `off`.
///
/// # Shared Properties
///
/// * `Selector` - CSS selector with element name `checkbox`, used to request the theme of the widget.
///
/// # Properties
///
/// * `Selected` - Bool value represents the selected state of the widget.
/// * `selector` - CSS selector with element name `checkbox`, used to request the theme of the widget.
/// * `selected` - Bool value represents the selected state of the widget.
///
/// # Others
///
......
......@@ -9,12 +9,11 @@ use crate::{
///
/// # Properties
///
/// * `Text` - String used to display the text of the text block.
/// * `Selector` - CSS selector with element name `textblock`, used to request the theme of the text block.
/// * `text` - String used to display the text of the text block.
/// * `selector` - CSS selector with element name `textblock`, used to request the theme of the text block.
///
/// # Others
///
/// * `ParentType`- None.
/// * `FixedSizeLayout` - Used to layout the widget.
/// * `TextRenderObject` - Used to draw the text of the widget.
pub struct TextBlock;
......
......@@ -171,18 +171,17 @@ impl State for TextBoxState {
/// The `TextBox` represents a single line text input widget.
///
/// # Shared Properties
/// # Properties
///
/// * `Text` - String used to display the text of the text box.
/// * `Watermark` - String used to display a placeholder text if `Text` string is empty.
/// * `Selector` - CSS selector with element name `textbox`, used to request the theme of the widget.
/// * `TextSelection` - Represents the current selection of the text used by the cursor.
/// * `Focused` - Defines if the widget is focused and handles the current text input.
/// * `text` - String used to display the text of the text box.
/// * `water_mark` - String used to display a placeholder text if `Text` string is empty.
/// * `selector` - CSS selector with element name `textbox`, used to request the theme of the widget.
/// * `text_selection` - Represents the current selection of the text used by the cursor.
/// * `focused` - Defines if the widget is focused and handles the current text input.
///
/// # Others
///
/// * `TextBoxState` - Handles the inner state of the widget.
/// * `KeyEventHandler` - Process the text input of the control if it is focused.
pub struct TextBox;
impl Widget for TextBox {
......
use crate::{
properties::{
Constraint, ConstraintBuilder, FontIcon, FontIconProperty, OrientationProperty,
Constraint, FontIcon, FontIconProperty, OrientationProperty,
PaddingProperty, PressedProperty, SelectedProperty, Text, TextProperty,
},
theme::Selector,
......@@ -9,19 +9,12 @@ use crate::{
/// The `ToggleButton` widget can be clicked by user. It's used to perform an action.
///
/// # Shared Properties
///
/// * `Text` - String used to display the text of the button.
/// * `FontIcon` - String used to display the font icon of the button.
/// * `Selector` - CSS selector with element name `button`, used to request the theme of the widget.
///
/// # Properties
///
/// * `Pressed` - Bool value represents the pressed state of the button.
///
/// # Others
///
/// * `ParentType`- Single.
/// * `text` - String used to display the text of the button.
/// * `font_icon` - String used to display the font icon of the button.
/// * `selector` - CSS selector with element name `button`, used to request the theme of the widget.
/// * `pressed` - Bool value represents the pressed state of the button.
pub struct ToggleButton;
impl Widget for ToggleButton {
......
......@@ -55,12 +55,11 @@ impl State for WaterMarkTextBlockState {
///
/// # Properties
///
/// * `Watermark` - String used to display a placeholder text if `Text` string is empty.
/// * `Selector` - CSS selector with element name `textblock` and class `watermark`, used to request the theme of the WaterMarkTextBlock.
/// * `watermark` - String used to display a placeholder text if `Text` string is empty.
/// * `selector` - CSS selector with element name `watermark` used to request the theme of the WaterMarkTextBlock.
///
/// # Others
///
/// * `ParentType`- None.