ColorSpace, ImageFormat, ImageUsageFlags, PresentMode, SwapchainConfigurator, SwapchainImage,
ThreadToken, create_device,
};
-use narcissus_maths::{Vec2, sin_cos_pi_f32, vec2};
+use narcissus_maths::{Vec2, vec2};
mod draw;
mod fonts;
draw_cmds: Vec<Draw2dCmd>,
}
+#[allow(unused)]
impl<'a> UiState<'a> {
fn new(fonts: &'a Fonts<'a>) -> Self {
let glyph_cache = GlyphCache::new(fonts, GLYPH_CACHE_SIZE, GLYPH_CACHE_SIZE, 1);
y: f32,
font_family: FontFamily,
font_size_px: f32,
+ color: u32,
args: std::fmt::Arguments,
) -> f32 {
let scissor_index = self.scissor_stack.last().copied().unwrap_or(0);
self.draw_cmds.push(Draw2dCmd::glyph(
scissor_index,
touched_glyph_index,
- microshades::GRAY_RGBA8[4].rotate_right(8),
+ color,
vec2(x, y),
));
}
let mut swapchain_configurator = Configurator();
- let mut draw_duration = Duration::ZERO;
-
'main: loop {
let frame = gpu.begin_frame();
{
{
let width = width as f32;
- let height = height as f32;
-
- let (s, c) = sin_cos_pi_f32(game_state.time * 0.1);
-
- let w = width / 5.0;
- let h = height / 5.0;
- let x = width / 2.0 + w * s;
- let y = height / 2.0 + w * c;
- ui_state.push_scissor(vec2(x - w, y - h), vec2(x + w, y + h), true);
- for _ in 0..200 {
- ui_state.rect(
- 0.0, 0.0, width, height, 0.0, [0.0; 4], 0x10101010, 0x10101010,
- );
- }
- ui_state.pop_scissor();
-
- ui_state.push_scissor(vec2(x - w, y - h), vec2(x + w, y + h), true);
-
- let mut y = 8.0 * ui_state.scale;
- for i in 0..224 {
- if i & 1 == 0 {
- ui_state.push_fullscreen_scissor();
- }
- let vertical_advance = ui_state.text_fmt(
- 5.0,
- y,
- FontFamily::NotoSansJapanese,
- 16.0 + s * 8.0,
- format_args!(
- "お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████お握り The Quick Brown Fox Jumped Over The Lazy Dog. ████████"
- ),
- );
- y += vertical_advance;
- if i & 1 == 0 {
- ui_state.pop_scissor();
- }
- }
+ let font_size_px = 20.0;
- ui_state.pop_scissor();
+ let font = ui_state.fonts.font(FontFamily::NotoSansJapanese);
+ let font_size_px_scaled = font_size_px * ui_state.scale;
+ let font_scale = font.scale_for_size_px(font_size_px_scaled);
- for i in 0..500 {
- let (s, c) = sin_cos_pi_f32(game_state.time * 0.1 + i as f32 * 0.01);
+ let y = font.ascent() * font_scale;
+ let h = (font.ascent() - font.descent()) * font_scale;
- let x = width / 2.0 + w * s;
- let y = height / 2.0 + w * c;
- ui_state.rect(
- x - 200.0,
- y - 200.0,
- 400.0,
- 400.0,
- 50.0,
- [100.0, 50.0, 25.0, 0.0],
- 0x33333333,
- (microshades::BLUE_RGBA8[4] >> 8) | 0xff00_0000,
- );
- }
+ ui_state.rect(0.0, 0.0, width, h, 0.0, [0.0; 4], 0x0, 0x40000000);
- for i in 0..50 {
- let (s, c) = sin_cos_pi_f32(game_state.time * 0.1 + i as f32 * 0.04);
+ ui_state.text_fmt(
+ 10.0,
+ y,
+ FontFamily::NotoSansJapanese,
+ font_size_px,
+ 0xffffffff,
+ format_args!("tick: {:?}", tick_duration),
+ );
- let x = width / 2.0 + w * 0.5 * s;
- let y = height / 2.0 + w * 0.5 * c;
+ for i in 1..=3 {
ui_state.rect(
- x - 200.0,
- y - 200.0,
- 400.0,
- 400.0,
- 10.0,
- [10.0, 10.0, 10.0, 10.0],
- 0xffff0000,
- 0x0,
+ width - font_size_px_scaled * i as f32,
+ 0.0,
+ font_size_px_scaled * 0.75,
+ font_size_px_scaled * 0.75,
+ 4.0 * ui_state.scale,
+ [5.0 * ui_state.scale; 4],
+ microshades::GREEN_RGBA8[3].rotate_right(8),
+ microshades::GRAY_RGBA8[0].rotate_right(8),
);
}
-
- let x = 10.0 * ui_state.scale;
- let mut y = 20.0 * ui_state.scale;
- for i in 0..10 {
- if i & 1 != 0 {
- y += ui_state.text_fmt(
- x,
- y,
- FontFamily::RobotoRegular,
- 20.0,
- format_args!("this tick: {:?}", tick_duration),
- );
- } else {
- y += ui_state.text_fmt(
- x,
- y,
- FontFamily::NotoSansJapanese,
- 20.0,
- format_args!("last draw: {:?}", draw_duration),
- );
- }
- }
}
draw_state.draw(
height,
swapchain_image,
);
-
- draw_duration = Instant::now() - draw_start;
}
gpu.end_frame(frame);