-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add examples for rect and text, refactor sugarloaf and remove custom …
…renderer
- Loading branch information
1 parent
245852b
commit dd6dd28
Showing
13 changed files
with
231 additions
and
189 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
extern crate tokio; | ||
|
||
use winit::platform::run_return::EventLoopExtRunReturn; | ||
use winit::{ | ||
dpi::LogicalSize, | ||
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}, | ||
event_loop::EventLoop, | ||
window::WindowBuilder, | ||
}; | ||
|
||
use sugarloaf::core::{Sugar, SugarloafStyle}; | ||
use sugarloaf::{RendererTarget, Sugarloaf}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut event_loop = EventLoop::new(); | ||
let width = 1200.0; | ||
let height = 800.0; | ||
|
||
let window = WindowBuilder::new() | ||
.with_title("Text example") | ||
.with_inner_size(LogicalSize::new(1200.0, 800.0)) | ||
.with_resizable(true) | ||
.build(&event_loop) | ||
.unwrap(); | ||
|
||
let mut sugarloaf = Sugarloaf::new( | ||
RendererTarget::Desktop, | ||
&window, | ||
wgpu::PowerPreference::HighPerformance, | ||
"Firamono".to_string(), | ||
) | ||
.await | ||
.expect("Sugarloaf instance should be created"); | ||
|
||
event_loop.run_return(move |event, _, control_flow| { | ||
control_flow.set_wait(); | ||
|
||
match event { | ||
Event::Resumed => { | ||
window.request_redraw(); | ||
} | ||
Event::WindowEvent { event, .. } => match event { | ||
WindowEvent::CloseRequested => control_flow.set_exit(), | ||
WindowEvent::KeyboardInput { | ||
input: | ||
KeyboardInput { | ||
virtual_keycode: Some(VirtualKeyCode::Space), | ||
state: ElementState::Released, | ||
.. | ||
}, | ||
.. | ||
} => { | ||
// | ||
} | ||
WindowEvent::ScaleFactorChanged { | ||
new_inner_size, | ||
scale_factor, | ||
.. | ||
} => { | ||
sugarloaf | ||
.rescale(scale_factor as f32) | ||
.resize(new_inner_size.width, new_inner_size.height) | ||
.render(wgpu::Color::BLACK); | ||
} | ||
_ => (), | ||
}, | ||
Event::RedrawRequested { .. } => { | ||
let sugar = vec![ | ||
Sugar { | ||
content: 'S', | ||
foreground_color: [1.0, 1.0, 1.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
Sugar { | ||
content: 'u', | ||
foreground_color: [0.0, 0.0, 0.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
Sugar { | ||
content: 'g', | ||
foreground_color: [1.0, 1.0, 1.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
Sugar { | ||
content: 'a', | ||
foreground_color: [0.0, 0.0, 0.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
Sugar { | ||
content: 'r', | ||
foreground_color: [1.0, 1.0, 1.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
]; | ||
|
||
let loaf = vec![ | ||
Sugar { | ||
content: 'l', | ||
foreground_color: [1.0, 1.0, 1.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
Sugar { | ||
content: 'o', | ||
foreground_color: [0.0, 0.0, 0.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
Sugar { | ||
content: 'a', | ||
foreground_color: [1.0, 1.0, 1.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
Sugar { | ||
content: 'f', | ||
foreground_color: [0.0, 0.0, 0.0, 1.0], | ||
background_color: [0.0, 0.0, 0.0, 1.0], | ||
}, | ||
]; | ||
|
||
let scale_factor = 2.; | ||
let font_size = 150.; | ||
|
||
let style = SugarloafStyle { | ||
screen_position: ( | ||
(20. + 10.) * scale_factor, | ||
(20. + font_size) * scale_factor, | ||
), | ||
text_scale: font_size * scale_factor, | ||
bounds: (width * scale_factor, height * scale_factor), | ||
}; | ||
|
||
sugarloaf.stack(sugar, style); | ||
sugarloaf.stack(loaf, style); | ||
sugarloaf.render(wgpu::Color::RED); | ||
} | ||
_ => { | ||
*control_flow = winit::event_loop::ControlFlow::Wait; | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod row; | ||
pub mod rect; | ||
pub mod text; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.