1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Pixel-perfect fonts

This commit is contained in:
Emil Ernerfeldt
2019-01-19 10:10:28 -06:00
parent cd8ca47e76
commit c2c94ddda5
14 changed files with 207 additions and 212 deletions

View File

@@ -30,9 +30,20 @@ impl App {
gui.add(Separator::new());
gui.add(label(format!(
"Screen size: {} x {}",
"Screen size: {} x {}, pixels_per_point: {}",
gui.input().screen_size.x,
gui.input().screen_size.y,
gui.input().pixels_per_point,
)));
gui.add(label(format!(
"mouse_pos: {} x {}",
gui.input().mouse_pos.x,
gui.input().mouse_pos.y,
)));
gui.add(label(format!(
"gui cursor: {} x {}",
gui.cursor().x,
gui.cursor().y,
)));
gui.horizontal(Align::Min, |gui| {

View File

@@ -29,10 +29,10 @@ pub struct State {
}
impl State {
fn new(canvas_id: &str) -> Result<State, JsValue> {
fn new(canvas_id: &str, pixels_per_point: f32) -> Result<State, JsValue> {
Ok(State {
app: Default::default(),
emigui: Emigui::new(),
emigui: Emigui::new(pixels_per_point),
webgl_painter: webgl::Painter::new(canvas_id)?,
everything_ms: 0.0,
})
@@ -56,7 +56,9 @@ impl State {
region.add(label(format!("Everything: {:.1} ms", self.everything_ms)));
let frame = self.emigui.paint();
let result = self.webgl_painter.paint(&frame, self.emigui.texture());
let result =
self.webgl_painter
.paint(&frame, self.emigui.texture(), raw_input.pixels_per_point);
self.everything_ms = now_ms() - everything_start;
@@ -65,8 +67,8 @@ impl State {
}
#[wasm_bindgen]
pub fn new_webgl_gui(canvas_id: &str) -> Result<State, JsValue> {
State::new(canvas_id)
pub fn new_webgl_gui(canvas_id: &str, pixels_per_point: f32) -> Result<State, JsValue> {
State::new(canvas_id, pixels_per_point)
}
#[wasm_bindgen]

View File

@@ -143,7 +143,12 @@ impl Painter {
self.current_texture_id = Some(texture.id);
}
pub fn paint(&mut self, frame: &Frame, texture: &Texture) -> Result<(), JsValue> {
pub fn paint(
&mut self,
frame: &Frame,
texture: &Texture,
pixels_per_point: f32,
) -> Result<(), JsValue> {
self.upload_texture(texture);
let gl = &self.gl;
@@ -280,8 +285,8 @@ impl Painter {
.unwrap();
gl.uniform2f(
Some(&u_screen_size_loc),
self.canvas.width() as f32,
self.canvas.height() as f32,
self.canvas.width() as f32 / pixels_per_point,
self.canvas.height() as f32 / pixels_per_point,
);
let u_tex_size_loc = gl