Skip to content

Commit

Permalink
refactor: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Stumblinbear committed Feb 11, 2024
1 parent fba4fba commit 2133628
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 222 deletions.
19 changes: 0 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug example 'alternating_windows'",
"cargo": {
"args": [
"build",
"--example=alternating_windows",
"--package=agui",
"--features=app,winit-vello,multi-threaded"
],
"filter": {
"name": "alternating_windows",
"kind": "example"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
Expand Down
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ agui = { path = "." }

tracing-subscriber = { version = "0.3", features = ["env-filter"] }

futures-timer = "3.0"
sysinfo = "0.29"

slotmap.workspace = true
Expand Down Expand Up @@ -135,10 +136,6 @@ opt-level = 1
[profile.dev.package.agui_winit]
opt-level = 1

[[example]]
name = "alternating_windows"
required-features = ["app", "winit-vello", "vello"]

[[example]]
name = "clipping"
required-features = ["app", "winit-vello", "vello"]
Expand Down
4 changes: 2 additions & 2 deletions crates/agui_winit/src/widgets/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ where
}

#[derive(PartialEq, Clone, WidgetProps)]
#[props(default)]
#[props(default, into)]
pub struct WinitWindowAttributes {
#[prop(!default, into)]
#[prop(!default)]
title: Cow<'static, str>,

inner_size: Option<Size>,
Expand Down
117 changes: 0 additions & 117 deletions examples/alternating_windows.rs

This file was deleted.

52 changes: 38 additions & 14 deletions examples/current_window.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use std::{thread, time::Duration};
use std::time::Duration;

use tracing::metadata::LevelFilter;
use tracing_subscriber::EnvFilter;

use agui::{
app::run_app,
prelude::*,
winit::{CurrentWindow, Window},
task::{context::ContextSpawnElementTask, TaskHandle},
vello::{
binding::VelloViewBinding,
renderer::{window::VelloWindowRenderer, VelloRenderer},
},
winit::{CurrentWindow, WinitWindow, WinitWindowAttributes},
};
use winit::{dpi::PhysicalSize, window::WindowBuilder};

fn main() {
let filter = EnvFilter::from_default_env()
Expand All @@ -23,15 +27,29 @@ fn main() {
.with_env_filter(filter)
.init();

run_app(build! {
<Window> {
window: || WindowBuilder::new()
.with_title("agui hello world")
.with_inner_size(PhysicalSize::new(800.0, 600.0)),
run_app(move || {
let vello_renderer = VelloRenderer::default();

child: <ExampleMain>::default(),
let (view, view_handle) = vello_renderer.new_view();

build! {
<WinitWindow> {
attributes: WinitWindowAttributes::builder()
.title("agui hello world")
.inner_size(Size::new(800.0, 600.0))
.build(),

renderer: VelloWindowRenderer::new(view_handle),

child: <VelloViewBinding> {
view: view,

child: <ExampleMain>::default()
}
}
}
});
})
.expect("Failed to run app");
}

#[derive(StatefulWidget, PartialEq, Default)]
Expand All @@ -48,6 +66,8 @@ impl StatefulWidget for ExampleMain {
#[derive(Default)]
struct ExampleMainState {
update_count: usize,

handle: Option<TaskHandle<()>>,
}

impl WidgetState for ExampleMainState {
Expand All @@ -60,11 +80,15 @@ impl WidgetState for ExampleMainState {
});
});

thread::spawn(move || loop {
thread::sleep(Duration::from_millis(1000));
self.handle = ctx
.spawn_task(|_| async move {
loop {
futures_timer::Delay::new(Duration::from_millis(1000)).await;

callback.call(());
});
callback.call(());
}
})
.ok();
}

fn build(&mut self, ctx: &mut StatefulBuildContext<Self>) -> Widget {
Expand Down
4 changes: 2 additions & 2 deletions examples/flexbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fn main() {
.with_env_filter(filter)
.init();

let vello_renderer = VelloRenderer::default();

run_app(move || {
let vello_renderer = VelloRenderer::default();

let (view, view_handle) = vello_renderer.new_view();

build! {
Expand Down
21 changes: 12 additions & 9 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use agui_vello::{
binding::VelloViewBinding,
renderer::{window::VelloWindowRenderer, VelloRenderer},
};
use agui_winit::{WinitWindow, WinitWindowAttributes};
use tracing::metadata::LevelFilter;
use tracing_subscriber::EnvFilter;

use agui::{app::run_app, prelude::*};
use agui::{
app::run_app,
prelude::*,
vello::{
binding::VelloViewBinding,
renderer::{window::VelloWindowRenderer, VelloRenderer},
},
winit::{WinitWindow, WinitWindowAttributes},
};

fn main() {
let filter = EnvFilter::from_default_env()
Expand All @@ -21,15 +24,15 @@ fn main() {
.with_env_filter(filter)
.init();

let vello_renderer = VelloRenderer::default();

run_app(move || {
let vello_renderer = VelloRenderer::default();

let (view, view_handle) = vello_renderer.new_view();

build! {
<WinitWindow> {
attributes: WinitWindowAttributes::builder()
.title("Hello, world!")
.title("agui hello world")
.build(),

renderer: VelloWindowRenderer::new(view_handle),
Expand Down
Loading

0 comments on commit 2133628

Please sign in to comment.