-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Component Group View with static header and without icons #3373
Changes from 129 commits
60ce484
9e7ff75
91fb726
eb8606d
b1d5ef9
6baab5e
06f1ec7
2d9daef
d680f66
3977a59
5a2db45
3785ab8
9dbd3bc
4fead21
b6e36db
66b0069
caecd7b
a9382bd
e79a3de
9373fa8
c3ef542
8b0475e
5a42e8a
349fd8b
d475a92
338d1eb
08cd066
fb23962
49b8442
ed123bb
8e3ecd6
c6a2cce
18fd311
a7ca8c2
b7324f2
8f5c4b4
df31d31
24d277f
fe27711
aeca296
61971f8
6eb7476
cc87551
8e60d5f
381249d
2db798d
f4294ea
cb07cee
28416d4
cf06630
bb13896
5162f67
0acd66a
17bba18
8a2faed
8b8260a
78b6a75
a61ebe5
0cd89e9
b9fb33a
544c3ad
0e5f89d
f02de48
16fc80c
2ad4c2a
22eed46
1a2ce68
edaf6ee
be3afdf
678b180
4bbe73d
fb41ef1
f75c082
8a516cc
ee0739f
7e03d97
b6d3fe4
5ecddba
64d68d1
540de0a
7d73016
ce840c9
68d05aa
64db7c5
4209782
f87fe82
2bced50
15a0a3e
9bbb9b4
4001a37
e5ea02f
ab1f6bb
65dd4fc
1413ced
048cfd8
aa892f6
9c374f5
1ede1fa
6a683d0
60622a1
f3c2409
b4d1508
be4f01f
ab2b98d
2cb584b
2e90072
fc20bcf
e859e5c
9c485ab
68fb971
51c722c
a622ed4
5c2cb86
ad33d98
9a4a203
3eb469e
1786520
ea2f9f0
0a963b7
3e2ea92
32e80ec
8775396
35744df
2c6a604
e1d3ac0
7b5fe8f
a26d544
5ce05c6
1054e3f
4760977
39def4b
363eaa9
ef406c1
017fdb1
4b135af
aa043dc
6df9b78
74c94d0
284466e
dd8c60c
2f7e90e
1efcf7f
d3465c9
4469aeb
57d0830
5c04403
4f386d2
cd3490c
766c16b
bf2f9ea
bd0f655
7d706d7
74d8280
2f456f4
61b546b
bc33013
8f2fc4a
d0a13e3
8046891
1be87d2
bd0abc0
e19329c
33ecb43
0a191c8
3930773
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "ide-view-component-browser" | ||
version = "0.1.0" | ||
authors = ["Enso Team <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
ide-view-component-group = { path = "component-group-view" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "ide-view-component-group" | ||
version = "0.1.0" | ||
authors = ["Enso Team <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
enso-frp = { version = "0.1.0", path = "../../../../../lib/rust/frp" } | ||
ensogl-core = { version = "0.1.0", path = "../../../../../lib/rust/ensogl/core" } | ||
ensogl-gui-component = { version = "0.1.0", path = "../../../../../lib/rust/ensogl/component/gui" } | ||
ensogl-hardcoded-theme = { version = "0.1.0", path = "../../../../../lib/rust/ensogl/app/theme/hardcoded" } | ||
ensogl-list-view = { version = "0.1.0", path = "../../../../../lib/rust/ensogl/component/list-view" } | ||
ensogl-text = { version = "0.1.0", path = "../../../../../lib/rust/ensogl/component/text" } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
//! An EnsoGL implementation of a Component Group View. | ||
//! | ||
//! A Component Group View is displayed as a header (containing the name of a group of Enso | ||
//! components) and a list of entries below it (names of the components belonging to that group). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We try not to repeat the names in the docs. The names such as "Enso" or "EnsoGL" do not have to appear here. It makes it easier in the future to refactor these names. Also:
|
||
|
||
#![recursion_limit = "512"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this needed? |
||
// === Standard Linter Configuration === | ||
#![deny(non_ascii_idents)] | ||
#![warn(unsafe_code)] | ||
// === Non-Standard Linter Configuration === | ||
#![warn(missing_copy_implementations)] | ||
#![warn(missing_debug_implementations)] | ||
#![warn(missing_docs)] | ||
#![warn(trivial_casts)] | ||
#![warn(trivial_numeric_casts)] | ||
#![warn(unused_import_braces)] | ||
#![warn(unused_qualifications)] | ||
|
||
use ensogl_core::prelude::*; | ||
|
||
use enso_frp as frp; | ||
use ensogl_core::application::Application; | ||
use ensogl_core::data::color::Rgba; | ||
use ensogl_core::display; | ||
use ensogl_core::display::shape::*; | ||
use ensogl_gui_component::component; | ||
use ensogl_gui_component::component::ComponentView; | ||
use ensogl_hardcoded_theme::application::component_browser::component_group as theme; | ||
use ensogl_list_view as list_view; | ||
use ensogl_list_view::entry; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of too many imports, you should use |
||
use ensogl_list_view::ListView; | ||
use ensogl_text as text; | ||
|
||
|
||
|
||
// ========================== | ||
// === Shapes Definitions === | ||
// ========================== | ||
|
||
|
||
// === Background === | ||
|
||
/// The background of the Component Group View. | ||
pub mod background { | ||
use super::*; | ||
|
||
ensogl_core::define_shape_system! { | ||
below = [list_view::background]; | ||
(style:Style, color:Vector4) { | ||
let sprite_width: Var<Pixels> = "input_size.x".into(); | ||
let sprite_height: Var<Pixels> = "input_size.y".into(); | ||
let color = Var::<Rgba>::from(color); | ||
let shape = Rect((&sprite_width, &sprite_height)).fill(color); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is just a rect with not rounded corners, why dont you use plane instead? Plane is faster to render There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason I don't understand, changing this line to use Plane instead: let shape = Plane().fill(color); results in the component rendering with wrong colors - specifically, the color behind the ListView is correct, but the one in the header area is not: Would you have some idea or hint as to what could be the reason for this? I checked what will happen if I use pub fn shape() -> AnyShape {
let shape = Plane().fill(color::Rgba(0.927, 0.937, 0.913, 1.0));
shape.into()
} and I also got a rectangle of a different color than expected: Whereas if I restore the pub fn shape() -> AnyShape {
let circle1 = Circle(50.px());
let circle_bg = circle1.translate_x(-(50.0.px()));
let circle_sub = circle1.translate_y(-(50.0.px()));
let rect = Rect((100.0.px(), 100.0.px()));
let shape = circle_bg + rect - circle_sub;
let shape = shape.fill(color::Rgba::new(0.927, 0.937, 0.913, 1.0));
shape.into()
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Seems like a bug. I will investigate that. But let's use rectangle now + create comment that it will be better to use plane, but there is some colouring bug. May be related to: #3384 |
||
shape.into() | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
// =========== | ||
// === FRP === | ||
// =========== | ||
|
||
ensogl_core::define_endpoints_2! { | ||
Input { | ||
set_header_text(String), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what else you can set in header? IMO this should be called "set_header" instead. |
||
set_entries(entry::AnyModelProvider<entry::Label>), | ||
set_background_color(Rgba), | ||
set_size(Vector2), | ||
} | ||
Output {} | ||
} | ||
|
||
impl component::Frp<Model> for Frp { | ||
fn init(api: &Self::Private, _app: &Application, model: &Model, style: &StyleWatchFrp) { | ||
let network = &api.network; | ||
let input = &api.input; | ||
let header_text_size = style.get_number(theme::header::text::size); | ||
frp::extend! { network | ||
|
||
// === Geometry === | ||
|
||
let header_geometry = HeaderGeometry::from_style(style, network); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, try making the file readable from top-to-bottom. |
||
size_and_header_geometry <- all(&input.set_size, &header_geometry); | ||
eval size_and_header_geometry(((size, hdr_geom)) model.resize(*size, *hdr_geom)); | ||
|
||
|
||
// === Header === | ||
|
||
init <- source_(); | ||
header_text_size <- all(&header_text_size, &init)._0(); | ||
model.header.set_default_text_size <+ header_text_size.map(|v| text::Size(*v)); | ||
model.header.set_content <+ input.set_header_text; | ||
eval input.set_background_color((c) | ||
model.background.color.set(c.into())); | ||
|
||
|
||
// === Entries === | ||
|
||
model.entries.set_background_color(Rgba(1.0, 1.0, 1.0, 0.0)); | ||
model.entries.show_background_shadow(false); | ||
model.entries.set_background_corners_radius(0.0); | ||
model.entries.set_background_color <+ input.set_background_color; | ||
model.entries.set_entries <+ input.set_entries; | ||
} | ||
init.emit(()); | ||
} | ||
} | ||
|
||
|
||
|
||
// ======================= | ||
// === Header Geometry === | ||
// ======================= | ||
|
||
#[derive(Debug, Copy, Clone, Default)] | ||
struct HeaderGeometry { | ||
height: f32, | ||
padding_left: f32, | ||
padding_right: f32, | ||
padding_bottom: f32, | ||
} | ||
|
||
impl HeaderGeometry { | ||
fn from_style(style: &StyleWatchFrp, network: &frp::Network) -> frp::Sampler<Self> { | ||
let height = style.get_number(theme::header::height); | ||
let padding_left = style.get_number(theme::header::padding::left); | ||
let padding_right = style.get_number(theme::header::padding::right); | ||
let padding_bottom = style.get_number(theme::header::padding::bottom); | ||
|
||
frp::extend! { network | ||
init <- source_(); | ||
theme <- all_with5(&init,&height,&padding_left,&padding_right,&padding_bottom, | ||
|_,&height,&padding_left,&padding_right,&padding_bottom| | ||
Self{height,padding_left,padding_right,padding_bottom} | ||
); | ||
theme_sampler <- theme.sampler(); | ||
} | ||
init.emit(()); | ||
theme_sampler | ||
} | ||
} | ||
|
||
|
||
|
||
// ============= | ||
// === Model === | ||
// ============= | ||
|
||
/// The Model of the [`View`] component. | ||
#[derive(Clone, CloneRef, Debug)] | ||
pub struct Model { | ||
display_object: display::object::Instance, | ||
header: text::Area, | ||
background: background::View, | ||
entries: ListView<entry::Label>, | ||
} | ||
|
||
impl display::Object for Model { | ||
fn display_object(&self) -> &display::object::Instance { | ||
&self.display_object | ||
} | ||
} | ||
|
||
impl component::Model for Model { | ||
fn label() -> &'static str { | ||
"ComponentGroupView" | ||
} | ||
|
||
fn new(app: &Application, logger: &Logger) -> Self { | ||
let display_object = display::object::Instance::new(&logger); | ||
let background = background::View::new(&logger); | ||
let header = text::Area::new(app); | ||
let entries = ListView::new(app); | ||
display_object.add_child(&background); | ||
display_object.add_child(&header); | ||
display_object.add_child(&entries); | ||
|
||
header.set_font("DejaVuSans-Bold"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should not be hardcoded here. |
||
let label_layer = &app.display.default_scene.layers.label; | ||
header.add_to_scene_layer(label_layer); | ||
|
||
Model { display_object, header, background, entries } | ||
} | ||
} | ||
|
||
impl Model { | ||
fn resize(&self, size: Vector2, header_geometry: HeaderGeometry) { | ||
// === Background === | ||
|
||
self.background.size.set(size); | ||
|
||
|
||
// === Header Text === | ||
|
||
let header_padding_left = header_geometry.padding_left; | ||
let header_text_x = -size.x / 2.0 + header_padding_left; | ||
let header_text_height = self.header.height.value(); | ||
let header_padding_bottom = header_geometry.padding_bottom; | ||
let header_height = header_geometry.height; | ||
let header_bottom_y = size.y / 2.0 - header_height; | ||
let header_text_y = header_bottom_y + header_text_height + header_padding_bottom; | ||
self.header.set_position_xy(Vector2(header_text_x, header_text_y)); | ||
let header_padding_right = header_geometry.padding_right; | ||
self.header.set_truncation_width(size.x - header_padding_left - header_padding_right); | ||
|
||
|
||
// === Entries === | ||
|
||
self.entries.resize(size - Vector2(0.0, header_height)); | ||
self.entries.set_position_y(-header_height / 2.0); | ||
} | ||
} | ||
|
||
|
||
|
||
// ============ | ||
// === View === | ||
// ============ | ||
|
||
/// The implementation of the visual component described in the module's documentation. | ||
pub type View = ComponentView<Model, Frp>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![recursion_limit = "1024"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this needed? |
||
// === Standard Linter Configuration === | ||
#![deny(non_ascii_idents)] | ||
#![warn(unsafe_code)] | ||
// === Non-Standard Linter Configuration === | ||
#![warn(missing_copy_implementations)] | ||
#![warn(missing_debug_implementations)] | ||
#![warn(missing_docs)] | ||
#![warn(trivial_casts)] | ||
#![warn(trivial_numeric_casts)] | ||
#![warn(unused_import_braces)] | ||
#![warn(unused_qualifications)] | ||
|
||
|
||
// ============== | ||
// === Export === | ||
// ============== | ||
|
||
pub use ide_view_component_group as component_group_view; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "debug-scene-component-group" | ||
version = "0.1.0" | ||
authors = ["Enso Team <[email protected]>"] | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
enso-frp = { path = "../../../../../lib/rust/frp" } | ||
ensogl-core = { path = "../../../../../lib/rust/ensogl/core" } | ||
ensogl-hardcoded-theme = { path = "../../../../../lib/rust/ensogl/app/theme/hardcoded" } | ||
ensogl-list-view = { path = "../../../../../lib/rust/ensogl/component/list-view" } | ||
ensogl-text-msdf-sys = { path = "../../../../../lib/rust/ensogl/component/text/msdf-sys" } | ||
ide-view-component-group = { path = "../../component-browser/component-group-view" } | ||
wasm-bindgen = { version = "0.2.78", features = ["nightly"] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this thing is called "Component Group View" instead of just "Component Group"? I know that we have "List View", but this is because "List" is a data structure. Other components, like "Text Area" are not named "Text Area View". @farmaazon, what do you think of it?