diff --git a/frontends/rioterm/src/context/grid.rs b/frontends/rioterm/src/context/grid.rs index de49be4807..007976a8b9 100644 --- a/frontends/rioterm/src/context/grid.rs +++ b/frontends/rioterm/src/context/grid.rs @@ -1021,2566 +1021,2566 @@ pub mod test { ); } - #[test] - fn test_split_right() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 1200.0, - 800.0, - SugarDimensions { - scale: 1., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 85); - assert_eq!(context_dimension.lines, 100); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - grid.split_right(second_context); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [0.0, 0.0], - }), - create_border([1.0, 0.0, 0.0, 0.0], [0.0, 800.0], [598., 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [598.0, 0.0], [1.0, 800.0]), - Object::RichText(RichText { - id: second_context_id, - position: [600., 0.0] - }), - create_border([1.0, 0.0, 0.0, 0.0], [600.0, 800.0], [600.0, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [1200.0, 0.0], [1.0, 800.0]), - ] - ); - - let (third_context, third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_right(third_context); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [0.0, 0.0], - }), - create_border([1.0, 0.0, 0.0, 0.0], [0.0, 800.0], [598., 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [598.0, 0.0], [1.0, 800.0]), - Object::RichText(RichText { - id: second_context_id, - position: [600.0, 0.0] - }), - create_border([1.0, 0.0, 0.0, 0.0], [600.0, 800.0], [298.0, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [898.0, 0.0], [1.0, 800.0]), - Object::RichText(RichText { - id: third_context_id, - position: [900.0, 0.0] - }), - create_border([1.0, 0.0, 0.0, 0.0], [900.0, 800.0], [300.0, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [1200.0, 0.0], [1.0, 800.0]), - ] - ); - } - - #[test] - fn test_split_right_with_margin() { - let margin = Delta { - x: 20., - top_y: 30., - bottom_y: 40., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [margin.x, margin.top_y], - })] - ); - grid.split_right(second_context); - - /* - > before split: - 20 (600/20) - |------| - - Available width should compute with margin - so should be 600 - 20 = 580, then will be: - 289 + 4 (PADDING) + 290 - - > after split: - 10 (289/0) (4) (290/10) - |----------|----------| - - Margin should be splitted between first columns - items and last columns items - */ - - let contexts = grid.contexts(); - assert_eq!(contexts[0].val.dimension.width, 286.); - assert_eq!(contexts[0].val.dimension.margin.x, 0.); - assert_eq!(contexts[1].val.dimension.width, 290.); - assert_eq!(contexts[1].val.dimension.margin.x, 10.); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [margin.x, margin.top_y], - }), - create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: second_context_id, - position: [167.0, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [145.0, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [312.0, margin.top_y], [1.0, 300.0]), - ] - ); - - let (third_context, third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_right(third_context); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [margin.x, margin.top_y], - }), - create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: second_context_id, - position: [167.0, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [65.5, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [232.5, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: third_context_id, - position: [236.5, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [236.5, 330.0], [67.5, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [304.0, margin.top_y], [1.0, 300.0]), - ] - ); - - // Last context should be updated with half of x - let contexts = grid.contexts(); - assert_eq!(contexts[0].val.dimension.width, 286.); - assert_eq!(contexts[0].val.dimension.margin.x, 0.); - assert_eq!(contexts[1].val.dimension.width, 131.); - assert_eq!(contexts[1].val.dimension.margin.x, 0.); - assert_eq!(contexts[2].val.dimension.width, 135.); - assert_eq!(contexts[2].val.dimension.margin.x, 10.); - - let (fourth_context, fourth_context_id) = { - let rich_text_id = 3; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.select_prev_split(); - grid.split_right(fourth_context); - - // If the split right happens in not the last - // then should not update margin to half of x - let contexts = grid.contexts(); - assert_eq!(contexts[0].val.dimension.width, 286.); - assert_eq!(contexts[0].val.dimension.margin.x, 0.); - assert_eq!(contexts[1].val.dimension.width, 51.5); - assert_eq!(contexts[1].val.dimension.margin.x, 0.); - assert_eq!(contexts[3].val.dimension.width, 55.5); - assert_eq!(contexts[3].val.dimension.margin.x, 0.); - - // 2 is the last one - assert_eq!(contexts[2].val.dimension.width, 135.0); - assert_eq!(contexts[2].val.dimension.margin.x, 10.); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [margin.x, margin.top_y], - }), - create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: second_context_id, - position: [167.0, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [25.75, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [192.75, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: fourth_context_id, - position: [196.75, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [196.75, 330.0], [27.75, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [224.5, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: third_context_id, - position: [228.5, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [228.5, 330.0], [67.5, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [296.0, margin.top_y], [1.0, 300.0]), - ] - ); - } - - #[test] - fn test_split_right_with_margin_inside_parent() { - let margin = Delta { - x: 20., - top_y: 30., - bottom_y: 40., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, _second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [margin.x, margin.top_y], - })] - ); - - let (third_context, _third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (fourth_context, _fourth_context_id) = { - let rich_text_id = 3; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (fifth_context, _fifth_context_id) = { - let rich_text_id = 3; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_right(second_context); - grid.select_prev_split(); - grid.split_down(third_context); - grid.split_right(fourth_context); - grid.split_right(fifth_context); - - // If the split right happens in not the last - // then should not update margin to half of x - - assert_eq!(grid.current_index(), 4); - - // |1.--------------|2.------------| - // |3.----|4.--|5.--|--------------| - let contexts = grid.contexts(); - assert_eq!(contexts.len(), 5); - assert_eq!(contexts[0].val.dimension.width, 286.); - assert_eq!(contexts[0].val.dimension.margin.x, 0.); - assert_eq!(contexts[1].val.dimension.width, 290.); - assert_eq!(contexts[1].val.dimension.margin.x, 10.); - assert_eq!(contexts[2].val.dimension.width, 129.0); - assert_eq!(contexts[2].val.dimension.margin.x, 0.); - assert_eq!(contexts[3].val.dimension.width, 52.5); - assert_eq!(contexts[3].val.dimension.margin.x, 0.); - assert_eq!(contexts[4].val.dimension.width, 56.5); - - // Fifth context should not have any margin x - // TODO: - // assert_eq!(contexts[4].val.dimension.margin.x, 0.); - - grid.remove_current(); - assert_eq!(grid.current_index(), 3); - let contexts = grid.contexts(); - assert_eq!(contexts[1].val.dimension.margin.x, 10.); - // Fourth context should not have any margin x - // TODO: - // assert_eq!(contexts[3].val.dimension.margin.x, 0.); - } - - #[test] - fn test_split_down_with_margin_inside_parent() { - let margin = Delta { - x: 20., - top_y: 30., - bottom_y: 40., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 1., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (third_context, third_context_id) = { - let rich_text_id = 3; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (fourth_context, fourth_context_id) = { - let rich_text_id = 4; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (fifth_context, fifth_context_id) = { - let rich_text_id = 5; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [margin.x, margin.top_y], - })] - ); - - grid.split_down(second_context); - grid.split_down(third_context); - grid.split_right(fourth_context); - grid.select_prev_split(); - grid.select_prev_split(); - let current_index = grid.current_index(); - let contexts = grid.contexts(); - assert_eq!(contexts[current_index].val.rich_text_id, second_context_id); - grid.split_right(fifth_context); - - // If the split right happens in not the last - // then should not update margin to half of x - - assert_eq!(grid.current_index(), 4); - - // |1.--------------| - // |2.------|5.-----| - // |3.------|4.-----| - let contexts = grid.contexts(); - assert_eq!(contexts.len(), 5); - - assert_eq!(contexts[0].val.rich_text_id, first_context_id); - assert_eq!(contexts[0].val.dimension.height, 298.); - assert_eq!(contexts[0].val.dimension.margin.top_y, 0.); - assert_eq!(contexts[0].val.dimension.margin.bottom_y, 0.); - let first_down = contexts[0].down; - assert_eq!(first_down, Some(1)); - assert_eq!( - contexts[first_down.unwrap_or_default()].val.rich_text_id, - second_context_id - ); - - assert_eq!(contexts[1].val.rich_text_id, second_context_id); - assert_eq!(contexts[1].val.dimension.height, 148.); - assert_eq!(contexts[1].val.dimension.margin.top_y, 0.); - assert_eq!(contexts[1].val.dimension.margin.bottom_y, 0.); - - assert_eq!(contexts[4].val.rich_text_id, fifth_context_id); - assert_eq!(contexts[4].val.dimension.height, 148.0); - assert_eq!(contexts[4].val.dimension.margin.top_y, 0.); - assert_eq!(contexts[4].val.dimension.margin.bottom_y, 0.); - - assert_eq!(contexts[2].val.rich_text_id, third_context_id); - assert_eq!(contexts[2].val.dimension.height, 150.0); - assert_eq!(contexts[2].val.dimension.margin.top_y, 0.); - assert_eq!(contexts[2].val.dimension.margin.bottom_y, 40.); - - assert_eq!(contexts[3].val.rich_text_id, fourth_context_id); - assert_eq!(contexts[3].val.dimension.height, 150.0); - assert_eq!(contexts[3].val.dimension.margin.top_y, 0.); - assert_eq!(contexts[3].val.dimension.margin.bottom_y, 40.); - - // Fifth context should not have any margin x - // TODO: Removal - // grid.remove_current(); - } - - #[test] - // https://github.com/raphamorim/rio/issues/760 - fn test_split_issue_760() { - let width = 1200.; - let height = 800.; - - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - width, - height, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 85); - assert_eq!(context_dimension.lines, 100); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 1., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - grid.split_down(second_context); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [0.0, 0.0], - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), - Object::RichText(RichText { - id: second_context_id, - position: [0.0, 202.0] - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), - create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), - create_border([0.0, 0.0, 1.0, 0.0], [600.0, 0.0], [1.0, 198.0]), - ] - ); - - let (third_context, third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.select_prev_split(); - assert_eq!(grid.current().rich_text_id, first_context_id); - assert_eq!(grid.current_index(), 0); - grid.split_right(third_context); - assert_eq!(grid.current().rich_text_id, third_context_id); - assert_eq!(grid.current_index(), 2); - - let contexts = grid.contexts(); - - let scaled_padding = PADDING * contexts[0].val.dimension.dimension.scale; - - // Check their respective width - assert_eq!( - contexts[0].val.dimension.width, - (width / 2.) - scaled_padding - ); - assert_eq!(contexts[1].val.dimension.width, width); - assert_eq!(contexts[2].val.dimension.width, width / 2.); - - // Check their respective height - let top_height = (height / 2.) - scaled_padding; - assert_eq!(contexts[0].val.dimension.height, top_height); - assert_eq!(contexts[1].val.dimension.height, height / 2.); - assert_eq!(contexts[2].val.dimension.height, top_height); - - // [RichText(RichText { id: 0, position: [0.0, 0.0] }), - // Rect(Rect { position: [298.0, 0.0], color: [0.0, 0.0, 1.0, 0.0], size: [1.0, 396.0] }), - // RichText(RichText { id: 2, position: [302.0, 0.0] }), - // Rect(Rect { position: [0.0, 198.0], color: [0.0, 0.0, 1.0, 0.0], size: [596.0, 1.0] }), - // RichText(RichText { id: 1, position: [0.0, 202.0] })] - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [0.0, 0.0], - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [298.0, 1.0]), - Object::RichText(RichText { - id: second_context_id, - position: [0.0, 202.0] - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), - create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), - create_border([0.0, 0.0, 1.0, 0.0], [298.0, 0.0], [1.0, 198.0]), - Object::RichText(RichText { - id: third_context_id, - position: [302.0, 0.0] - }), - create_border([0.0, 0.0, 1.0, 0.0], [302.0, 198.0], [300.0, 1.0]), - create_border([0.0, 0.0, 1.0, 0.0], [602.0, 0.0], [1.0, 198.0]), - ] - ); - } - - #[test] - fn test_remove_right_with_margin() { - let margin = Delta { - x: 20., - top_y: 30., - bottom_y: 40., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [margin.x, margin.top_y], - })] - ); - grid.split_right(second_context); - - let (third_context, third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (fourth_context, fourth_context_id) = { - let rich_text_id = 3; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_right(third_context); - - let first_expected_dimension = (286., 0.); - let second_expected_dimension = (131., 0.); - let third_expected_dimension = (135., 10.); - let contexts = grid.contexts(); - assert_eq!(contexts[0].val.dimension.width, first_expected_dimension.0); - assert_eq!( - contexts[0].val.dimension.margin.x, - first_expected_dimension.1 - ); - assert_eq!(contexts[1].val.dimension.width, second_expected_dimension.0); - assert_eq!( - contexts[1].val.dimension.margin.x, - second_expected_dimension.1 - ); - assert_eq!(contexts[2].val.dimension.width, third_expected_dimension.0); - assert_eq!( - contexts[2].val.dimension.margin.x, - third_expected_dimension.1 - ); - - grid.select_prev_split(); - grid.split_right(fourth_context); - - // If the split right happens in not the last - // then should not update margin to half of x - let contexts = grid.contexts(); - assert_eq!(contexts[0].val.dimension.width, 286.); - assert_eq!(contexts[0].val.dimension.margin.x, 0.); - assert_eq!(contexts[1].val.dimension.width, 51.5); - assert_eq!(contexts[1].val.dimension.margin.x, 0.); - assert_eq!(contexts[3].val.dimension.width, 55.5); - assert_eq!(contexts[3].val.dimension.margin.x, 0.); - - // 2 is the last one - assert_eq!(contexts[2].val.dimension.width, 135.0); - assert_eq!(contexts[2].val.dimension.margin.x, 10.); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [margin.x, margin.top_y], - }), - create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.], [143.0, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: second_context_id, - position: [167.0, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.], [25.75, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [192.75, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: fourth_context_id, - position: [196.75, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [196.75, 330.], [27.75, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [224.5, margin.top_y], [1.0, 300.0]), - Object::RichText(RichText { - id: third_context_id, - position: [228.5, margin.top_y] - }), - create_border([1.0, 0.0, 0.0, 0.0], [228.5, 330.], [67.5, 1.0]), - create_border([1.0, 0.0, 0.0, 0.0], [296.0, margin.top_y], [1.0, 300.0]), - ] - ); - - grid.remove_current(); - - // If the split right happens in not the last - // then should not update margin to half of x - let contexts = grid.contexts(); - assert_eq!(contexts[0].val.dimension.width, first_expected_dimension.0); - assert_eq!( - contexts[0].val.dimension.margin.x, - first_expected_dimension.1 - ); - assert_eq!(contexts[1].val.dimension.width, second_expected_dimension.0); - assert_eq!( - contexts[1].val.dimension.margin.x, - second_expected_dimension.1 - ); - assert_eq!(contexts[2].val.dimension.width, third_expected_dimension.0); - assert_eq!( - contexts[2].val.dimension.margin.x, - third_expected_dimension.1 - ); - - assert_eq!(grid.current_index(), 1); - grid.select_next_split(); - assert_eq!(grid.current_index(), 2); - - // Margin x should move to last - grid.remove_current(); - let contexts = grid.contexts(); - assert_eq!(contexts[0].val.dimension.width, 286.); - assert_eq!(contexts[0].val.dimension.margin.x, 0.); - assert_eq!(contexts[1].val.dimension.width, 290.); - assert_eq!(contexts[1].val.dimension.margin.x, 10.); - } - - #[test] - fn test_split_down() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 1200.0, - 800.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 85); - assert_eq!(context_dimension.lines, 100); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 1., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - grid.split_down(second_context); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [0.0, 0.0], - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), - Object::RichText(RichText { - id: second_context_id, - position: [0.0, 202.0] - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), - create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), - create_border([0.0, 0.0, 1.0, 0.0], [600.0, 0.0], [1.0, 198.0]), - ] - ); - - let (third_context, third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_down(third_context); - - assert_eq!( - grid.objects(), - vec![ - Object::RichText(RichText { - id: first_context_id, - position: [0.0, 0.0], - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), - Object::RichText(RichText { - id: second_context_id, - position: [0.0, 202.0] - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 300.0], [600.0, 1.0]), - Object::RichText(RichText { - id: third_context_id, - position: [0.0, 304.0] - }), - create_border([0.0, 0.0, 1.0, 0.0], [0.0, 404.0], [600.0, 1.0]), - create_border([0.0, 0.0, 1.0, 0.0], [600.0, 304.0], [1.0, 100.0]), - create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 98.0]), - create_border([0.0, 0.0, 1.0, 0.0], [600.0, 0.0], [1.0, 198.0]), - ] - ); - } - - #[test] - fn test_resize() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, _second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (third_context, _third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - grid.split_right(second_context); - grid.split_down(third_context); - - // assert_eq!( - // grid.objects(), - // vec![ - // Object::RichText(RichText { - // id: first_context_id, - // position: [0.0, 0.0], - // }), - // Object::Rect(Rect { - // position: [147.0, 0.0], - // color: [0.0, 0.0, 0.0, 0.0], - // size: [1.0, 300.0] - // }), - // Object::RichText(RichText { - // id: second_context_id, - // position: [149.0, 0.0] - // }), - // Object::Rect(Rect { - // position: [149.0, 147.0], - // color: [0.0, 0.0, 0.0, 0.0], - // size: [294.0, 1.0] - // }), - // Object::RichText(RichText { - // id: third_context_id, - // position: [149.0, 149.0] - // }), - // ] - // ); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - - grid.resize(1200.0, 600.0); - - // TODO: Finish test - } - - #[test] - fn test_remove_right_without_children() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, _second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - assert_eq!(grid.current().dimension.width, 600.); - - grid.split_right(second_context); - - let new_expected_width = 600. / 2.; - - assert_eq!(grid.current().dimension.width, new_expected_width); - assert_eq!(grid.current_index(), 1); - - grid.select_prev_split(); - let scaled_padding = PADDING * grid.current().dimension.dimension.scale; - let old_expected_width = (600. / 2.) - scaled_padding; - assert_eq!(grid.current().dimension.width, old_expected_width); - assert_eq!(grid.current_index(), 0); - - grid.select_next_split(); - assert_eq!(grid.current_index(), 1); - - grid.remove_current(); - - assert_eq!(grid.current_index(), 0); - // Whenever return to one should drop padding - assert_eq!(grid.current().dimension.width, 600.); - } - - #[test] - fn test_remove_right_with_children() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, _second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - grid.split_right(second_context); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - - let new_context_expected_width = 600. / 2.; - - assert_eq!(grid.current().dimension.width, new_context_expected_width); - assert_eq!(grid.current_index(), 1); - - grid.select_prev_split(); - - let scaled_padding = PADDING * grid.current().dimension.dimension.scale; - let old_context_expected_width = (600. / 2.) - scaled_padding; - assert_eq!(grid.current().dimension.width, old_context_expected_width); - assert_eq!(grid.current_index(), 0); - - let current_index = grid.current_index(); - assert_eq!(grid.contexts()[current_index].right, Some(1)); - assert_eq!(grid.contexts()[current_index].down, None); - - grid.remove_current(); - - assert_eq!(grid.current_index(), 0); - // Whenever return to one should drop padding - let expected_width = 600.; - assert_eq!(grid.current().dimension.width, expected_width); - - let current_index = grid.current_index(); - assert_eq!(grid.contexts()[current_index].right, None); - assert_eq!(grid.contexts()[current_index].down, None); - } - - #[test] - fn test_remove_right_with_down_children() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - grid.split_right(second_context); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - - let new_context_expected_width = 600. / 2.; - - assert_eq!(grid.current().dimension.width, new_context_expected_width); - assert_eq!(grid.current_index(), 1); - - let (third_context, third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_down(third_context); - assert_eq!(grid.current_index(), 2); - assert_eq!(grid.current().dimension.width, new_context_expected_width); - assert_eq!(grid.current().dimension.height, 300.); - - // Move back - grid.select_prev_split(); - - assert_eq!(grid.current_index(), 1); - assert_eq!(grid.current().rich_text_id, second_context_id); - assert_eq!(grid.current().dimension.width, new_context_expected_width); - assert_eq!(grid.current().dimension.height, 296.); - - // Remove the current should actually make right being down - grid.remove_current(); - - assert_eq!(grid.current_index(), 1); - assert_eq!(grid.current().rich_text_id, third_context_id); - assert_eq!(grid.current().dimension.width, new_context_expected_width); - assert_eq!(grid.current().dimension.height, 600.); - } - - #[test] - fn test_remove_down_without_children() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, _second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - assert_eq!(grid.current().dimension.width, 600.); - - grid.split_down(second_context); - - let new_expected_width = 600. / 2.; - - assert_eq!(grid.current().dimension.height, new_expected_width); - assert_eq!(grid.current_index(), 1); - - grid.select_prev_split(); - let scaled_padding = PADDING * grid.current().dimension.dimension.scale; - let old_expected_width = (600. / 2.) - scaled_padding; - assert_eq!(grid.current().dimension.height, old_expected_width); - assert_eq!(grid.current_index(), 0); - - grid.select_next_split(); - assert_eq!(grid.current_index(), 1); - - grid.remove_current(); - - assert_eq!(grid.current_index(), 0); - // Whenever return to one should drop padding - assert_eq!(grid.current().dimension.height, 600.); - } - - #[test] - fn test_remove_down_with_children() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, _second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - grid.split_down(second_context); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - - let new_context_expected_height = 600. / 2.; - - assert_eq!(grid.current().dimension.height, new_context_expected_height); - assert_eq!(grid.current_index(), 1); - - grid.select_prev_split(); - - let scaled_padding = PADDING * grid.current().dimension.dimension.scale; - let old_context_expected_height = (600. / 2.) - scaled_padding; - assert_eq!(grid.current().dimension.height, old_context_expected_height); - assert_eq!(grid.current_index(), 0); - - let current_index = grid.current_index(); - assert_eq!(grid.contexts()[current_index].down, Some(1)); - assert_eq!(grid.contexts()[current_index].right, None); - - grid.remove_current(); - - assert_eq!(grid.current_index(), 0); - // Whenever return to one should drop padding - let expected_height = 600.; - assert_eq!(grid.current().dimension.height, expected_height); - - let current_index = grid.current_index(); - assert_eq!(grid.contexts()[current_index].down, None); - assert_eq!(grid.contexts()[current_index].right, None); - } - - #[test] - fn test_remove_down_with_right_children() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - grid.split_down(second_context); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - - let new_context_expected_height = 600. / 2.; - - assert_eq!(grid.current().dimension.height, new_context_expected_height); - assert_eq!(grid.current_index(), 1); - - let (third_context, third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_right(third_context); - assert_eq!(grid.current_index(), 2); - assert_eq!(grid.current().dimension.width, new_context_expected_height); - assert_eq!(grid.current().dimension.height, 300.); - - // Move back - grid.select_prev_split(); - - assert_eq!(grid.current_index(), 1); - assert_eq!(grid.current().rich_text_id, second_context_id); - assert_eq!(grid.current().dimension.height, new_context_expected_height); - assert_eq!(grid.current().dimension.width, 296.); - - // Remove the current should actually make down being down - grid.remove_current(); - - assert_eq!(grid.current_index(), 1); - assert_eq!(grid.current().rich_text_id, third_context_id); - assert_eq!(grid.current().dimension.height, new_context_expected_height); - assert_eq!(grid.current().dimension.width, 600.); - } - - #[test] - fn test_remove_context_with_parent_but_down_children() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (third_context, third_context_id) = { - let rich_text_id = 3; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (fourth_context, fourth_context_id) = { - let rich_text_id = 4; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (fifth_context, fifth_context_id) = { - let rich_text_id = 5; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (sixth_context, sixth_context_id) = { - let rich_text_id = 6; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - // The test is to validate the removal of a context with parenting however - // should move to up the down items - // - // Test setup - // - // |1.-----|.3-----|4.-----| - // |2.-----|.5-|6.-|-------| - - grid.split_down(second_context); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - - let new_context_expected_height = 600. / 2.; - - assert_eq!(grid.current().dimension.height, new_context_expected_height); - assert_eq!(grid.current().rich_text_id, second_context_id); - assert_eq!(grid.current_index(), 1); - - grid.select_prev_split(); - assert_eq!(grid.current().rich_text_id, first_context_id); - - grid.split_right(third_context); - assert_eq!(grid.current().rich_text_id, third_context_id); - - grid.split_right(fourth_context); - assert_eq!(grid.current().rich_text_id, fourth_context_id); - - let current_index = grid.current_index(); - assert_eq!(current_index, 3); - assert_eq!(grid.contexts()[current_index].down, None); - - // So far we have: - // - // |1.-----|.3-----|4.-----| - // |2.-----|-------|-------| - - grid.select_prev_split(); - assert_eq!(grid.current().rich_text_id, third_context_id); - let current_index = grid.current_index(); - assert_eq!(current_index, 2); - assert_eq!(grid.contexts()[current_index].down, None); - - grid.split_down(fifth_context); - assert_eq!(grid.current().rich_text_id, fifth_context_id); - - grid.split_right(sixth_context); - assert_eq!(grid.current().rich_text_id, sixth_context_id); - - grid.select_prev_split(); - grid.select_prev_split(); - grid.select_prev_split(); - - assert_eq!(grid.current().rich_text_id, third_context_id); - - let current_index = grid.current_index(); - let right = grid.contexts()[current_index].right; - assert_eq!( - grid.contexts()[right.unwrap_or_default()].val.rich_text_id, - fourth_context_id - ); - let current_index = grid.current_index(); - let down = grid.contexts()[current_index].down; - assert_eq!( - grid.contexts()[down.unwrap_or_default()].val.rich_text_id, - fifth_context_id - ); - // Setup complete, now we have 3 as active as well - // - // |1.-----|.3-----|4.-----| - // |2.-----|.5-|6.-|-------| - // - // If we remove 3 then should be - // - // |1.-----|.5-|6.-|4.-----| - // |2.-----|---|---|-------| - - grid.remove_current(); - - // Check if current is 5 and next is 6 - assert_eq!(grid.current().rich_text_id, fifth_context_id); - let current_index = grid.current_index(); - let right = grid.contexts()[current_index].right; - assert_eq!( - grid.contexts()[right.unwrap_or_default()].val.rich_text_id, - sixth_context_id - ); - - // Let's go back to 1 to check if leads to 5 - grid.select_prev_split(); - grid.select_prev_split(); - grid.select_prev_split(); - - assert_eq!(grid.current().rich_text_id, first_context_id); - let current_index = grid.current_index(); - assert_eq!(current_index, 0); - let right = grid.contexts()[current_index].right; - assert_eq!(right, Some(3)); - assert_eq!( - grid.contexts()[right.unwrap_or_default()].val.rich_text_id, - fifth_context_id - ); - - // Let's go to 6 to check if leads to 4 - // - // |1.-----|.5-|6.-|4.-----| - // |2.-----|---|---|-------| - - grid.select_next_split(); - grid.select_next_split(); - grid.select_next_split(); - grid.select_next_split(); - - assert_eq!(grid.current().rich_text_id, sixth_context_id); - let current_index = grid.current_index(); - let right = grid.contexts()[current_index].right; - assert_eq!(right, Some(2)); - assert_eq!( - grid.contexts()[right.unwrap_or_default()].val.rich_text_id, - fourth_context_id - ); - } - - #[test] - fn test_remove_context_without_parents_but_with_right_and_down_children() { - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (third_context, third_context_id) = { - let rich_text_id = 3; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (fourth_context, fourth_context_id) = { - let rich_text_id = 4; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - grid.split_right(second_context); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - - let new_context_expected_width = 600. / 2.; - - assert_eq!(grid.current().dimension.width, new_context_expected_width); - assert_eq!(grid.current().rich_text_id, second_context_id); - assert_eq!(grid.current_index(), 1); - - grid.select_prev_split(); - grid.select_prev_split(); - assert_eq!(grid.current().rich_text_id, second_context_id); - - grid.select_prev_split(); - assert_eq!(grid.current().rich_text_id, first_context_id); - - grid.split_down(third_context); - assert_eq!(grid.current().rich_text_id, third_context_id); - assert_eq!(grid.current().dimension.width, 296.); - assert_eq!(grid.current().dimension.height, 300.); - - grid.select_prev_split(); - grid.select_prev_split(); - grid.select_prev_split(); - grid.select_prev_split(); - assert_eq!(grid.current().rich_text_id, second_context_id); - grid.split_down(fourth_context); - - assert_eq!(grid.current_index(), 3); - assert_eq!(grid.current().rich_text_id, fourth_context_id); - - grid.select_next_split(); - assert_eq!(grid.current_index(), 0); - assert_eq!(grid.current().rich_text_id, first_context_id); - - // Active is 1 - // |1.----|.2----| - // |3.----|.4----| - - // Remove the current should actually make right being down - grid.remove_current(); - let current_index = grid.current_index(); - // Move third context to first position - assert_eq!(current_index, 0); - assert_eq!(grid.current().rich_text_id, third_context_id); - let right = grid.contexts()[current_index].right; - let right_context = grid.contexts()[right.unwrap_or_default()].val.rich_text_id; - assert_eq!(right_context, second_context_id); - - // Result: - // |3.----|.2----| - // |------|.4----| - - // Now let's create a more complex case - // |3.---------|.2---------| - // |5.-|6.-|7.-|.4---------| - - let (fifth_context, fifth_context_id) = { - let rich_text_id = 5; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (sixth_context, sixth_context_id) = { - let rich_text_id = 6; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (seventh_context, seventh_context_id) = { - let rich_text_id = 7; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_down(fifth_context); - grid.split_right(sixth_context); - grid.split_right(seventh_context); - - assert_eq!(grid.current_index(), 5); - assert_eq!(grid.current().rich_text_id, seventh_context_id); - - // Current: - // |3.---------|.2---------| - // |5.-|6.-|7.-|.4---------| - // - // Now if we move back to 3. and remove it: - // Should move 5, 6 and 7 to top. - // - // |5.-|6.-|7.-|.2---------| - // |---|---|---|.4---------| - grid.select_next_split(); - assert_eq!(grid.current().rich_text_id, third_context_id); - let current_index = grid.current_index(); - let down = grid.contexts()[current_index].down; - assert_eq!( - grid.contexts()[down.unwrap_or_default()].val.rich_text_id, - fifth_context_id - ); - - grid.remove_current(); - assert_eq!(grid.current().rich_text_id, fifth_context_id); - - let current_index = grid.current_index(); - let right = grid.contexts()[current_index].right.unwrap_or_default(); - let right_context = &grid.contexts()[right]; - assert_eq!(right_context.val.rich_text_id, sixth_context_id); - - // Current: - // |5.-|6.-|7.-|.2---------| - // |---|---|---|.4---------| - - // Ok, let's test the reverse to right operations - // First remove 5 and 6 - - grid.remove_current(); - assert_eq!(grid.current().rich_text_id, sixth_context_id); - let current_index = grid.current_index(); - assert_eq!(grid.contexts()[current_index].down, None); - let right = grid.contexts()[current_index].right; - assert_eq!( - grid.contexts()[right.unwrap_or_default()].val.rich_text_id, - seventh_context_id - ); - - grid.remove_current(); - assert_eq!(grid.current().rich_text_id, seventh_context_id); - let right = grid.contexts()[current_index].right; - assert_eq!( - grid.contexts()[right.unwrap_or_default()].val.rich_text_id, - second_context_id - ); - - // Current: - // |7.---------|.2---------| - // |-----------|.4---------| - - // Now let's add many 5 and 6 as down items on 7th - // - // Should be: - // |7.---------|.2---------| - // |5.---------|.4---------| - // |6.---------|-----------| - - let (fifth_context, fifth_context_id) = { - let rich_text_id = 5; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (sixth_context, sixth_context_id) = { - let rich_text_id = 6; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_down(fifth_context); - grid.split_down(sixth_context); - - assert_eq!(grid.current().rich_text_id, sixth_context_id); - grid.select_prev_split(); - assert_eq!(grid.current().rich_text_id, fifth_context_id); - grid.select_prev_split(); - grid.select_prev_split(); - grid.select_prev_split(); - assert_eq!(grid.current().rich_text_id, seventh_context_id); - - // Next step remove 7 - // - // Should be: - // |5.---------|.2---------| - // |6.---------|.4---------| - // |-----------|-----------| - - grid.remove_current(); - assert_eq!(grid.current().rich_text_id, fifth_context_id); - let right = grid.contexts()[current_index].right; - let down = grid.contexts()[current_index].down; - assert_eq!( - grid.contexts()[right.unwrap_or_default()].val.rich_text_id, - second_context_id - ); - assert_eq!( - grid.contexts()[down.unwrap_or_default()].val.rich_text_id, - sixth_context_id - ); - - // Next step remove 5 - // - // Should be: - // |6.---------|.2---------| - // |-----------|.4---------| - // |-----------|-----------| - - grid.remove_current(); - assert_eq!(grid.current().rich_text_id, sixth_context_id); - let right = grid.contexts()[current_index].right; - assert_eq!( - grid.contexts()[right.unwrap_or_default()].val.rich_text_id, - second_context_id - ); - assert_eq!(grid.contexts()[current_index].down, None); - } - - #[test] - fn test_select_current_based_on_mouse() { - let mut mouse = Mouse::default(); - let margin = Delta { - x: 0., - top_y: 0., - bottom_y: 0., - }; - - let context_dimension = ContextDimension::build( - 600.0, - 600.0, - SugarDimensions { - scale: 2., - width: 14., - height: 8., - }, - 1.0, - Delta::::default(), - ); - - assert_eq!(context_dimension.columns, 42); - assert_eq!(context_dimension.lines, 75); - - let (first_context, first_context_id) = { - let rich_text_id = 0; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let (second_context, second_context_id) = { - let rich_text_id = 1; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - let mut grid = - ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); - - assert_eq!( - grid.objects(), - vec![Object::RichText(RichText { - id: first_context_id, - position: [0., 0.], - })] - ); - - grid.select_current_based_on_mouse(&mouse); - // On first should always return first item - assert_eq!(grid.current_index(), 0); - - grid.split_down(second_context); - - assert_eq!(grid.width, 600.0); - assert_eq!(grid.height, 600.0); - - let new_context_expected_height = 600. / 2.; - - assert_eq!(grid.current().dimension.height, new_context_expected_height); - assert_eq!(grid.current_index(), 1); - - let (third_context, third_context_id) = { - let rich_text_id = 2; - let route_id = 0; - ( - create_mock_context( - VoidListener {}, - WindowId::from(0), - route_id, - rich_text_id, - context_dimension, - ), - rich_text_id, - ) - }; - - grid.split_right(third_context); - assert_eq!(grid.current_index(), 2); - assert_eq!(grid.current().dimension.width, new_context_expected_height); - assert_eq!(grid.current().dimension.height, 300.); - - grid.select_current_based_on_mouse(&mouse); - assert_eq!(grid.current_index(), 0); - assert_eq!(grid.current().rich_text_id, 0); - - let scaled_padding = PADDING * grid.current().dimension.dimension.scale; - mouse.y = (new_context_expected_height + scaled_padding) as usize; - grid.select_current_based_on_mouse(&mouse); - - assert_eq!(grid.current_index(), 1); - assert_eq!(grid.current().rich_text_id, second_context_id); - - mouse.x = 304; - grid.select_current_based_on_mouse(&mouse); - - assert_eq!(grid.current_index(), 2); - assert_eq!(grid.current().rich_text_id, third_context_id); - } + // #[test] + // fn test_split_right() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 1200.0, + // 800.0, + // SugarDimensions { + // scale: 1., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 85); + // assert_eq!(context_dimension.lines, 100); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + // grid.split_right(second_context); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [0.0, 0.0], + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [0.0, 800.0], [598., 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [598.0, 0.0], [1.0, 800.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [600., 0.0] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [600.0, 800.0], [600.0, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [1200.0, 0.0], [1.0, 800.0]), + // ] + // ); + + // let (third_context, third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_right(third_context); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [0.0, 0.0], + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [0.0, 800.0], [598., 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [598.0, 0.0], [1.0, 800.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [600.0, 0.0] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [600.0, 800.0], [298.0, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [898.0, 0.0], [1.0, 800.0]), + // Object::RichText(RichText { + // id: third_context_id, + // position: [900.0, 0.0] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [900.0, 800.0], [300.0, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [1200.0, 0.0], [1.0, 800.0]), + // ] + // ); + // } + + // #[test] + // fn test_split_right_with_margin() { + // let margin = Delta { + // x: 20., + // top_y: 30., + // bottom_y: 40., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [margin.x, margin.top_y], + // })] + // ); + // grid.split_right(second_context); + + // /* + // > before split: + // 20 (600/20) + // |------| + + // Available width should compute with margin + // so should be 600 - 20 = 580, then will be: + // 289 + 4 (PADDING) + 290 + + // > after split: + // 10 (289/0) (4) (290/10) + // |----------|----------| + + // Margin should be splitted between first columns + // items and last columns items + // */ + + // let contexts = grid.contexts(); + // assert_eq!(contexts[0].val.dimension.width, 286.); + // assert_eq!(contexts[0].val.dimension.margin.x, 0.); + // assert_eq!(contexts[1].val.dimension.width, 290.); + // assert_eq!(contexts[1].val.dimension.margin.x, 10.); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [margin.x, margin.top_y], + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [167.0, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [145.0, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [312.0, margin.top_y], [1.0, 300.0]), + // ] + // ); + + // let (third_context, third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_right(third_context); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [margin.x, margin.top_y], + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [167.0, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [65.5, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [232.5, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: third_context_id, + // position: [236.5, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [236.5, 330.0], [67.5, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [304.0, margin.top_y], [1.0, 300.0]), + // ] + // ); + + // // Last context should be updated with half of x + // let contexts = grid.contexts(); + // assert_eq!(contexts[0].val.dimension.width, 286.); + // assert_eq!(contexts[0].val.dimension.margin.x, 0.); + // assert_eq!(contexts[1].val.dimension.width, 131.); + // assert_eq!(contexts[1].val.dimension.margin.x, 0.); + // assert_eq!(contexts[2].val.dimension.width, 135.); + // assert_eq!(contexts[2].val.dimension.margin.x, 10.); + + // let (fourth_context, fourth_context_id) = { + // let rich_text_id = 3; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.select_prev_split(); + // grid.split_right(fourth_context); + + // // If the split right happens in not the last + // // then should not update margin to half of x + // let contexts = grid.contexts(); + // assert_eq!(contexts[0].val.dimension.width, 286.); + // assert_eq!(contexts[0].val.dimension.margin.x, 0.); + // assert_eq!(contexts[1].val.dimension.width, 51.5); + // assert_eq!(contexts[1].val.dimension.margin.x, 0.); + // assert_eq!(contexts[3].val.dimension.width, 55.5); + // assert_eq!(contexts[3].val.dimension.margin.x, 0.); + + // // 2 is the last one + // assert_eq!(contexts[2].val.dimension.width, 135.0); + // assert_eq!(contexts[2].val.dimension.margin.x, 10.); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [margin.x, margin.top_y], + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.0], [143.0, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [167.0, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.0], [25.75, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [192.75, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: fourth_context_id, + // position: [196.75, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [196.75, 330.0], [27.75, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [224.5, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: third_context_id, + // position: [228.5, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [228.5, 330.0], [67.5, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [296.0, margin.top_y], [1.0, 300.0]), + // ] + // ); + // } + + // #[test] + // fn test_split_right_with_margin_inside_parent() { + // let margin = Delta { + // x: 20., + // top_y: 30., + // bottom_y: 40., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, _second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [margin.x, margin.top_y], + // })] + // ); + + // let (third_context, _third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (fourth_context, _fourth_context_id) = { + // let rich_text_id = 3; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (fifth_context, _fifth_context_id) = { + // let rich_text_id = 3; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_right(second_context); + // grid.select_prev_split(); + // grid.split_down(third_context); + // grid.split_right(fourth_context); + // grid.split_right(fifth_context); + + // // If the split right happens in not the last + // // then should not update margin to half of x + + // assert_eq!(grid.current_index(), 4); + + // // |1.--------------|2.------------| + // // |3.----|4.--|5.--|--------------| + // let contexts = grid.contexts(); + // assert_eq!(contexts.len(), 5); + // assert_eq!(contexts[0].val.dimension.width, 286.); + // assert_eq!(contexts[0].val.dimension.margin.x, 0.); + // assert_eq!(contexts[1].val.dimension.width, 290.); + // assert_eq!(contexts[1].val.dimension.margin.x, 10.); + // assert_eq!(contexts[2].val.dimension.width, 129.0); + // assert_eq!(contexts[2].val.dimension.margin.x, 0.); + // assert_eq!(contexts[3].val.dimension.width, 52.5); + // assert_eq!(contexts[3].val.dimension.margin.x, 0.); + // assert_eq!(contexts[4].val.dimension.width, 56.5); + + // // Fifth context should not have any margin x + // // TODO: + // // assert_eq!(contexts[4].val.dimension.margin.x, 0.); + + // grid.remove_current(); + // assert_eq!(grid.current_index(), 3); + // let contexts = grid.contexts(); + // assert_eq!(contexts[1].val.dimension.margin.x, 10.); + // // Fourth context should not have any margin x + // // TODO: + // // assert_eq!(contexts[3].val.dimension.margin.x, 0.); + // } + + // #[test] + // fn test_split_down_with_margin_inside_parent() { + // let margin = Delta { + // x: 20., + // top_y: 30., + // bottom_y: 40., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 1., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (third_context, third_context_id) = { + // let rich_text_id = 3; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (fourth_context, fourth_context_id) = { + // let rich_text_id = 4; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (fifth_context, fifth_context_id) = { + // let rich_text_id = 5; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [margin.x, margin.top_y], + // })] + // ); + + // grid.split_down(second_context); + // grid.split_down(third_context); + // grid.split_right(fourth_context); + // grid.select_prev_split(); + // grid.select_prev_split(); + // let current_index = grid.current_index(); + // let contexts = grid.contexts(); + // assert_eq!(contexts[current_index].val.rich_text_id, second_context_id); + // grid.split_right(fifth_context); + + // // If the split right happens in not the last + // // then should not update margin to half of x + + // assert_eq!(grid.current_index(), 4); + + // // |1.--------------| + // // |2.------|5.-----| + // // |3.------|4.-----| + // let contexts = grid.contexts(); + // assert_eq!(contexts.len(), 5); + + // assert_eq!(contexts[0].val.rich_text_id, first_context_id); + // assert_eq!(contexts[0].val.dimension.height, 298.); + // assert_eq!(contexts[0].val.dimension.margin.top_y, 0.); + // assert_eq!(contexts[0].val.dimension.margin.bottom_y, 0.); + // let first_down = contexts[0].down; + // assert_eq!(first_down, Some(1)); + // assert_eq!( + // contexts[first_down.unwrap_or_default()].val.rich_text_id, + // second_context_id + // ); + + // assert_eq!(contexts[1].val.rich_text_id, second_context_id); + // assert_eq!(contexts[1].val.dimension.height, 148.); + // assert_eq!(contexts[1].val.dimension.margin.top_y, 0.); + // assert_eq!(contexts[1].val.dimension.margin.bottom_y, 0.); + + // assert_eq!(contexts[4].val.rich_text_id, fifth_context_id); + // assert_eq!(contexts[4].val.dimension.height, 148.0); + // assert_eq!(contexts[4].val.dimension.margin.top_y, 0.); + // assert_eq!(contexts[4].val.dimension.margin.bottom_y, 0.); + + // assert_eq!(contexts[2].val.rich_text_id, third_context_id); + // assert_eq!(contexts[2].val.dimension.height, 150.0); + // assert_eq!(contexts[2].val.dimension.margin.top_y, 0.); + // assert_eq!(contexts[2].val.dimension.margin.bottom_y, 40.); + + // assert_eq!(contexts[3].val.rich_text_id, fourth_context_id); + // assert_eq!(contexts[3].val.dimension.height, 150.0); + // assert_eq!(contexts[3].val.dimension.margin.top_y, 0.); + // assert_eq!(contexts[3].val.dimension.margin.bottom_y, 40.); + + // // Fifth context should not have any margin x + // // TODO: Removal + // // grid.remove_current(); + // } + + // #[test] + // // https://github.com/raphamorim/rio/issues/760 + // fn test_split_issue_760() { + // let width = 1200.; + // let height = 800.; + + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // width, + // height, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 85); + // assert_eq!(context_dimension.lines, 100); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 1., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + // grid.split_down(second_context); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [0.0, 0.0], + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [0.0, 202.0] + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [600.0, 0.0], [1.0, 198.0]), + // ] + // ); + + // let (third_context, third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.select_prev_split(); + // assert_eq!(grid.current().rich_text_id, first_context_id); + // assert_eq!(grid.current_index(), 0); + // grid.split_right(third_context); + // assert_eq!(grid.current().rich_text_id, third_context_id); + // assert_eq!(grid.current_index(), 2); + + // let contexts = grid.contexts(); + + // let scaled_padding = PADDING * contexts[0].val.dimension.dimension.scale; + + // // Check their respective width + // assert_eq!( + // contexts[0].val.dimension.width, + // (width / 2.) - scaled_padding + // ); + // assert_eq!(contexts[1].val.dimension.width, width); + // assert_eq!(contexts[2].val.dimension.width, width / 2.); + + // // Check their respective height + // let top_height = (height / 2.) - scaled_padding; + // assert_eq!(contexts[0].val.dimension.height, top_height); + // assert_eq!(contexts[1].val.dimension.height, height / 2.); + // assert_eq!(contexts[2].val.dimension.height, top_height); + + // // [RichText(RichText { id: 0, position: [0.0, 0.0] }), + // // Rect(Rect { position: [298.0, 0.0], color: [0.0, 0.0, 1.0, 0.0], size: [1.0, 396.0] }), + // // RichText(RichText { id: 2, position: [302.0, 0.0] }), + // // Rect(Rect { position: [0.0, 198.0], color: [0.0, 0.0, 1.0, 0.0], size: [596.0, 1.0] }), + // // RichText(RichText { id: 1, position: [0.0, 202.0] })] + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [0.0, 0.0], + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [298.0, 1.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [0.0, 202.0] + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [298.0, 0.0], [1.0, 198.0]), + // Object::RichText(RichText { + // id: third_context_id, + // position: [302.0, 0.0] + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [302.0, 198.0], [300.0, 1.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [602.0, 0.0], [1.0, 198.0]), + // ] + // ); + // } + + // #[test] + // fn test_remove_right_with_margin() { + // let margin = Delta { + // x: 20., + // top_y: 30., + // bottom_y: 40., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [1., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [margin.x, margin.top_y], + // })] + // ); + // grid.split_right(second_context); + + // let (third_context, third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (fourth_context, fourth_context_id) = { + // let rich_text_id = 3; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_right(third_context); + + // let first_expected_dimension = (286., 0.); + // let second_expected_dimension = (131., 0.); + // let third_expected_dimension = (135., 10.); + // let contexts = grid.contexts(); + // assert_eq!(contexts[0].val.dimension.width, first_expected_dimension.0); + // assert_eq!( + // contexts[0].val.dimension.margin.x, + // first_expected_dimension.1 + // ); + // assert_eq!(contexts[1].val.dimension.width, second_expected_dimension.0); + // assert_eq!( + // contexts[1].val.dimension.margin.x, + // second_expected_dimension.1 + // ); + // assert_eq!(contexts[2].val.dimension.width, third_expected_dimension.0); + // assert_eq!( + // contexts[2].val.dimension.margin.x, + // third_expected_dimension.1 + // ); + + // grid.select_prev_split(); + // grid.split_right(fourth_context); + + // // If the split right happens in not the last + // // then should not update margin to half of x + // let contexts = grid.contexts(); + // assert_eq!(contexts[0].val.dimension.width, 286.); + // assert_eq!(contexts[0].val.dimension.margin.x, 0.); + // assert_eq!(contexts[1].val.dimension.width, 51.5); + // assert_eq!(contexts[1].val.dimension.margin.x, 0.); + // assert_eq!(contexts[3].val.dimension.width, 55.5); + // assert_eq!(contexts[3].val.dimension.margin.x, 0.); + + // // 2 is the last one + // assert_eq!(contexts[2].val.dimension.width, 135.0); + // assert_eq!(contexts[2].val.dimension.margin.x, 10.); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [margin.x, margin.top_y], + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [20.0, 330.], [143.0, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [163.0, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [167.0, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [167.0, 330.], [25.75, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [192.75, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: fourth_context_id, + // position: [196.75, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [196.75, 330.], [27.75, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [224.5, margin.top_y], [1.0, 300.0]), + // Object::RichText(RichText { + // id: third_context_id, + // position: [228.5, margin.top_y] + // }), + // create_border([1.0, 0.0, 0.0, 0.0], [228.5, 330.], [67.5, 1.0]), + // create_border([1.0, 0.0, 0.0, 0.0], [296.0, margin.top_y], [1.0, 300.0]), + // ] + // ); + + // grid.remove_current(); + + // // If the split right happens in not the last + // // then should not update margin to half of x + // let contexts = grid.contexts(); + // assert_eq!(contexts[0].val.dimension.width, first_expected_dimension.0); + // assert_eq!( + // contexts[0].val.dimension.margin.x, + // first_expected_dimension.1 + // ); + // assert_eq!(contexts[1].val.dimension.width, second_expected_dimension.0); + // assert_eq!( + // contexts[1].val.dimension.margin.x, + // second_expected_dimension.1 + // ); + // assert_eq!(contexts[2].val.dimension.width, third_expected_dimension.0); + // assert_eq!( + // contexts[2].val.dimension.margin.x, + // third_expected_dimension.1 + // ); + + // assert_eq!(grid.current_index(), 1); + // grid.select_next_split(); + // assert_eq!(grid.current_index(), 2); + + // // Margin x should move to last + // grid.remove_current(); + // let contexts = grid.contexts(); + // assert_eq!(contexts[0].val.dimension.width, 286.); + // assert_eq!(contexts[0].val.dimension.margin.x, 0.); + // assert_eq!(contexts[1].val.dimension.width, 290.); + // assert_eq!(contexts[1].val.dimension.margin.x, 10.); + // } + + // #[test] + // fn test_split_down() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 1200.0, + // 800.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 85); + // assert_eq!(context_dimension.lines, 100); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 1., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + // grid.split_down(second_context); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [0.0, 0.0], + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [0.0, 202.0] + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 402.0], [600.0, 1.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 200.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [600.0, 0.0], [1.0, 198.0]), + // ] + // ); + + // let (third_context, third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_down(third_context); + + // assert_eq!( + // grid.objects(), + // vec![ + // Object::RichText(RichText { + // id: first_context_id, + // position: [0.0, 0.0], + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 198.0], [600.0, 1.0]), + // Object::RichText(RichText { + // id: second_context_id, + // position: [0.0, 202.0] + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 300.0], [600.0, 1.0]), + // Object::RichText(RichText { + // id: third_context_id, + // position: [0.0, 304.0] + // }), + // create_border([0.0, 0.0, 1.0, 0.0], [0.0, 404.0], [600.0, 1.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [600.0, 304.0], [1.0, 100.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [600.0, 202.0], [1.0, 98.0]), + // create_border([0.0, 0.0, 1.0, 0.0], [600.0, 0.0], [1.0, 198.0]), + // ] + // ); + // } + + // #[test] + // fn test_resize() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, _second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (third_context, _third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // grid.split_right(second_context); + // grid.split_down(third_context); + + // // assert_eq!( + // // grid.objects(), + // // vec![ + // // Object::RichText(RichText { + // // id: first_context_id, + // // position: [0.0, 0.0], + // // }), + // // Object::Rect(Rect { + // // position: [147.0, 0.0], + // // color: [0.0, 0.0, 0.0, 0.0], + // // size: [1.0, 300.0] + // // }), + // // Object::RichText(RichText { + // // id: second_context_id, + // // position: [149.0, 0.0] + // // }), + // // Object::Rect(Rect { + // // position: [149.0, 147.0], + // // color: [0.0, 0.0, 0.0, 0.0], + // // size: [294.0, 1.0] + // // }), + // // Object::RichText(RichText { + // // id: third_context_id, + // // position: [149.0, 149.0] + // // }), + // // ] + // // ); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + + // grid.resize(1200.0, 600.0); + + // // TODO: Finish test + // } + + // #[test] + // fn test_remove_right_without_children() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, _second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + // assert_eq!(grid.current().dimension.width, 600.); + + // grid.split_right(second_context); + + // let new_expected_width = 600. / 2.; + + // assert_eq!(grid.current().dimension.width, new_expected_width); + // assert_eq!(grid.current_index(), 1); + + // grid.select_prev_split(); + // let scaled_padding = PADDING * grid.current().dimension.dimension.scale; + // let old_expected_width = (600. / 2.) - scaled_padding; + // assert_eq!(grid.current().dimension.width, old_expected_width); + // assert_eq!(grid.current_index(), 0); + + // grid.select_next_split(); + // assert_eq!(grid.current_index(), 1); + + // grid.remove_current(); + + // assert_eq!(grid.current_index(), 0); + // // Whenever return to one should drop padding + // assert_eq!(grid.current().dimension.width, 600.); + // } + + // #[test] + // fn test_remove_right_with_children() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, _second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // grid.split_right(second_context); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + + // let new_context_expected_width = 600. / 2.; + + // assert_eq!(grid.current().dimension.width, new_context_expected_width); + // assert_eq!(grid.current_index(), 1); + + // grid.select_prev_split(); + + // let scaled_padding = PADDING * grid.current().dimension.dimension.scale; + // let old_context_expected_width = (600. / 2.) - scaled_padding; + // assert_eq!(grid.current().dimension.width, old_context_expected_width); + // assert_eq!(grid.current_index(), 0); + + // let current_index = grid.current_index(); + // assert_eq!(grid.contexts()[current_index].right, Some(1)); + // assert_eq!(grid.contexts()[current_index].down, None); + + // grid.remove_current(); + + // assert_eq!(grid.current_index(), 0); + // // Whenever return to one should drop padding + // let expected_width = 600.; + // assert_eq!(grid.current().dimension.width, expected_width); + + // let current_index = grid.current_index(); + // assert_eq!(grid.contexts()[current_index].right, None); + // assert_eq!(grid.contexts()[current_index].down, None); + // } + + // #[test] + // fn test_remove_right_with_down_children() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // grid.split_right(second_context); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + + // let new_context_expected_width = 600. / 2.; + + // assert_eq!(grid.current().dimension.width, new_context_expected_width); + // assert_eq!(grid.current_index(), 1); + + // let (third_context, third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_down(third_context); + // assert_eq!(grid.current_index(), 2); + // assert_eq!(grid.current().dimension.width, new_context_expected_width); + // assert_eq!(grid.current().dimension.height, 300.); + + // // Move back + // grid.select_prev_split(); + + // assert_eq!(grid.current_index(), 1); + // assert_eq!(grid.current().rich_text_id, second_context_id); + // assert_eq!(grid.current().dimension.width, new_context_expected_width); + // assert_eq!(grid.current().dimension.height, 296.); + + // // Remove the current should actually make right being down + // grid.remove_current(); + + // assert_eq!(grid.current_index(), 1); + // assert_eq!(grid.current().rich_text_id, third_context_id); + // assert_eq!(grid.current().dimension.width, new_context_expected_width); + // assert_eq!(grid.current().dimension.height, 600.); + // } + + // #[test] + // fn test_remove_down_without_children() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, _second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + // assert_eq!(grid.current().dimension.width, 600.); + + // grid.split_down(second_context); + + // let new_expected_width = 600. / 2.; + + // assert_eq!(grid.current().dimension.height, new_expected_width); + // assert_eq!(grid.current_index(), 1); + + // grid.select_prev_split(); + // let scaled_padding = PADDING * grid.current().dimension.dimension.scale; + // let old_expected_width = (600. / 2.) - scaled_padding; + // assert_eq!(grid.current().dimension.height, old_expected_width); + // assert_eq!(grid.current_index(), 0); + + // grid.select_next_split(); + // assert_eq!(grid.current_index(), 1); + + // grid.remove_current(); + + // assert_eq!(grid.current_index(), 0); + // // Whenever return to one should drop padding + // assert_eq!(grid.current().dimension.height, 600.); + // } + + // #[test] + // fn test_remove_down_with_children() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, _second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // grid.split_down(second_context); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + + // let new_context_expected_height = 600. / 2.; + + // assert_eq!(grid.current().dimension.height, new_context_expected_height); + // assert_eq!(grid.current_index(), 1); + + // grid.select_prev_split(); + + // let scaled_padding = PADDING * grid.current().dimension.dimension.scale; + // let old_context_expected_height = (600. / 2.) - scaled_padding; + // assert_eq!(grid.current().dimension.height, old_context_expected_height); + // assert_eq!(grid.current_index(), 0); + + // let current_index = grid.current_index(); + // assert_eq!(grid.contexts()[current_index].down, Some(1)); + // assert_eq!(grid.contexts()[current_index].right, None); + + // grid.remove_current(); + + // assert_eq!(grid.current_index(), 0); + // // Whenever return to one should drop padding + // let expected_height = 600.; + // assert_eq!(grid.current().dimension.height, expected_height); + + // let current_index = grid.current_index(); + // assert_eq!(grid.contexts()[current_index].down, None); + // assert_eq!(grid.contexts()[current_index].right, None); + // } + + // #[test] + // fn test_remove_down_with_right_children() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // grid.split_down(second_context); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + + // let new_context_expected_height = 600. / 2.; + + // assert_eq!(grid.current().dimension.height, new_context_expected_height); + // assert_eq!(grid.current_index(), 1); + + // let (third_context, third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_right(third_context); + // assert_eq!(grid.current_index(), 2); + // assert_eq!(grid.current().dimension.width, new_context_expected_height); + // assert_eq!(grid.current().dimension.height, 300.); + + // // Move back + // grid.select_prev_split(); + + // assert_eq!(grid.current_index(), 1); + // assert_eq!(grid.current().rich_text_id, second_context_id); + // assert_eq!(grid.current().dimension.height, new_context_expected_height); + // assert_eq!(grid.current().dimension.width, 296.); + + // // Remove the current should actually make down being down + // grid.remove_current(); + + // assert_eq!(grid.current_index(), 1); + // assert_eq!(grid.current().rich_text_id, third_context_id); + // assert_eq!(grid.current().dimension.height, new_context_expected_height); + // assert_eq!(grid.current().dimension.width, 600.); + // } + + // #[test] + // fn test_remove_context_with_parent_but_down_children() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (third_context, third_context_id) = { + // let rich_text_id = 3; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (fourth_context, fourth_context_id) = { + // let rich_text_id = 4; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (fifth_context, fifth_context_id) = { + // let rich_text_id = 5; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (sixth_context, sixth_context_id) = { + // let rich_text_id = 6; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // // The test is to validate the removal of a context with parenting however + // // should move to up the down items + // // + // // Test setup + // // + // // |1.-----|.3-----|4.-----| + // // |2.-----|.5-|6.-|-------| + + // grid.split_down(second_context); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + + // let new_context_expected_height = 600. / 2.; + + // assert_eq!(grid.current().dimension.height, new_context_expected_height); + // assert_eq!(grid.current().rich_text_id, second_context_id); + // assert_eq!(grid.current_index(), 1); + + // grid.select_prev_split(); + // assert_eq!(grid.current().rich_text_id, first_context_id); + + // grid.split_right(third_context); + // assert_eq!(grid.current().rich_text_id, third_context_id); + + // grid.split_right(fourth_context); + // assert_eq!(grid.current().rich_text_id, fourth_context_id); + + // let current_index = grid.current_index(); + // assert_eq!(current_index, 3); + // assert_eq!(grid.contexts()[current_index].down, None); + + // // So far we have: + // // + // // |1.-----|.3-----|4.-----| + // // |2.-----|-------|-------| + + // grid.select_prev_split(); + // assert_eq!(grid.current().rich_text_id, third_context_id); + // let current_index = grid.current_index(); + // assert_eq!(current_index, 2); + // assert_eq!(grid.contexts()[current_index].down, None); + + // grid.split_down(fifth_context); + // assert_eq!(grid.current().rich_text_id, fifth_context_id); + + // grid.split_right(sixth_context); + // assert_eq!(grid.current().rich_text_id, sixth_context_id); + + // grid.select_prev_split(); + // grid.select_prev_split(); + // grid.select_prev_split(); + + // assert_eq!(grid.current().rich_text_id, third_context_id); + + // let current_index = grid.current_index(); + // let right = grid.contexts()[current_index].right; + // assert_eq!( + // grid.contexts()[right.unwrap_or_default()].val.rich_text_id, + // fourth_context_id + // ); + // let current_index = grid.current_index(); + // let down = grid.contexts()[current_index].down; + // assert_eq!( + // grid.contexts()[down.unwrap_or_default()].val.rich_text_id, + // fifth_context_id + // ); + // // Setup complete, now we have 3 as active as well + // // + // // |1.-----|.3-----|4.-----| + // // |2.-----|.5-|6.-|-------| + // // + // // If we remove 3 then should be + // // + // // |1.-----|.5-|6.-|4.-----| + // // |2.-----|---|---|-------| + + // grid.remove_current(); + + // // Check if current is 5 and next is 6 + // assert_eq!(grid.current().rich_text_id, fifth_context_id); + // let current_index = grid.current_index(); + // let right = grid.contexts()[current_index].right; + // assert_eq!( + // grid.contexts()[right.unwrap_or_default()].val.rich_text_id, + // sixth_context_id + // ); + + // // Let's go back to 1 to check if leads to 5 + // grid.select_prev_split(); + // grid.select_prev_split(); + // grid.select_prev_split(); + + // assert_eq!(grid.current().rich_text_id, first_context_id); + // let current_index = grid.current_index(); + // assert_eq!(current_index, 0); + // let right = grid.contexts()[current_index].right; + // assert_eq!(right, Some(3)); + // assert_eq!( + // grid.contexts()[right.unwrap_or_default()].val.rich_text_id, + // fifth_context_id + // ); + + // // Let's go to 6 to check if leads to 4 + // // + // // |1.-----|.5-|6.-|4.-----| + // // |2.-----|---|---|-------| + + // grid.select_next_split(); + // grid.select_next_split(); + // grid.select_next_split(); + // grid.select_next_split(); + + // assert_eq!(grid.current().rich_text_id, sixth_context_id); + // let current_index = grid.current_index(); + // let right = grid.contexts()[current_index].right; + // assert_eq!(right, Some(2)); + // assert_eq!( + // grid.contexts()[right.unwrap_or_default()].val.rich_text_id, + // fourth_context_id + // ); + // } + + // #[test] + // fn test_remove_context_without_parents_but_with_right_and_down_children() { + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (third_context, third_context_id) = { + // let rich_text_id = 3; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (fourth_context, fourth_context_id) = { + // let rich_text_id = 4; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // grid.split_right(second_context); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + + // let new_context_expected_width = 600. / 2.; + + // assert_eq!(grid.current().dimension.width, new_context_expected_width); + // assert_eq!(grid.current().rich_text_id, second_context_id); + // assert_eq!(grid.current_index(), 1); + + // grid.select_prev_split(); + // grid.select_prev_split(); + // assert_eq!(grid.current().rich_text_id, second_context_id); + + // grid.select_prev_split(); + // assert_eq!(grid.current().rich_text_id, first_context_id); + + // grid.split_down(third_context); + // assert_eq!(grid.current().rich_text_id, third_context_id); + // assert_eq!(grid.current().dimension.width, 296.); + // assert_eq!(grid.current().dimension.height, 300.); + + // grid.select_prev_split(); + // grid.select_prev_split(); + // grid.select_prev_split(); + // grid.select_prev_split(); + // assert_eq!(grid.current().rich_text_id, second_context_id); + // grid.split_down(fourth_context); + + // assert_eq!(grid.current_index(), 3); + // assert_eq!(grid.current().rich_text_id, fourth_context_id); + + // grid.select_next_split(); + // assert_eq!(grid.current_index(), 0); + // assert_eq!(grid.current().rich_text_id, first_context_id); + + // // Active is 1 + // // |1.----|.2----| + // // |3.----|.4----| + + // // Remove the current should actually make right being down + // grid.remove_current(); + // let current_index = grid.current_index(); + // // Move third context to first position + // assert_eq!(current_index, 0); + // assert_eq!(grid.current().rich_text_id, third_context_id); + // let right = grid.contexts()[current_index].right; + // let right_context = grid.contexts()[right.unwrap_or_default()].val.rich_text_id; + // assert_eq!(right_context, second_context_id); + + // // Result: + // // |3.----|.2----| + // // |------|.4----| + + // // Now let's create a more complex case + // // |3.---------|.2---------| + // // |5.-|6.-|7.-|.4---------| + + // let (fifth_context, fifth_context_id) = { + // let rich_text_id = 5; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (sixth_context, sixth_context_id) = { + // let rich_text_id = 6; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (seventh_context, seventh_context_id) = { + // let rich_text_id = 7; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_down(fifth_context); + // grid.split_right(sixth_context); + // grid.split_right(seventh_context); + + // assert_eq!(grid.current_index(), 5); + // assert_eq!(grid.current().rich_text_id, seventh_context_id); + + // // Current: + // // |3.---------|.2---------| + // // |5.-|6.-|7.-|.4---------| + // // + // // Now if we move back to 3. and remove it: + // // Should move 5, 6 and 7 to top. + // // + // // |5.-|6.-|7.-|.2---------| + // // |---|---|---|.4---------| + // grid.select_next_split(); + // assert_eq!(grid.current().rich_text_id, third_context_id); + // let current_index = grid.current_index(); + // let down = grid.contexts()[current_index].down; + // assert_eq!( + // grid.contexts()[down.unwrap_or_default()].val.rich_text_id, + // fifth_context_id + // ); + + // grid.remove_current(); + // assert_eq!(grid.current().rich_text_id, fifth_context_id); + + // let current_index = grid.current_index(); + // let right = grid.contexts()[current_index].right.unwrap_or_default(); + // let right_context = &grid.contexts()[right]; + // assert_eq!(right_context.val.rich_text_id, sixth_context_id); + + // // Current: + // // |5.-|6.-|7.-|.2---------| + // // |---|---|---|.4---------| + + // // Ok, let's test the reverse to right operations + // // First remove 5 and 6 + + // grid.remove_current(); + // assert_eq!(grid.current().rich_text_id, sixth_context_id); + // let current_index = grid.current_index(); + // assert_eq!(grid.contexts()[current_index].down, None); + // let right = grid.contexts()[current_index].right; + // assert_eq!( + // grid.contexts()[right.unwrap_or_default()].val.rich_text_id, + // seventh_context_id + // ); + + // grid.remove_current(); + // assert_eq!(grid.current().rich_text_id, seventh_context_id); + // let right = grid.contexts()[current_index].right; + // assert_eq!( + // grid.contexts()[right.unwrap_or_default()].val.rich_text_id, + // second_context_id + // ); + + // // Current: + // // |7.---------|.2---------| + // // |-----------|.4---------| + + // // Now let's add many 5 and 6 as down items on 7th + // // + // // Should be: + // // |7.---------|.2---------| + // // |5.---------|.4---------| + // // |6.---------|-----------| + + // let (fifth_context, fifth_context_id) = { + // let rich_text_id = 5; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (sixth_context, sixth_context_id) = { + // let rich_text_id = 6; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_down(fifth_context); + // grid.split_down(sixth_context); + + // assert_eq!(grid.current().rich_text_id, sixth_context_id); + // grid.select_prev_split(); + // assert_eq!(grid.current().rich_text_id, fifth_context_id); + // grid.select_prev_split(); + // grid.select_prev_split(); + // grid.select_prev_split(); + // assert_eq!(grid.current().rich_text_id, seventh_context_id); + + // // Next step remove 7 + // // + // // Should be: + // // |5.---------|.2---------| + // // |6.---------|.4---------| + // // |-----------|-----------| + + // grid.remove_current(); + // assert_eq!(grid.current().rich_text_id, fifth_context_id); + // let right = grid.contexts()[current_index].right; + // let down = grid.contexts()[current_index].down; + // assert_eq!( + // grid.contexts()[right.unwrap_or_default()].val.rich_text_id, + // second_context_id + // ); + // assert_eq!( + // grid.contexts()[down.unwrap_or_default()].val.rich_text_id, + // sixth_context_id + // ); + + // // Next step remove 5 + // // + // // Should be: + // // |6.---------|.2---------| + // // |-----------|.4---------| + // // |-----------|-----------| + + // grid.remove_current(); + // assert_eq!(grid.current().rich_text_id, sixth_context_id); + // let right = grid.contexts()[current_index].right; + // assert_eq!( + // grid.contexts()[right.unwrap_or_default()].val.rich_text_id, + // second_context_id + // ); + // assert_eq!(grid.contexts()[current_index].down, None); + // } + + // #[test] + // fn test_select_current_based_on_mouse() { + // let mut mouse = Mouse::default(); + // let margin = Delta { + // x: 0., + // top_y: 0., + // bottom_y: 0., + // }; + + // let context_dimension = ContextDimension::build( + // 600.0, + // 600.0, + // SugarDimensions { + // scale: 2., + // width: 14., + // height: 8., + // }, + // 1.0, + // Delta::::default(), + // ); + + // assert_eq!(context_dimension.columns, 42); + // assert_eq!(context_dimension.lines, 75); + + // let (first_context, first_context_id) = { + // let rich_text_id = 0; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let (second_context, second_context_id) = { + // let rich_text_id = 1; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // let mut grid = + // ContextGrid::::new(first_context, margin, [0., 0., 0., 0.]); + + // assert_eq!( + // grid.objects(), + // vec![Object::RichText(RichText { + // id: first_context_id, + // position: [0., 0.], + // })] + // ); + + // grid.select_current_based_on_mouse(&mouse); + // // On first should always return first item + // assert_eq!(grid.current_index(), 0); + + // grid.split_down(second_context); + + // assert_eq!(grid.width, 600.0); + // assert_eq!(grid.height, 600.0); + + // let new_context_expected_height = 600. / 2.; + + // assert_eq!(grid.current().dimension.height, new_context_expected_height); + // assert_eq!(grid.current_index(), 1); + + // let (third_context, third_context_id) = { + // let rich_text_id = 2; + // let route_id = 0; + // ( + // create_mock_context( + // VoidListener {}, + // WindowId::from(0), + // route_id, + // rich_text_id, + // context_dimension, + // ), + // rich_text_id, + // ) + // }; + + // grid.split_right(third_context); + // assert_eq!(grid.current_index(), 2); + // assert_eq!(grid.current().dimension.width, new_context_expected_height); + // assert_eq!(grid.current().dimension.height, 300.); + + // grid.select_current_based_on_mouse(&mouse); + // assert_eq!(grid.current_index(), 0); + // assert_eq!(grid.current().rich_text_id, 0); + + // let scaled_padding = PADDING * grid.current().dimension.dimension.scale; + // mouse.y = (new_context_expected_height + scaled_padding) as usize; + // grid.select_current_based_on_mouse(&mouse); + + // assert_eq!(grid.current_index(), 1); + // assert_eq!(grid.current().rich_text_id, second_context_id); + + // mouse.x = 304; + // grid.select_current_based_on_mouse(&mouse); + + // assert_eq!(grid.current_index(), 2); + // assert_eq!(grid.current().rich_text_id, third_context_id); + // } }