gaming
This commit is contained in:
1 parent
23a5ccd05e
commit
c7e3225c5f
11 files changed
+247
-142
No files matched your search
+33
-23
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use app::App;
|
||||
use gui::{Dir, Rect, UI, UIColor, WidgetArrUtil, WidgetUtil, fixed, ratio, rel};
|
||||
use gui::*;
|
||||
use render::Renderer;
|
||||
use winit::{event::WindowEvent, event_loop::ActiveEventLoop, window::Window};
|
||||
|
||||
@@ -14,44 +14,46 @@ pub fn main() {
|
||||
|
||||
pub struct Client {
|
||||
renderer: Renderer,
|
||||
ui: Ui,
|
||||
test: WidgetId<Span>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn new(window: Arc<Window>) -> Self {
|
||||
let mut renderer = Renderer::new(window);
|
||||
let renderer = Renderer::new(window);
|
||||
let rect = Rect {
|
||||
color: UIColor::WHITE,
|
||||
color: UiColor::WHITE,
|
||||
radius: 20.0,
|
||||
thickness: 0.0,
|
||||
inner_radius: 0.0,
|
||||
};
|
||||
let mut ui = UI::build();
|
||||
let blue = ui.add(rect.color(UIColor::BLUE));
|
||||
let handle = blue.handle();
|
||||
let mut ui = ui.finish(
|
||||
let mut ui = Ui::new();
|
||||
let test = ui.id();
|
||||
ui.set_base(
|
||||
(
|
||||
(
|
||||
blue,
|
||||
rect.color(UiColor::BLUE),
|
||||
(
|
||||
rect.color(UIColor::RED).center((100.0, 100.0)),
|
||||
rect.color(UiColor::RED).center((100.0, 100.0)),
|
||||
(
|
||||
rect.color(UIColor::ORANGE),
|
||||
rect.color(UIColor::LIME).pad(10.0),
|
||||
rect.color(UiColor::ORANGE),
|
||||
rect.color(UiColor::LIME).pad(10.0),
|
||||
)
|
||||
.span(Dir::RIGHT, [1, 1]),
|
||||
rect.color(UIColor::YELLOW),
|
||||
rect.color(UiColor::YELLOW),
|
||||
)
|
||||
.span(Dir::RIGHT, [2, 2, 1])
|
||||
.pad(10),
|
||||
)
|
||||
.span(Dir::RIGHT, [1, 3]),
|
||||
Span::empty(Dir::RIGHT).id(&test),
|
||||
(
|
||||
rect.color(UIColor::GREEN),
|
||||
rect.color(UIColor::ORANGE),
|
||||
rect.color(UIColor::CYAN),
|
||||
rect.color(UIColor::BLUE),
|
||||
rect.color(UIColor::MAGENTA),
|
||||
rect.color(UIColor::RED),
|
||||
rect.color(UiColor::GREEN),
|
||||
rect.color(UiColor::ORANGE),
|
||||
rect.color(UiColor::CYAN),
|
||||
rect.color(UiColor::BLUE),
|
||||
rect.color(UiColor::MAGENTA),
|
||||
rect.color(UiColor::RED),
|
||||
)
|
||||
.span(
|
||||
Dir::LEFT,
|
||||
@@ -65,19 +67,27 @@ impl Client {
|
||||
],
|
||||
),
|
||||
)
|
||||
.span(Dir::DOWN, [3, 1])
|
||||
.span(Dir::DOWN, [3, 1, 1])
|
||||
.pad(10),
|
||||
);
|
||||
ui.widgets.get_mut(&handle).unwrap().color = UIColor::MAGENTA;
|
||||
renderer.update(&ui);
|
||||
Self { renderer }
|
||||
Self { renderer, ui, test }
|
||||
}
|
||||
|
||||
pub fn event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
|
||||
match event {
|
||||
WindowEvent::CloseRequested => event_loop.exit(),
|
||||
WindowEvent::RedrawRequested => self.renderer.draw(),
|
||||
WindowEvent::RedrawRequested => {
|
||||
self.renderer.update(&mut self.ui);
|
||||
self.renderer.draw()
|
||||
}
|
||||
WindowEvent::Resized(size) => self.renderer.resize(&size),
|
||||
WindowEvent::KeyboardInput { event, .. } => {
|
||||
if event.state.is_pressed() {
|
||||
let child = self.ui.add(Rect::new(Color::YELLOW)).erase_type();
|
||||
self.ui[&self.test].children.push((child, fixed(20.0)));
|
||||
self.renderer.window().request_redraw();
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use gui::{UIRenderNode, UI};
|
||||
use gui::{UIRenderNode, Ui};
|
||||
use pollster::FutureExt;
|
||||
use std::sync::Arc;
|
||||
use wgpu::util::StagingBelt;
|
||||
@@ -7,6 +7,7 @@ use winit::{dpi::PhysicalSize, window::Window};
|
||||
pub const CLEAR_COLOR: wgpu::Color = wgpu::Color::BLACK;
|
||||
|
||||
pub struct Renderer {
|
||||
window: Arc<Window>,
|
||||
surface: wgpu::Surface<'static>,
|
||||
device: wgpu::Device,
|
||||
queue: wgpu::Queue,
|
||||
@@ -17,7 +18,7 @@ pub struct Renderer {
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn update(&mut self, ui: &UI) {
|
||||
pub fn update(&mut self, ui: &mut Ui) {
|
||||
self.ui_node.update(&self.device, &self.queue, ui);
|
||||
}
|
||||
|
||||
@@ -127,6 +128,11 @@ impl Renderer {
|
||||
encoder,
|
||||
staging_belt,
|
||||
ui_node: shape_pipeline,
|
||||
window,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn window(&self) -> &Window {
|
||||
self.window.as_ref()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user