Skip to content

Commit

Permalink
core,desktop: Update to winit v0.30.5 and latest egui from git
Browse files Browse the repository at this point in the history
  • Loading branch information
torokati44 committed Sep 11, 2024
1 parent 0adbf65 commit a36927f
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 190 deletions.
365 changes: 215 additions & 150 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
naga = { version = "22.1.0", features = ["wgsl-out"] }
wgpu = "22.1.0"
egui = { git = "https://github.com/emilk/egui.git", rev = "37b1e1504db14697c39ce1c3bb5e58f4f2b819bf" }
egui = { git = "https://github.com/emilk/egui.git", rev = "f4697bc007447c6c2674beb4e25f599fb7afa093" }
clap = { version = "4.5.17", features = ["derive"] }
anyhow = "1.0"
slotmap = "1.0.7"
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ hashbrown = { version = "0.14.5", features = ["raw"] }
scopeguard = "1.2.0"
fluent-templates = "0.10.1"
egui = { workspace = true, optional = true }
egui_extras = { git = "https://github.com/emilk/egui.git", rev = "37b1e1504db14697c39ce1c3bb5e58f4f2b819bf", default-features = false, optional = true }
egui_extras = { git = "https://github.com/emilk/egui.git", rev = "f4697bc007447c6c2674beb4e25f599fb7afa093", default-features = false, optional = true }
png = { version = "0.17.13", optional = true }
flv-rs = { path = "../flv" }
async-channel = { workspace = true }
Expand Down
14 changes: 7 additions & 7 deletions core/src/debug_ui/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl DisplayObjectWindow {
ui.label("Focus Rect");
let focus_rect = object.focus_rect();
let mut new_focus_rect = focus_rect;
ComboBox::from_id_source(ui.id().with("focus_rect"))
ComboBox::from_id_salt(ui.id().with("focus_rect"))
.selected_text(optional_boolean_switch_value(focus_rect))
.show_ui(ui, |ui| {
for value in [None, Some(true), Some(false)] {
Expand Down Expand Up @@ -395,7 +395,7 @@ impl DisplayObjectWindow {
ui.label("Autosize");
ui.horizontal(|ui| {
let mut autosize = object.autosize();
ComboBox::from_id_source(ui.id().with("autosize"))
ComboBox::from_id_salt(ui.id().with("autosize"))
.selected_text(format!("{:?}", autosize))
.show_ui(ui, |ui| {
for value in [
Expand Down Expand Up @@ -476,7 +476,7 @@ impl DisplayObjectWindow {
});

CollapsingHeader::new("Span List")
.id_source(ui.id().with("spans"))
.id_salt(ui.id().with("spans"))
.show(ui, |ui| {
Grid::new(ui.id().with("spans"))
.num_columns(7)
Expand Down Expand Up @@ -598,7 +598,7 @@ impl DisplayObjectWindow {
});

CollapsingHeader::new("Frame List")
.id_source(ui.id().with("frames"))
.id_salt(ui.id().with("frames"))
.show(ui, |ui| {
Grid::new(ui.id().with("frames"))
.num_columns(5)
Expand Down Expand Up @@ -715,7 +715,7 @@ impl DisplayObjectWindow {
"automatic"
};
CollapsingHeader::new(format!("Tab Order ({})", tab_order_suffix))
.id_source(ui.id().with("tab_order"))
.id_salt(ui.id().with("tab_order"))
.show(ui, |ui| {
Grid::new(ui.id().with("tab_order_grid"))
.num_columns(3)
Expand Down Expand Up @@ -877,7 +877,7 @@ impl DisplayObjectWindow {
ui.label("Blend mode");
let old_blend = object.blend_mode();
let mut new_blend = old_blend;
ComboBox::from_id_source(ui.id().with("blendmode"))
ComboBox::from_id_salt(ui.id().with("blendmode"))
.selected_text(blend_mode_name(old_blend))
.show_ui(ui, |ui| {
for mode in ALL_BLEND_MODES {
Expand Down Expand Up @@ -921,7 +921,7 @@ impl DisplayObjectWindow {
let filters = object.filters();
if !filters.is_empty() {
CollapsingHeader::new(format!("Filters ({})", filters.len()))
.id_source(ui.id().with("filters"))
.id_salt(ui.id().with("filters"))
.show(ui, |ui| {
for filter in filters {
ui.label(format!("{:?}", filter));
Expand Down
2 changes: 1 addition & 1 deletion core/src/debug_ui/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl DomainListWindow {
}

CollapsingHeader::new(format!("Class {class_name}"))
.id_source(ui.id().with(class.0.as_ptr()))
.id_salt(ui.id().with(class.0.as_ptr()))
.show(ui, |ui| {
for class_obj in &*class.class_objects() {
let button = ui.button(format!("{class_obj:?}"));
Expand Down
2 changes: 1 addition & 1 deletion core/src/debug_ui/movie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl MovieWindow {

if !movie.parameters().is_empty() {
CollapsingHeader::new("Parameters")
.id_source(ui.id().with("parameters"))
.id_salt(ui.id().with("parameters"))
.default_open(false)
.show(ui, |ui| {
Grid::new(ui.id().with("parameters"))
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ unknown-git = "deny"
# github.com organizations to allow git sources for
github = [
"ruffle-rs",
# TODO: Remove once a release with https://github.com/emilk/egui/pull/4847 in it is out.
# TODO: Remove once a release with https://github.com/emilk/egui/pull/4939 in it is out.
"emilk",
# TODO: Remove once a release with https://github.com/PolyMeilex/rfd/pull/209 in it is out.
"PolyMeilex",
Expand Down
8 changes: 4 additions & 4 deletions desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ workspace = true
clap = { workspace = true }
cpal = "0.15.3"
egui = { workspace = true }
egui_extras = { git = "https://github.com/emilk/egui.git", rev = "37b1e1504db14697c39ce1c3bb5e58f4f2b819bf", default-features = false, features = ["image"] }
egui-wgpu = { git = "https://github.com/emilk/egui.git", rev = "37b1e1504db14697c39ce1c3bb5e58f4f2b819bf", features = ["winit"] }
egui_extras = { git = "https://github.com/emilk/egui.git", rev = "f4697bc007447c6c2674beb4e25f599fb7afa093", default-features = false, features = ["image"] }
egui-wgpu = { git = "https://github.com/emilk/egui.git", rev = "f4697bc007447c6c2674beb4e25f599fb7afa093", features = ["winit"] }
image = { workspace = true, features = ["png"] }
egui-winit = { git = "https://github.com/emilk/egui.git", rev = "37b1e1504db14697c39ce1c3bb5e58f4f2b819bf" }
egui-winit = { git = "https://github.com/emilk/egui.git", rev = "f4697bc007447c6c2674beb4e25f599fb7afa093" }
fontdb = "0.21"
ruffle_core = { path = "../core", features = ["audio", "clap", "mp3", "nellymoser", "default_compatibility_rules", "egui"] }
ruffle_render = { path = "../render", features = ["clap"] }
Expand All @@ -28,7 +28,7 @@ ruffle_frontend_utils = { path = "../frontend-utils" }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
tracing-appender = "0.2.3"
winit = "0.29.15"
winit = "0.30.5"
webbrowser = "1.0.1"
url = { workspace = true }
dirs = "5.0"
Expand Down
23 changes: 15 additions & 8 deletions desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use std::time::{Duration, Instant};
use url::Url;
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Size};
use winit::event::{ElementState, KeyEvent, Modifiers, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::keyboard::{Key, NamedKey};
use winit::window::{Fullscreen, Icon, Window, WindowBuilder};
use winit::window::{Fullscreen, Icon, Window, WindowAttributes};

pub struct App {
preferences: GlobalPreferences,
Expand All @@ -43,22 +43,26 @@ impl App {
let icon =
Icon::from_rgba(icon_bytes.to_vec(), 32, 32).context("Couldn't load app icon")?;

let event_loop = EventLoopBuilder::with_user_event().build()?;
let event_loop = EventLoop::with_user_event().build()?;

let no_gui = preferences.cli.no_gui;
let min_window_size = (16, if no_gui { 16 } else { MENU_HEIGHT + 16 }).into();
let max_window_size = get_screen_size(&event_loop);
let preferred_width = preferences.cli.width;
let preferred_height = preferences.cli.height;
let start_fullscreen = preferences.cli.fullscreen;

let window = WindowBuilder::new()
let window_attributes = WindowAttributes::default()
.with_visible(false)
.with_title("Ruffle")
.with_window_icon(Some(icon))
.with_min_inner_size(min_window_size)
.with_max_inner_size(max_window_size)
.build(&event_loop)?;
.with_min_inner_size(min_window_size);

// TODO: Migrate to ActiveEventLoop::create_window, see:
// https://github.com/rust-windowing/winit/releases/tag/v0.30.0
#[allow(deprecated)]
let window = event_loop.create_window(window_attributes)?;
let max_window_size = get_screen_size(&window);
window.set_max_inner_size(Some(max_window_size));
let window = Arc::new(window);

let mut font_database = fontdb::Database::default();
Expand Down Expand Up @@ -136,6 +140,9 @@ impl App {
// Poll UI events.
let event_loop = self.event_loop.take().expect("App already running");
let event_loop_proxy = event_loop.create_proxy();
// TODO: Migrate to `EventLoop::run_app` and `impl ApplicationHandler<RuffleEvent> for App`,
// see: https://github.com/rust-windowing/winit/releases/tag/v0.30.0
#[allow(deprecated)]
event_loop.run(move |event, elwt| {
let mut check_redraw = false;
match event {
Expand Down
10 changes: 8 additions & 2 deletions desktop/src/gui/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ impl GuiController {

let theme_controller =
ThemeController::new(window.clone(), preferences.clone(), egui_ctx.clone()).await;
let mut egui_winit =
egui_winit::State::new(egui_ctx, ViewportId::ROOT, window.as_ref(), None, None);
let mut egui_winit = egui_winit::State::new(
egui_ctx,
ViewportId::ROOT,
window.as_ref(),
None,
None,
None,
);
egui_winit.set_max_texture_side(descriptors.limits.max_texture_dimension_2d as usize);

let movie_view_renderer = Arc::new(MovieViewRenderer::new(
Expand Down
6 changes: 3 additions & 3 deletions desktop/src/gui/dialogs/open_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl OpenDialog {

// TODO: This should probably be a global setting somewhere, not per load
ui.label(text(locale, "open-url-mode"));
ComboBox::from_id_source("open-file-advanced-options-open-url-mode")
ComboBox::from_id_salt("open-file-advanced-options-open-url-mode")
.selected_text(match self.options.open_url_mode {
OpenURLMode::Allow => text(locale, "open-url-mode-allow"),
OpenURLMode::Confirm => text(locale, "open-url-mode-confirm"),
Expand Down Expand Up @@ -764,7 +764,7 @@ impl<T: Copy + PartialEq> InnerField for EnumDropdownField<T> {
}

fn ui(&self, ui: &mut Ui, value: &mut Self::Value, _error: bool, locale: &LanguageIdentifier) {
ComboBox::from_id_source(self.id)
ComboBox::from_id_salt(self.id)
.selected_text((self.value_to_name)(*value, locale))
.show_ui(ui, |ui| {
for possible_value in &self.possible_values {
Expand Down Expand Up @@ -811,7 +811,7 @@ impl InnerField for BooleanDropdownField {
}

fn ui(&self, ui: &mut Ui, value: &mut Self::Value, _error: bool, locale: &LanguageIdentifier) {
ComboBox::from_id_source(self.id)
ComboBox::from_id_salt(self.id)
.selected_text((self.value_to_name)(*value, locale))
.show_ui(ui, |ui| {
ui.selectable_value(value, false, (self.value_to_name)(false, locale));
Expand Down
14 changes: 7 additions & 7 deletions desktop/src/gui/dialogs/preferences_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl PreferencesDialog {
.on_hover_text(locked_text);
} else {
let previous = self.graphics_backend;
ComboBox::from_id_source("graphics-backend")
ComboBox::from_id_salt("graphics-backend")
.selected_text(graphics_backend_name(locale, self.graphics_backend))
.show_ui(ui, |ui| {
ui.selectable_value(
Expand Down Expand Up @@ -220,7 +220,7 @@ impl PreferencesDialog {
.on_hover_text(locked_text);
} else {
let previous = self.power_preference;
ComboBox::from_id_source("graphics-power")
ComboBox::from_id_salt("graphics-power")
.selected_text(graphics_power_name(locale, self.power_preference))
.show_ui(ui, |ui| {
ui.selectable_value(
Expand All @@ -244,7 +244,7 @@ impl PreferencesDialog {
fn show_language_preferences(&mut self, locale: &LanguageIdentifier, ui: &mut Ui) {
ui.label(text(locale, "language"));
let previous = self.language.clone();
ComboBox::from_id_source("language")
ComboBox::from_id_salt("language")
.selected_text(language_name(&self.language))
.show_ui(ui, |ui| {
for language in available_languages() {
Expand All @@ -264,7 +264,7 @@ impl PreferencesDialog {
fn show_theme_preferences(&mut self, locale: &LanguageIdentifier, ui: &mut Ui) {
ui.label(text(locale, "theme"));
let previous = self.theme_preference;
ComboBox::from_id_source("theme")
ComboBox::from_id_salt("theme")
.selected_text(theme_preference_name(locale, self.theme_preference))
.show_ui(ui, |ui| {
ui.selectable_value(
Expand Down Expand Up @@ -294,7 +294,7 @@ impl PreferencesDialog {

let previous = self.output_device.clone();
let default = text(locale, "audio-output-device-default");
ComboBox::from_id_source("audio-output-device")
ComboBox::from_id_salt("audio-output-device")
.selected_text(self.output_device.as_deref().unwrap_or(default.as_ref()))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.output_device, None, default);
Expand Down Expand Up @@ -350,7 +350,7 @@ impl PreferencesDialog {
ui.label(text(locale, "log-filename-pattern"));

let previous = self.log_filename_pattern;
ComboBox::from_id_source("log-filename-pattern")
ComboBox::from_id_salt("log-filename-pattern")
.selected_text(filename_pattern_name(locale, self.log_filename_pattern))
.show_ui(ui, |ui| {
ui.selectable_value(
Expand Down Expand Up @@ -383,7 +383,7 @@ impl PreferencesDialog {
.on_hover_text(locked_text);
} else {
let previous = self.storage_backend;
ComboBox::from_id_source("storage-backend")
ComboBox::from_id_salt("storage-backend")
.selected_text(storage_backend_name(locale, self.storage_backend))
.show_ui(ui, |ui| {
ui.selectable_value(
Expand Down
7 changes: 3 additions & 4 deletions desktop/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::custom_event::RuffleEvent;
use anyhow::{anyhow, Error};
use gilrs::Button;
use ruffle_core::events::{GamepadButton, KeyCode, TextControlCode};
use std::path::Path;
use url::Url;
use winit::dpi::PhysicalSize;
use winit::event::{KeyEvent, Modifiers};
use winit::event_loop::EventLoop;
use winit::keyboard::{Key, KeyLocation, NamedKey};
use winit::window::Window;

/// Converts a winit event to a Ruffle `TextControlCode`.
/// Returns `None` if there is no match.
Expand Down Expand Up @@ -205,13 +204,13 @@ pub fn gilrs_button_to_gamepad_button(button: Button) -> Option<GamepadButton> {
}
}

pub fn get_screen_size(event_loop: &EventLoop<RuffleEvent>) -> PhysicalSize<u32> {
pub fn get_screen_size(window: &Window) -> PhysicalSize<u32> {
let mut min_x = 0;
let mut min_y = 0;
let mut max_x = 0;
let mut max_y = 0;

for monitor in event_loop.available_monitors() {
for monitor in window.available_monitors() {
let size = monitor.size();
let position = monitor.position();
min_x = min_x.min(position.x);
Expand Down

0 comments on commit a36927f

Please sign in to comment.