mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 12:50:04 -04:00
Control the maximum egui web canvas size with App::max_size_points
This commit is contained in:
@@ -191,7 +191,7 @@ impl AppRunner {
|
||||
}
|
||||
|
||||
pub fn logic(&mut self) -> Result<(egui::Output, Vec<egui::ClippedMesh>), JsValue> {
|
||||
resize_canvas_to_screen_size(self.web_backend.canvas_id());
|
||||
resize_canvas_to_screen_size(self.web_backend.canvas_id(), self.app.max_size_points());
|
||||
let canvas_size = canvas_size_in_points(self.web_backend.canvas_id());
|
||||
let raw_input = self.input.new_frame(canvas_size);
|
||||
self.web_backend.begin_frame(raw_input);
|
||||
|
||||
@@ -123,15 +123,15 @@ pub fn canvas_size_in_points(canvas_id: &str) -> egui::Vec2 {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn resize_canvas_to_screen_size(canvas_id: &str) -> Option<()> {
|
||||
pub fn resize_canvas_to_screen_size(canvas_id: &str, max_size_points: egui::Vec2) -> Option<()> {
|
||||
let canvas = canvas_element(canvas_id)?;
|
||||
|
||||
let screen_size_points = screen_size_in_native_points()?;
|
||||
let pixels_per_point = native_pixels_per_point();
|
||||
|
||||
let max_size_pixels = pixels_per_point * max_size_points;
|
||||
|
||||
let canvas_size_pixels = pixels_per_point * screen_size_points;
|
||||
// Some browsers get slow with huge WebGL canvases, so we limit the size:
|
||||
let max_size_pixels = egui::vec2(2048.0, 4096.0);
|
||||
let canvas_size_pixels = canvas_size_pixels.min(max_size_pixels);
|
||||
let canvas_size_points = canvas_size_pixels / pixels_per_point;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user