Skip to content
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

ECS #432

Merged
merged 25 commits into from
May 8, 2024
Merged

ECS #432

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ rust-version = "1.75"
license.workspace = true

[workspace.dependencies]
peniko = "0.1.0"
kurbo = { version = "0.11", features = ["serde"] }
serde = "1.0"
lapce-xi-rope = { version = "0.3.2", features = ["serde"] }
strum = { version = "0.26.2" }
Expand All @@ -31,6 +33,7 @@ raw-window-handle = "0.6.0"
wgpu = { version = "0.19.0" }

[dependencies]
slotmap = "1.0.7"
sha2 = "0.10.6"
bitflags = "2.2.1"
indexmap = "2"
Expand All @@ -42,9 +45,9 @@ rfd = { version = "0.14.0", default-features = false, features = [
"xdg-portal",
], optional = true }
raw-window-handle = { workspace = true }
kurbo = { version = "0.9.5", features = ["serde"] }
unicode-segmentation = "1.10.0"
floem-peniko = "0.1.0"
peniko = { workspace = true }
kurbo = { workspace = true }
crossbeam-channel = "0.5.6"
im-rc = "15.1.0"
serde = { workspace = true, optional = true }
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,30 @@ _The project is still maturing. We will make occasional breaking changes and add
![Quickstart](docs/img/quickstart.png)

```rust
use floem::reactive::create_signal;
use floem::view::View;
use floem::views::{h_stack, label, v_stack, Decorators};
use floem::widgets::button;
use floem::{
reactive::create_signal,
views::{label, ButtonClass, Decorators},
IntoView,
};

fn app_view() -> impl View {
fn app_view() -> impl IntoView {
// Create a reactive signal with a counter value, defaulting to 0
let (counter, set_counter) = create_signal(0);

// Create a vertical layout
v_stack((
(
// The counter value updates automatically, thanks to reactivity
label(move || format!("Value: {}", counter.get())),
// Create a horizontal layout
h_stack((
button(|| "Increment").on_click_stop(move |_| {
(
"Increment".class(ButtonClass).on_click_stop(move |_| {
set_counter.update(|value| *value += 1);
}),
button(|| "Decrement").on_click_stop(move |_| {
"Decrement".class(ButtonClass).on_click_stop(move |_| {
set_counter.update(|value| *value -= 1);
}),
)),
))
),
).style(|s| s.flex_col())
}

fn main() {
Expand Down
7 changes: 4 additions & 3 deletions editor-core/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{
borrow::{Borrow, Cow},
cmp::Ordering,
collections::BTreeSet,
fmt::Display,
sync::{
atomic::{self, AtomicU64},
Arc,
Expand Down Expand Up @@ -92,9 +93,9 @@ pub struct Buffer {
line_ending: LineEnding,
}

impl ToString for Buffer {
fn to_string(&self) -> String {
self.text().to_string()
impl Display for Buffer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.text().to_string())
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/animations/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use floem::{
peniko::Color,
reactive::{create_rw_signal, create_signal},
style_class,
view::View,
views::{container, empty, h_stack, label, stack, static_label, text, v_stack, Decorators},
IntoView,
};

fn app_view() -> impl View {
fn app_view() -> impl IntoView {
v_stack((progress_bar_container(), cube_container()))
}

style_class!(pub Button);
fn progress_bar_container() -> impl View {
fn progress_bar_container() -> impl IntoView {
let width = 300.0;
let anim_id = create_rw_signal(None);
let is_stopped = create_rw_signal(false);
Expand Down Expand Up @@ -108,7 +108,7 @@ fn progress_bar_container() -> impl View {
})
}

fn cube_container() -> impl View {
fn cube_container() -> impl IntoView {
let (counter, set_counter) = create_signal(0.0);
let (is_hovered, set_is_hovered) = create_signal(false);

Expand Down
10 changes: 5 additions & 5 deletions examples/context/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ use floem::{
keyboard::{Key, Modifiers, NamedKey},
peniko::Color,
reactive::{provide_context, use_context},
view::View,
views::{empty, label, v_stack, Decorators},
IntoView, View,
};

fn colored_label(text: String) -> impl View {
fn colored_label(text: String) -> impl IntoView {
let color: Color = use_context().unwrap();
label(move || text.clone()).style(move |s| s.color(color))
}

fn context_container<V: View + 'static>(
fn context_container<V: IntoView + 'static>(
color: Color,
name: String,
view_fn: impl Fn() -> V,
) -> impl View {
) -> impl IntoView {
provide_context(color);

v_stack((colored_label(name), view_fn())).style(move |s| {
Expand All @@ -27,7 +27,7 @@ fn context_container<V: View + 'static>(
})
}

fn app_view() -> impl View {
fn app_view() -> impl IntoView {
provide_context(Color::BLACK);

let view = v_stack((
Expand Down
8 changes: 8 additions & 0 deletions examples/counter-simple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "counter-simple"
version = "0.1.0"
edition = "2021"

[dependencies]
im.workspace = true
floem = { path = "../.." }
30 changes: 30 additions & 0 deletions examples/counter-simple/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use floem::{
reactive::create_signal,
views::{label, ButtonClass, Decorators},
IntoView,
};

fn app_view() -> impl IntoView {
// Create a reactive signal with a counter value, defaulting to 0
let (counter, set_counter) = create_signal(0);

// Create a vertical layout
(
// The counter value updates automatically, thanks to reactivity
label(move || format!("Value: {}", counter.get())),
// Create a horizontal layout
(
"Increment".class(ButtonClass).on_click_stop(move |_| {
set_counter.update(|value| *value += 1);
}),
"Decrement".class(ButtonClass).on_click_stop(move |_| {
set_counter.update(|value| *value -= 1);
}),
),
)
.style(|s| s.flex_col())
}

fn main() {
floem::launch(app_view);
}
35 changes: 18 additions & 17 deletions examples/counter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ use floem::{
peniko::Color,
reactive::create_signal,
unit::UnitExt,
view::View,
views::{label, stack, text, Decorators},
views::{dyn_container, Decorators},
IntoView, View,
};

fn app_view() -> impl View {
fn app_view() -> impl IntoView {
let (counter, set_counter) = create_signal(0);
let view = stack((
label(move || format!("Value: {}", counter.get())).style(|s| s.padding(10.0)),
stack((
text("Increment")
let view = (
dyn_container(move || format!("Value: {}", counter.get())),
counter.style(|s| s.padding(10.0)),
(
"Increment"
.style(|s| {
s.border_radius(10.0)
.padding(10.0)
Expand All @@ -28,7 +29,7 @@ fn app_view() -> impl View {
}
})
.keyboard_navigatable(),
text("Decrement")
"Decrement"
.on_click_stop({
move |_| {
set_counter.update(|value| *value -= 1);
Expand All @@ -45,7 +46,7 @@ fn app_view() -> impl View {
.active(|s| s.color(Color::WHITE).background(Color::RED))
})
.keyboard_navigatable(),
text("Reset to 0")
"Reset to 0"
.on_click_stop(move |_| {
println!("Reset counter pressed"); // will not fire if button is disabled
set_counter.update(|value| *value = 0);
Expand All @@ -63,14 +64,14 @@ fn app_view() -> impl View {
.active(|s| s.color(Color::WHITE).background(Color::YELLOW_GREEN))
})
.keyboard_navigatable(),
)),
))
.style(|s| {
s.size(100.pct(), 100.pct())
.flex_col()
.items_center()
.justify_center()
});
),
)
.style(|s| {
s.size(100.pct(), 100.pct())
.flex_col()
.items_center()
.justify_center()
});

let id = view.id();
view.on_key_up(Key::Named(NamedKey::F11), Modifiers::empty(), move |_| {
Expand Down
4 changes: 2 additions & 2 deletions examples/draggable/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use floem::{
peniko::Color,
view::View,
views::{label, Decorators},
IntoView,
};

fn app_view() -> impl View {
fn app_view() -> impl IntoView {
label(|| "Drag me!")
.style(|s| {
s.border(1.0)
Expand Down
22 changes: 9 additions & 13 deletions examples/dyn-container/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use floem::{
reactive::{create_rw_signal, RwSignal},
view::View,
views::{dyn_container, h_stack, label, v_stack, Decorators},
widgets::button,
views::{button, dyn_container, h_stack, label, v_stack, Decorators},
IntoView,
};

#[derive(Clone, PartialEq)]
Expand All @@ -11,11 +10,11 @@ enum ViewSwitcher {
Two,
}

fn view_one() -> impl View {
fn view_one() -> impl IntoView {
label(|| "A view")
}

fn view_two(view: RwSignal<ViewSwitcher>) -> impl View {
fn view_two(view: RwSignal<ViewSwitcher>) -> impl IntoView {
v_stack((
label(|| "Another view"),
button(|| "Switch back").on_click_stop(move |_| {
Expand All @@ -25,7 +24,7 @@ fn view_two(view: RwSignal<ViewSwitcher>) -> impl View {
.style(|s| s.gap(0.0, 10.0))
}

fn app_view() -> impl View {
fn app_view() -> impl IntoView {
let view = create_rw_signal(ViewSwitcher::One);

v_stack((
Expand All @@ -41,13 +40,10 @@ fn app_view() -> impl View {
})
.style(|s| s.margin_bottom(20)),
)),
dyn_container(
move || view.get(),
move |value| match value {
ViewSwitcher::One => view_one().any(),
ViewSwitcher::Two => view_two(view).any(),
},
)
dyn_container(move || match view.get() {
ViewSwitcher::One => view_one().into_any(),
ViewSwitcher::Two => view_two(view).into_any(),
})
.style(|s| s.padding(10).border(1)),
))
.style(|s| {
Expand Down
6 changes: 3 additions & 3 deletions examples/editor/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use floem::{
keyboard::{Key, Modifiers, NamedKey},
reactive::RwSignal,
view::View,
views::{
button,
editor::{
command::{Command, CommandExecuted},
core::{command::EditCommand, editor::EditType, selection::Selection},
text::{default_dark_color, SimpleStyling},
},
stack, text_editor, Decorators,
},
widgets::button,
IntoView, View,
};

fn app_view() -> impl View {
fn app_view() -> impl IntoView {
let text = std::env::args()
.nth(1)
.map(|s| std::fs::read_to_string(s).unwrap());
Expand Down
7 changes: 3 additions & 4 deletions examples/files/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use floem::{
action::{open_file, save_as},
file::{FileDialogOptions, FileSpec},
keyboard::{Key, Modifiers, NamedKey},
view::View,
views::{h_stack, Decorators},
widgets::button,
views::{button, h_stack, Decorators},
IntoView, View,
};

fn app_view() -> impl View {
fn app_view() -> impl IntoView {
let view = h_stack((
button(|| "Select file").on_click_cont(|_| {
open_file(
Expand Down
Loading
Loading