Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler warnings #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/about.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl WindowExt<UserEvent> for AboutWindow {

let mut context = EguiWinitWgpuContext::new(&window, event_loop)?;

let mut egui_ctx = context.context_mut();
let egui_ctx = context.context_mut();

let is_dark = theme == Theme::Dark;
if egui_ctx.style().visuals.dark_mode != is_dark {
Expand All @@ -49,7 +49,7 @@ impl WindowExt<UserEvent> for AboutWindow {
});
}

setup_fonts(&mut egui_ctx);
setup_fonts(egui_ctx);

Ok(Self { context, window })
}
Expand Down
38 changes: 14 additions & 24 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ impl App {
Event::RedrawRequested(window_id) => {
if window_id == self.window.id() {
self.core.redraw(&self.window);
} else {
if let Some(window) = self.sub_window_map.get_mut(&window_id) {
window.render();
}
} else if let Some(window) = self.sub_window_map.get_mut(&window_id) {
window.render();
}
}
Event::WindowEvent {
Expand All @@ -78,11 +76,9 @@ impl App {
} => {
if window_id == self.window.id() {
self.core.handle_window_event(event);
} else {
if let Some(window) = self.sub_window_map.get_mut(&window_id) {
if window.handle_window_event(event) {
window.request_redraw();
}
} else if let Some(window) = self.sub_window_map.get_mut(&window_id) {
if window.handle_window_event(event) {
window.request_redraw();
}
}

Expand All @@ -103,13 +99,11 @@ impl App {
}
}
WindowEvent::MouseInput { button, state, .. } => {
if window_id == self.window.id() {
match button {
MouseButton::Left => self
.core
.handle_mouse_input(*state == ElementState::Pressed),
_ => {}
}
let right_window = window_id == self.window.id();
let left_pressed = matches!(button, MouseButton::Left);
if right_window && left_pressed {
self.core
.handle_mouse_input(*state == ElementState::Pressed);
}
}
WindowEvent::Resized(physical_size) => {
Expand All @@ -119,10 +113,8 @@ impl App {
physical_size.height as f32,
self.window.scale_factor() as f32,
);
} else {
if let Some(window) = self.sub_window_map.get_mut(&window_id) {
window.on_resized(physical_size.width, physical_size.height);
}
} else if let Some(window) = self.sub_window_map.get_mut(&window_id) {
window.on_resized(physical_size.width, physical_size.height);
}
}
WindowEvent::ScaleFactorChanged {
Expand All @@ -137,10 +129,8 @@ impl App {
new_inner_size.height as f32,
*scale_factor as f32,
);
} else {
if let Some(window) = self.sub_window_map.get_mut(&window_id) {
window.on_scaled(*scale_factor as f32);
}
} else if let Some(window) = self.sub_window_map.get_mut(&window_id) {
window.on_scaled(*scale_factor as f32);
}
}
_ => {}
Expand Down
12 changes: 6 additions & 6 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Core {
.wgs()
.name()
.to_ascii_lowercase()
.replace(" ", "_"),
.replace(' ', "_"),
"png"
);
self.runtime.request_capture_image(
Expand Down Expand Up @@ -184,7 +184,7 @@ impl Core {
UserEvent::OpenExample(example) => {
let bytes = example.data();

match load_wgs_from_buffer(&bytes) {
match load_wgs_from_buffer(bytes) {
Ok(wgs) => {
self.wgs_path = None;

Expand Down Expand Up @@ -446,7 +446,7 @@ impl Core {

self.runtime.render_with(|device, queue, view| {
for (id, delta) in &full_output.textures_delta.set {
self.ui_renderer.update_texture(device, queue, *id, &delta);
self.ui_renderer.update_texture(device, queue, *id, delta);
}

let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
Expand Down Expand Up @@ -524,7 +524,7 @@ impl Core {
// Save as.
if let Some(path) = create_file(&format!(
"{}.{}",
wgs.name().to_ascii_lowercase().replace(" ", "_"),
wgs.name().to_ascii_lowercase().replace(' ', "_"),
wgs_core::EXTENSION
)) {
self.wgs_path = Some(path);
Expand All @@ -540,13 +540,13 @@ impl Core {
.wgs()
.name()
.to_ascii_lowercase()
.replace(" ", "_"),
.replace(' ', "_"),
wgs_core::EXTENSION
));
}

if self.wgs_path.is_some() {
save_wgs(&self.wgs_path.as_ref().unwrap(), &wgs);
save_wgs(self.wgs_path.as_ref().unwrap(), wgs);

self.change_status(AppStatus::Info(fl!("status_save_ok")));

Expand Down
2 changes: 1 addition & 1 deletion src/egui_winit_wgpu_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl EguiWinitWgpuContext {
pub fn new<T>(window: &Window, event_loop: &EventLoopWindowTarget<T>) -> Result<Self> {
let mut painter = Painter::new(WgpuConfiguration::default(), 1, None, true);

futures::executor::block_on(painter.set_window(Some(&window)))?;
futures::executor::block_on(painter.set_window(Some(window)))?;

let mut state = State::new(&event_loop);
state.set_pixels_per_point(window.scale_factor() as f32);
Expand Down
13 changes: 11 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::example::Example;
use std::fmt::Debug;
use winit::event_loop::EventLoopProxy;

#[derive(Clone, Debug)]
#[allow(dead_code)]
pub enum AppStatus {
Idle,
Info(String),
Expand Down Expand Up @@ -44,9 +46,16 @@ pub struct EventProxyWinit<T: 'static> {
inner: EventLoopProxy<T>,
}

impl<T> EventProxy<T> for EventProxyWinit<T> {
impl<T> EventProxy<T> for EventProxyWinit<T>
where
T: Debug,
{
fn send_event(&self, event: T) {
self.inner.send_event(event);
// Not sure if unwrap is the best idea here, but I don't know enough
// about the app to say other wise
//
// Feel free to replace
self.inner.send_event(event).unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd not recommand unwrap here, because it's not an issue that should panic.

In the long term, I think it would be a better idea to send the Result to the application layer and handle them there.

}
}

Expand Down
5 changes: 5 additions & 0 deletions src/ui/highlight/code_theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ impl Default for CodeTheme {
}
}

// WHY DO I NEED TO DO THIS??? They're public functions
//
// Anyways I do, if you make changes to this implementation make sure to remove this before you
// compile to check for any warnings
#[allow(dead_code)]
impl CodeTheme {
pub fn from_style(style: &Style) -> Self {
if style.visuals.dark_mode {
Expand Down
6 changes: 3 additions & 3 deletions src/ui/highlight.rs → src/ui/highlight/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Highlighter {

while !text.is_empty() {
if text.starts_with("//") {
let end = text.find("\n").unwrap_or(text.len());
let end = text.find('\n').unwrap_or(text.len());
job.append(&text[..end], 0.0, theme.format(TokenType::Comment));
text = &text[end..];
} else if text.starts_with("/*") {
Expand All @@ -49,7 +49,7 @@ impl Highlighter {
.map_or_else(|| text.len(), |i| i + 1);
job.append(&text[..end], 0.0, theme.format(TokenType::Whitespace));
text = &text[end..];
} else if text.starts_with("@") {
} else if text.starts_with('@') {
job.append("@", 0.0, theme.format(TokenType::Literal));
text = &text[1..];
let end = text[1..]
Expand All @@ -58,7 +58,7 @@ impl Highlighter {
let word = &text[..end];
job.append(word, 0.0, theme.format(TokenType::KeywordType));
text = &text[end..];
} else if text.starts_with("<") {
} else if text.starts_with('<') {
job.append("<", 0.0, theme.format(TokenType::Literal));
text = &text[1..];
is_inside_angle_bracket = true;
Expand Down
154 changes: 80 additions & 74 deletions src/ui/image_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,91 +44,92 @@ impl<'a> Widget for ImageUpload<'a> {
Stroke::new(self.rounding.min(self.size * 0.5), ui.visuals().window_fill),
);

if self.editable || self.removable {
if ui.rect_contains_pointer(rect) {
ui.put(rect, |ui: &mut Ui| {
ui.painter().rect_filled(
rect,
self.rounding,
Color32::from_rgba_premultiplied(20, 20, 20, 180),
let editable = self.editable;
let removable = self.removable;
let contains_pointer = ui.rect_contains_pointer(rect);

if (editable || removable) && contains_pointer {
ui.put(rect, |ui: &mut Ui| {
ui.painter().rect_filled(
rect,
self.rounding,
Color32::from_rgba_premultiplied(20, 20, 20, 180),
);

let mut content_size = Vec2::default();
let button_padding = ui.spacing().button_padding;

if self.editable {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems weird using editable in L51, but uses self.editable again here. Same L72, L82, L98, L114.

let (_text, size) = layout_text_widget(
ui,
icon_to_char(Icon::Edit).to_string(),
button_padding,
);

let mut content_size = Vec2::default();
let button_padding = ui.spacing().button_padding;

if self.editable {
let (_text, size) = layout_text_widget(
ui,
icon_to_char(Icon::Edit).to_string(),
button_padding,
);

content_size += size;
}

if self.removable {
let (_text, size) = layout_text_widget(
ui,
icon_to_char(Icon::Delete).to_string(),
button_padding,
);

content_size += size;
}

let button_count = if self.editable && self.removable {
2.0
} else {
1.0
};

let item_spacing = ui.spacing().item_spacing;
let content_size = vec2(
content_size[0] + (button_count - 1.0) * item_spacing.x,
content_size[1],
);

let content_rect = Rect::from_center_size(rect.center(), content_size);
content_size += size;
}

ui.allocate_ui_at_rect(content_rect, |ui| {
ui.horizontal_centered(|ui| {
if self.editable {
let resp = ui.button(icon_to_char(Icon::Edit).to_string());

let resp = if !self.edit_hint.is_empty() {
resp.on_hover_text(self.edit_hint)
} else {
resp
};
if self.removable {
let (_text, size) = layout_text_widget(
ui,
icon_to_char(Icon::Delete).to_string(),
button_padding,
);

if resp.clicked() {
if let Some(on_edit) = self.on_edit {
on_edit();
}
content_size += size;
}

let button_count = if self.editable && self.removable {
2.0
} else {
1.0
};

let item_spacing = ui.spacing().item_spacing;
let content_size = vec2(
content_size[0] + (button_count - 1.0) * item_spacing.x,
content_size[1],
);

let content_rect = Rect::from_center_size(rect.center(), content_size);

ui.allocate_ui_at_rect(content_rect, |ui| {
ui.horizontal_centered(|ui| {
if self.editable {
let resp = ui.button(icon_to_char(Icon::Edit).to_string());

let resp = if !self.edit_hint.is_empty() {
resp.on_hover_text(self.edit_hint)
} else {
resp
};

if resp.clicked() {
if let Some(on_edit) = self.on_edit {
on_edit();
}
}
}

if self.removable {
let resp =
ui.button(icon_to_char(Icon::Delete).to_string());
if self.removable {
let resp = ui.button(icon_to_char(Icon::Delete).to_string());

let resp = if !self.remove_hint.is_empty() {
resp.on_hover_text(self.remove_hint)
} else {
resp
};
let resp = if !self.remove_hint.is_empty() {
resp.on_hover_text(self.remove_hint)
} else {
resp
};

if resp.clicked() {
if let Some(on_remove) = self.on_remove {
on_remove();
}
if resp.clicked() {
if let Some(on_remove) = self.on_remove {
on_remove();
}
}
});
})
.response
});
}
}
});
})
.response
});
}
}
None => {
Expand Down Expand Up @@ -156,6 +157,11 @@ impl<'a> Widget for ImageUpload<'a> {
}
}

// WHY DO I NEED TO DO THIS??? They're public functions
//
// Anyways I do, if you make changes to this implementation make sure to remove this before you
// compile to check for any warnings
#[allow(dead_code)]
impl<'a> ImageUpload<'a> {
pub fn new(texture_id: Option<TextureId>) -> Self {
Self {
Expand Down
Loading