Skip to content

Commit

Permalink
ListView: fix default height of items
Browse files Browse the repository at this point in the history
  • Loading branch information
ogoffart committed Jul 22, 2021
1 parent a6d3b11 commit ff8f793
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions sixtyfps_compiler/builtins.60
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ export NativeScrollView := _ {
property <length> native_padding_right: native_output;
property <length> native_padding_top: native_output;
property <length> native_padding_bottom: native_output;
//-default_size_binding:expands_to_parent_geometry
//-is_internal
}

Expand Down
10 changes: 9 additions & 1 deletion sixtyfps_compiler/passes/repeater_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LICENSE END */
Make sure that the Repeated expression are just components without any children
*/

use crate::expression_tree::NamedReference;
use crate::expression_tree::{Expression, NamedReference};
use crate::langtype::Type;
use crate::object_tree::*;
use std::cell::RefCell;
Expand Down Expand Up @@ -55,6 +55,14 @@ fn create_repeater_components(component: &Rc<Component>) {
..Component::default()
});

if !comp.root_element.borrow().bindings.contains_key("height") {
let preferred = Expression::PropertyReference(NamedReference::new(
&comp.root_element,
"preferred_height",
));
comp.root_element.borrow_mut().bindings.insert("height".into(), preferred.into());
}

let weak = Rc::downgrade(&comp);
recurse_elem(&comp.root_element, &(), &mut |e, _| {
e.borrow_mut().enclosing_component = weak.clone()
Expand Down
65 changes: 65 additions & 0 deletions tests/cases/elements/listview.60
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2021 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2021 Simon Hausmann <simon.hausmann@sixtyfps.io>

SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */

import { ListView } from "sixtyfps_widgets.60";

TestCase := Window {
width: 400px;
height: 540px;

property <string> value;

listview := ListView {
for data in [
{ text: "Blue", color: #0000ff, bg: #eeeeee},
{ text: "Red", color: #ff0000, bg: #eeeeee},
{ text: "Green", color: #00ff00, bg: #eeeeee},
{ text: "Yellow", color: #ffff00, bg: #222222 },
{ text: "Black", color: #000000, bg: #eeeeee },
{ text: "White", color: #ffffff, bg: #222222 },
{ text: "Magenta", color: #ff00ff, bg: #eeeeee },
{ text: "Cyan", color: #00ffff, bg: #222222 },
] : delegate := Rectangle {
background: @linear-gradient(90deg, data.bg,data.bg.brighter(0.5));
width: 100%; // FIXME shouldn't be needed
HorizontalLayout {
text_Name := Text {
height: 100px;
text: data.text;
color: data.color;
font_size: 20px ;
}
}
TouchArea { clicked => { value = data.text; } }
}
}
}

/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
sixtyfps::testing::send_mouse_click(&instance, 5., 205.);
assert_eq(instance.get_value(), "Green");
```

```rust
let instance = TestCase::new();
sixtyfps::testing::send_mouse_click(&instance, 5., 205.);
assert_eq!(instance.get_value(), "Green");
```

```js
var instance = new sixtyfps.TestCase();
instance.send_mouse_click(5., 205.);
assert.equal(instance.value, "Green");
```

*/

0 comments on commit ff8f793

Please sign in to comment.