display example text on screen

This commit is contained in:
Anton-4 2022-02-11 20:15:09 +01:00
parent 9efd352d43
commit 51d86f101f
No known key found for this signature in database
GPG key ID: C954D6E0F9C0ABFD
4 changed files with 74 additions and 9 deletions

View file

@ -1,9 +1,9 @@
app "hello-gui"
packages { pf: "platform" }
imports [ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ]
imports [ ] #[ pf.Action.{ Action }, pf.Elem.{ button, text, row, col } ]
provides [ render ] to pf
render =
btn = button { onPress : \prev, _ -> Action.none } (text "Hello, button!")
# btn = button { onPress : \prev, _ -> Action.none } (text "Hello, button!")
"Hello, World!"

View file

@ -1,7 +1,7 @@
use crate::graphics::{
use crate::{graphics::{
lowlevel::buffer::create_rect_buffers, lowlevel::ortho::update_ortho_buffer,
lowlevel::pipelines, primitives::rect::Rect, primitives::text::build_glyph_brush,
};
lowlevel::pipelines, primitives::rect::Rect, primitives::text::{build_glyph_brush, owned_section_from_text, Text}, colors,
}, rects_and_texts::RectsAndTexts};
use pipelines::RectResources;
use roc_std::RocStr;
use std::error::Error;
@ -88,6 +88,19 @@ fn run_event_loop(title: &str) -> Result<(), Box<dyn Error>> {
let mut keyboard_modifiers = ModifiersState::empty();
let mut rects_and_texts = RectsAndTexts::new();
let hello_text = owned_section_from_text(&Text {
position: (50.0, 50.0).into(),
area_bounds: (size.width as f32, size.height as f32).into(),
color: colors::WHITE,
text: "Hello, World!",
size: 40.0,
..Default::default()
});
rects_and_texts.add_text_behind(hello_text);
// Render loop
window.request_redraw();
@ -192,11 +205,11 @@ fn run_event_loop(title: &str) -> Result<(), Box<dyn Error>> {
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
// for text_section in &rendered_wgpu.text_sections_behind {
// let borrowed_text = text_section.to_borrowed();
for text_section in &rects_and_texts.text_sections_behind {
let borrowed_text = text_section.to_borrowed();
// glyph_brush.queue(borrowed_text);
// }
glyph_brush.queue(borrowed_text);
}
// draw first layer of text
glyph_brush

View file

@ -7,6 +7,7 @@ use std::os::raw::c_char;
mod graphics;
mod gui;
mod rects_and_texts;
extern "C" {
#[link_name = "roc__renderForHost_1_exposed"]

View file

@ -0,0 +1,51 @@
use crate::graphics::primitives::rect::Rect;
use crate::graphics::primitives::text::{owned_section_from_text, Text};
#[derive(Debug)]
pub struct RectsAndTexts {
pub text_sections_behind: Vec<glyph_brush::OwnedSection>, // displayed in front of rect_behind, behind everything else
pub text_sections_front: Vec<glyph_brush::OwnedSection>, // displayed in front of everything
pub rects_behind: Vec<Rect>, // displayed at lowest depth
pub rects_front: Vec<Rect>, // displayed in front of text_sections_behind, behind text_sections_front
}
impl RectsAndTexts {
pub fn new() -> Self {
Self {
text_sections_behind: Vec::new(),
text_sections_front: Vec::new(),
rects_behind: Vec::new(),
rects_front: Vec::new(),
}
}
pub fn add_text_behind(&mut self, new_text_section: glyph_brush::OwnedSection) {
self.text_sections_behind.push(new_text_section);
}
pub fn add_text_front(&mut self, new_text_section: glyph_brush::OwnedSection) {
self.text_sections_front.push(new_text_section);
}
pub fn add_rect_behind(&mut self, new_rect: Rect) {
self.rects_behind.push(new_rect);
}
pub fn add_rects_behind(&mut self, new_rects: Vec<Rect>) {
self.rects_behind.extend(new_rects);
}
pub fn add_rect_front(&mut self, new_rect: Rect) {
self.rects_front.push(new_rect);
}
pub fn extend(&mut self, rects_and_texts: RectsAndTexts) {
self.text_sections_behind
.extend(rects_and_texts.text_sections_behind);
self.text_sections_front
.extend(rects_and_texts.text_sections_front);
self.rects_behind.extend(rects_and_texts.rects_behind);
self.rects_front.extend(rects_and_texts.rects_front);
}
}