Skip to content

Commit 5986d69

Browse files
geom3trikrhelmot
authored andcommitted
Add main widow before calling build closure (baseview)
1 parent 98355df commit 5986d69

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

crates/vizia_baseview/src/application.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::window::ViziaWindow;
2-
use crate::Renderer;
32
use baseview::{WindowHandle, WindowScalePolicy};
4-
use femtovg::Canvas;
53
use raw_window_handle::HasRawWindowHandle;
64

75
use crate::proxy::queue_get;
@@ -163,26 +161,15 @@ pub(crate) struct ApplicationRunner {
163161
}
164162

165163
impl ApplicationRunner {
166-
pub fn new(
167-
mut context: Context,
168-
win_desc: WindowDescription,
169-
scale_policy: WindowScalePolicy,
170-
renderer: Renderer,
171-
) -> Self {
172-
let mut cx = BackendContext::new(&mut context);
173-
164+
pub fn new(context: Context, scale_policy: WindowScalePolicy) -> Self {
174165
let event_manager = EventManager::new();
175166

176-
let canvas = Canvas::new(renderer).expect("Cannot create canvas");
177-
178167
// Assume scale for now until there is an event with a new one.
179168
let scale_factor = match scale_policy {
180169
WindowScalePolicy::ScaleFactor(scale) => scale,
181170
WindowScalePolicy::SystemScaleFactor => 1.0,
182171
};
183172

184-
cx.add_main_window(&win_desc, canvas, scale_factor as f32);
185-
186173
ApplicationRunner {
187174
event_manager,
188175
context,

crates/vizia_baseview/src/window.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,30 @@ impl ViziaWindow {
2424
builder: Option<Box<dyn FnOnce(&mut Context) + Send>>,
2525
on_idle: Option<Box<dyn Fn(&mut Context) + Send>>,
2626
) -> ViziaWindow {
27+
let context = window.gl_context().expect("Window was created without OpenGL support");
28+
let renderer = load_renderer(window);
29+
30+
unsafe { context.make_current() };
31+
32+
let canvas = Canvas::new(renderer).expect("Cannot create canvas");
33+
34+
// Assume scale for now until there is an event with a new one.
35+
let scale_factor = match scale_policy {
36+
WindowScalePolicy::ScaleFactor(scale) => scale,
37+
WindowScalePolicy::SystemScaleFactor => 1.0,
38+
};
39+
40+
BackendContext::new(&mut cx).add_main_window(&win_desc, canvas, scale_factor as f32);
41+
42+
cx.remove_user_themes();
2743
if let Some(builder) = builder {
2844
(builder)(&mut cx);
2945
}
3046

31-
let context = window.gl_context().expect("Window was created without OpenGL support");
32-
let renderer = load_renderer(window);
47+
let mut backend_cx = BackendContext::new(&mut cx);
48+
backend_cx.synchronize_fonts();
3349

34-
unsafe { context.make_current() };
35-
let application = ApplicationRunner::new(cx, win_desc, scale_policy, renderer);
50+
let application = ApplicationRunner::new(cx, scale_policy);
3651
unsafe { context.make_not_current() };
3752

3853
ViziaWindow { application, on_idle }

0 commit comments

Comments
 (0)