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

Added window-size example #186

Merged
merged 1 commit into from
Nov 19, 2023
Merged
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
8 changes: 8 additions & 0 deletions examples/window-size/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "window-size"
version = "0.1.0"
edition = "2021"

[dependencies]
im = "15.1.0"
floem = { path = "../.." }
66 changes: 66 additions & 0 deletions examples/window-size/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use floem::{
event::{Event, EventListener},
keyboard::{Key, NamedKey},
kurbo::Size,
view::View,
views::{label, v_stack, Decorators},
widgets::button,
window::{new_window, WindowConfig},
Application,
};

fn sub_window_view() -> impl View {
v_stack((label(move || String::from("Hello world")).style(|s| s.font_size(30.0)),)).style(|s| {
s.flex_col()
.items_center()
.justify_center()
.width_full()
.height_full()
})
}

fn app_view() -> impl View {
let view = v_stack((
label(move || String::from("Hello world")).style(|s| s.font_size(30.0)),
button(|| "Open another window").on_click_stop(|_| {
new_window(
|_| sub_window_view(),
Some(
WindowConfig::default()
.size(Size::new(600.0, 100.0))
.title("Window Size Sub Example"),
),
);
}),
))
.style(|s| {
s.flex_col()
.items_center()
.justify_center()
.width_full()
.height_full()
.gap(0.0, 10.0)
});

let id = view.id();
view.on_event_stop(EventListener::KeyUp, move |e| {
if let Event::KeyUp(e) = e {
if e.key.logical_key == Key::Named(NamedKey::F11) {
id.inspect();
}
}
})
}

fn main() {
Application::new()
.window(
|_| app_view(),
Some(
WindowConfig::default()
.size(Size::new(800.0, 250.0))
.title("Window Size Example"),
),
)
.run();
}