Merge branch 'master' into beacon
This commit is contained in:
commit
8bd5de72ea
371 changed files with 33138 additions and 12950 deletions
|
|
@ -2,13 +2,15 @@
|
|||
name = "integration"
|
||||
version = "0.1.0"
|
||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
iced_winit.workspace = true
|
||||
iced_wgpu.workspace = true
|
||||
|
||||
iced_widget.workspace = true
|
||||
iced_widget.features = ["wgpu"]
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
tracing-subscriber = "0.3"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
use iced_wgpu::Renderer;
|
||||
use iced_widget::{column, container, row, slider, text, text_input};
|
||||
use iced_winit::core::alignment;
|
||||
use iced_winit::core::{Color, Element, Length, Theme};
|
||||
use iced_winit::runtime::{Command, Program};
|
||||
use iced_widget::{bottom, column, row, slider, text, text_input};
|
||||
use iced_winit::core::{Color, Element, Theme};
|
||||
|
||||
pub struct Controls {
|
||||
background_color: Color,
|
||||
|
|
@ -28,12 +26,8 @@ impl Controls {
|
|||
}
|
||||
}
|
||||
|
||||
impl Program for Controls {
|
||||
type Theme = Theme;
|
||||
type Message = Message;
|
||||
type Renderer = Renderer;
|
||||
|
||||
fn update(&mut self, message: Message) -> Command<Message> {
|
||||
impl Controls {
|
||||
pub fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::BackgroundColorChanged(color) => {
|
||||
self.background_color = color;
|
||||
|
|
@ -42,11 +36,9 @@ impl Program for Controls {
|
|||
self.input = input;
|
||||
}
|
||||
}
|
||||
|
||||
Command::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message, Theme, Renderer> {
|
||||
pub fn view(&self) -> Element<Message, Theme, Renderer> {
|
||||
let background_color = self.background_color;
|
||||
|
||||
let sliders = row![
|
||||
|
|
@ -75,21 +67,17 @@ impl Program for Controls {
|
|||
.width(500)
|
||||
.spacing(20);
|
||||
|
||||
container(
|
||||
bottom(
|
||||
column![
|
||||
text("Background color").color(Color::WHITE),
|
||||
text(format!("{background_color:?}"))
|
||||
.size(14)
|
||||
.color(Color::WHITE),
|
||||
text_input("Placeholder", &self.input)
|
||||
.on_input(Message::InputChanged),
|
||||
text!("{background_color:?}").size(14).color(Color::WHITE),
|
||||
sliders,
|
||||
text_input("Type something...", &self.input)
|
||||
.on_input(Message::InputChanged),
|
||||
]
|
||||
.spacing(10),
|
||||
)
|
||||
.padding(10)
|
||||
.height(Length::Fill)
|
||||
.align_y(alignment::Vertical::Bottom)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,17 @@ use controls::Controls;
|
|||
use scene::Scene;
|
||||
|
||||
use iced_wgpu::graphics::Viewport;
|
||||
use iced_wgpu::{wgpu, Engine, Renderer};
|
||||
use iced_wgpu::{Engine, Renderer, wgpu};
|
||||
use iced_winit::Clipboard;
|
||||
use iced_winit::conversion;
|
||||
use iced_winit::core::mouse;
|
||||
use iced_winit::core::renderer;
|
||||
use iced_winit::core::time::Instant;
|
||||
use iced_winit::core::window;
|
||||
use iced_winit::core::{Color, Font, Pixels, Size, Theme};
|
||||
use iced_winit::core::{Event, Font, Pixels, Size, Theme};
|
||||
use iced_winit::futures;
|
||||
use iced_winit::runtime::program;
|
||||
use iced_winit::runtime::user_interface::{self, UserInterface};
|
||||
use iced_winit::winit;
|
||||
use iced_winit::Clipboard;
|
||||
|
||||
use winit::{
|
||||
event::WindowEvent,
|
||||
|
|
@ -42,8 +43,10 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
engine: Engine,
|
||||
renderer: Renderer,
|
||||
scene: Scene,
|
||||
state: program::State<Controls>,
|
||||
cursor_position: Option<winit::dpi::PhysicalPosition<f64>>,
|
||||
controls: Controls,
|
||||
events: Vec<Event>,
|
||||
cursor: mouse::Cursor,
|
||||
cache: user_interface::Cache,
|
||||
clipboard: Clipboard,
|
||||
viewport: Viewport,
|
||||
modifiers: ModifiersState,
|
||||
|
|
@ -67,7 +70,7 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
Size::new(physical_size.width, physical_size.height),
|
||||
window.scale_factor(),
|
||||
);
|
||||
let clipboard = Clipboard::connect(&window);
|
||||
let clipboard = Clipboard::connect(window.clone());
|
||||
|
||||
let backend =
|
||||
wgpu::util::backend_bits_from_env().unwrap_or_default();
|
||||
|
|
@ -101,6 +104,8 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
required_features: adapter_features
|
||||
& wgpu::Features::default(),
|
||||
required_limits: wgpu::Limits::default(),
|
||||
memory_hints:
|
||||
wgpu::MemoryHints::MemoryUsage,
|
||||
},
|
||||
None,
|
||||
)
|
||||
|
|
@ -144,19 +149,13 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
// Initialize iced
|
||||
let engine =
|
||||
Engine::new(&adapter, &device, &queue, format, None);
|
||||
let mut renderer = Renderer::new(
|
||||
let renderer = Renderer::new(
|
||||
&device,
|
||||
&engine,
|
||||
Font::default(),
|
||||
Pixels::from(16),
|
||||
);
|
||||
|
||||
let state = program::State::new(
|
||||
controls,
|
||||
viewport.logical_size(),
|
||||
&mut renderer,
|
||||
);
|
||||
|
||||
// You should change this if you want to render continuously
|
||||
event_loop.set_control_flow(ControlFlow::Wait);
|
||||
|
||||
|
|
@ -169,9 +168,11 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
engine,
|
||||
renderer,
|
||||
scene,
|
||||
state,
|
||||
cursor_position: None,
|
||||
controls,
|
||||
events: Vec::new(),
|
||||
cursor: mouse::Cursor::Unavailable,
|
||||
modifiers: ModifiersState::default(),
|
||||
cache: user_interface::Cache::new(),
|
||||
clipboard,
|
||||
viewport,
|
||||
resized: false,
|
||||
|
|
@ -194,11 +195,13 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
engine,
|
||||
renderer,
|
||||
scene,
|
||||
state,
|
||||
controls,
|
||||
events,
|
||||
viewport,
|
||||
cursor_position,
|
||||
cursor,
|
||||
modifiers,
|
||||
clipboard,
|
||||
cache,
|
||||
resized,
|
||||
} = self
|
||||
else {
|
||||
|
|
@ -238,8 +241,6 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
&wgpu::CommandEncoderDescriptor { label: None },
|
||||
);
|
||||
|
||||
let program = state.program();
|
||||
|
||||
let view = frame.texture.create_view(
|
||||
&wgpu::TextureViewDescriptor::default(),
|
||||
);
|
||||
|
|
@ -249,7 +250,7 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
let mut render_pass = Scene::clear(
|
||||
&view,
|
||||
&mut encoder,
|
||||
program.background_color(),
|
||||
controls.background_color(),
|
||||
);
|
||||
|
||||
// Draw the scene
|
||||
|
|
@ -257,6 +258,33 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
}
|
||||
|
||||
// And then iced on top
|
||||
let mut interface = UserInterface::build(
|
||||
controls.view(),
|
||||
viewport.logical_size(),
|
||||
std::mem::take(cache),
|
||||
renderer,
|
||||
);
|
||||
|
||||
let _ = interface.update(
|
||||
&[Event::Window(
|
||||
window::Event::RedrawRequested(
|
||||
Instant::now(),
|
||||
),
|
||||
)],
|
||||
*cursor,
|
||||
renderer,
|
||||
clipboard,
|
||||
&mut Vec::new(),
|
||||
);
|
||||
|
||||
let mouse_interaction = interface.draw(
|
||||
renderer,
|
||||
&Theme::Dark,
|
||||
&renderer::Style::default(),
|
||||
*cursor,
|
||||
);
|
||||
*cache = interface.into_cache();
|
||||
|
||||
renderer.present(
|
||||
engine,
|
||||
device,
|
||||
|
|
@ -273,17 +301,15 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
frame.present();
|
||||
|
||||
// Update the mouse cursor
|
||||
window.set_cursor(
|
||||
iced_winit::conversion::mouse_interaction(
|
||||
state.mouse_interaction(),
|
||||
),
|
||||
);
|
||||
window.set_cursor(conversion::mouse_interaction(
|
||||
mouse_interaction,
|
||||
));
|
||||
}
|
||||
Err(error) => match error {
|
||||
wgpu::SurfaceError::OutOfMemory => {
|
||||
panic!(
|
||||
"Swapchain error: {error}. \
|
||||
Rendering cannot continue."
|
||||
Rendering cannot continue."
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -294,7 +320,11 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
}
|
||||
}
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
*cursor_position = Some(position);
|
||||
*cursor =
|
||||
mouse::Cursor::Available(conversion::cursor_position(
|
||||
position,
|
||||
viewport.scale_factor(),
|
||||
));
|
||||
}
|
||||
WindowEvent::ModifiersChanged(new_modifiers) => {
|
||||
*modifiers = new_modifiers.state();
|
||||
|
|
@ -309,37 +339,42 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
|
|||
}
|
||||
|
||||
// Map window event to iced event
|
||||
if let Some(event) = iced_winit::conversion::window_event(
|
||||
window::Id::MAIN,
|
||||
if let Some(event) = conversion::window_event(
|
||||
event,
|
||||
window.scale_factor(),
|
||||
*modifiers,
|
||||
) {
|
||||
state.queue_event(event);
|
||||
events.push(event);
|
||||
}
|
||||
|
||||
// If there are events pending
|
||||
if !state.is_queue_empty() {
|
||||
// We update iced
|
||||
let _ = state.update(
|
||||
if !events.is_empty() {
|
||||
// We process them
|
||||
let mut interface = UserInterface::build(
|
||||
controls.view(),
|
||||
viewport.logical_size(),
|
||||
cursor_position
|
||||
.map(|p| {
|
||||
conversion::cursor_position(
|
||||
p,
|
||||
viewport.scale_factor(),
|
||||
)
|
||||
})
|
||||
.map(mouse::Cursor::Available)
|
||||
.unwrap_or(mouse::Cursor::Unavailable),
|
||||
std::mem::take(cache),
|
||||
renderer,
|
||||
&Theme::Dark,
|
||||
&renderer::Style {
|
||||
text_color: Color::WHITE,
|
||||
},
|
||||
clipboard,
|
||||
);
|
||||
|
||||
let mut messages = Vec::new();
|
||||
|
||||
let _ = interface.update(
|
||||
events,
|
||||
*cursor,
|
||||
renderer,
|
||||
clipboard,
|
||||
&mut messages,
|
||||
);
|
||||
|
||||
events.clear();
|
||||
*cache = interface.into_cache();
|
||||
|
||||
// update our UI with any messages
|
||||
for message in messages {
|
||||
controls.update(message);
|
||||
}
|
||||
|
||||
// and request a redraw
|
||||
window.request_redraw();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,12 +72,13 @@ fn build_pipeline(
|
|||
layout: Some(&pipeline_layout),
|
||||
vertex: wgpu::VertexState {
|
||||
module: &vs_module,
|
||||
entry_point: "main",
|
||||
entry_point: Some("main"),
|
||||
buffers: &[],
|
||||
compilation_options: wgpu::PipelineCompilationOptions::default(),
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &fs_module,
|
||||
entry_point: "main",
|
||||
entry_point: Some("main"),
|
||||
targets: &[Some(wgpu::ColorTargetState {
|
||||
format: texture_format,
|
||||
blend: Some(wgpu::BlendState {
|
||||
|
|
@ -86,6 +87,7 @@ fn build_pipeline(
|
|||
}),
|
||||
write_mask: wgpu::ColorWrites::ALL,
|
||||
})],
|
||||
compilation_options: wgpu::PipelineCompilationOptions::default(),
|
||||
}),
|
||||
primitive: wgpu::PrimitiveState {
|
||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
|
|
@ -99,5 +101,6 @@ fn build_pipeline(
|
|||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multiview: None,
|
||||
cache: None,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue