Fix minor warnings and debug log
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
use std::{
|
||||
fmt::{self, Display}, ops::Deref
|
||||
};
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use iced::{
|
||||
advanced::{layout::{Limits, Node}, overlay, renderer::{Quad, Style}, text::Renderer, widget::{tree::{State, Tag}, Operation, Tree}, Clipboard, Layout, Shell, Text, Widget}, alignment::Vertical, keyboard::{key::Named, Key}, mouse::{Button, Cursor, Interaction, ScrollDelta}, widget::{column, lazy, text}, Color, Element, Event, Fill, Font, Length, Padding, Pixels, Point, Rectangle, Size, Task, Vector
|
||||
Color, Element, Event, Font, Length, Padding, Pixels, Point, Rectangle, Size, Task, Vector,
|
||||
advanced::{
|
||||
Clipboard, Layout, Shell, Text, Widget,
|
||||
layout::{Limits, Node},
|
||||
overlay,
|
||||
renderer::{Quad, Style},
|
||||
text::Renderer,
|
||||
widget::{
|
||||
Operation, Tree,
|
||||
tree::{State, Tag},
|
||||
},
|
||||
},
|
||||
alignment::Vertical,
|
||||
keyboard::{Key, key::Named},
|
||||
mouse::{Button, Cursor, Interaction, ScrollDelta},
|
||||
};
|
||||
// use iced_core::{
|
||||
// Clipboard, Color, Event, Layout, Length, Pixels, Point, Rectangle, Shell, Size, Text, Vector,
|
||||
// Widget,
|
||||
// layout::{Limits, Node},
|
||||
// mouse::{Cursor, Interaction},
|
||||
// overlay,
|
||||
// renderer::{Quad, Style},
|
||||
// widget::{
|
||||
// Operation, Tree,
|
||||
// tree::{State, Tag},
|
||||
// },
|
||||
// };
|
||||
use nes_emu::Memory;
|
||||
|
||||
use nes_emu::{PPU, Mapped, PPUMMRegisters};
|
||||
use nes_emu::{Mapped, PPU, PPUMMRegisters};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
struct Cpu<'a>(&'a Mapped);
|
||||
@@ -82,53 +82,53 @@ pub enum HexEvent {}
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct HexView {}
|
||||
|
||||
struct Val(Option<u8>);
|
||||
impl fmt::Display for Val {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if let Some(val) = self.0 {
|
||||
write!(f, "{:02X}", val)
|
||||
} else {
|
||||
write!(f, "XX")
|
||||
}
|
||||
}
|
||||
}
|
||||
// struct Val(Option<u8>);
|
||||
// impl fmt::Display for Val {
|
||||
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// if let Some(val) = self.0 {
|
||||
// write!(f, "{:02X}", val)
|
||||
// } else {
|
||||
// write!(f, "XX")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
impl HexView {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
// pub fn new() -> Self {
|
||||
// Self {}
|
||||
// }
|
||||
|
||||
pub fn render_any<'a, M: Memory + Copy + 'a>(&self, mem: M) -> Element<'a, HexEvent> {
|
||||
struct Row<M: Memory>(usize, M);
|
||||
impl<'a, M: Memory + 'a> fmt::Display for Row<M> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", Val(self.1.peek(self.0)))?;
|
||||
for i in 1..16 {
|
||||
write!(f, " {}", Val(self.1.peek(self.0 + i)))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
column![
|
||||
text!("Hex view"),
|
||||
iced::widget::scrollable(lazy(mem.edit_ver(), move |_| column(
|
||||
[
|
||||
text!(" | 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F")
|
||||
.font(Font::MONOSPACE)
|
||||
.into()
|
||||
]
|
||||
.into_iter()
|
||||
.chain((0..mem.len()).step_by(16).map(|off| {
|
||||
text!(" {off:04X} | {}", Row(off, mem))
|
||||
.font(Font::MONOSPACE)
|
||||
.into()
|
||||
}))
|
||||
)))
|
||||
.width(Fill),
|
||||
]
|
||||
.width(Fill)
|
||||
.into()
|
||||
}
|
||||
// pub fn render_any<'a, M: Memory + Copy + 'a>(&self, mem: M) -> Element<'a, HexEvent> {
|
||||
// struct Row<M: Memory>(usize, M);
|
||||
// impl<'a, M: Memory + 'a> fmt::Display for Row<M> {
|
||||
// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// write!(f, "{}", Val(self.1.peek(self.0)))?;
|
||||
// for i in 1..16 {
|
||||
// write!(f, " {}", Val(self.1.peek(self.0 + i)))?;
|
||||
// }
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
// column![
|
||||
// text!("Hex view"),
|
||||
// iced::widget::scrollable(lazy(mem.edit_ver(), move |_| column(
|
||||
// [
|
||||
// text!(" | 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F")
|
||||
// .font(Font::MONOSPACE)
|
||||
// .into()
|
||||
// ]
|
||||
// .into_iter()
|
||||
// .chain((0..mem.len()).step_by(16).map(|off| {
|
||||
// text!(" {off:04X} | {}", Row(off, mem))
|
||||
// .font(Font::MONOSPACE)
|
||||
// .into()
|
||||
// }))
|
||||
// )))
|
||||
// .width(Fill),
|
||||
// ]
|
||||
// .width(Fill)
|
||||
// .into()
|
||||
// }
|
||||
pub fn render_cpu<'a>(&self, mem: &'a Mapped) -> Element<'a, HexEvent> {
|
||||
// self.render_any(Cpu(mem))
|
||||
Element::new(
|
||||
@@ -147,35 +147,35 @@ impl HexView {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, ev: HexEvent) -> Task<HexEvent> {
|
||||
pub fn update(&mut self, _ev: HexEvent) -> Task<HexEvent> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BufferSlice<'a>(pub &'a [u8]);
|
||||
// pub struct BufferSlice<'a>(pub &'a [u8]);
|
||||
|
||||
impl Deref for BufferSlice<'_> {
|
||||
type Target = [u8];
|
||||
// impl Deref for BufferSlice<'_> {
|
||||
// type Target = [u8];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
// fn deref(&self) -> &Self::Target {
|
||||
// self.0
|
||||
// }
|
||||
// }
|
||||
|
||||
pub trait Buffer {
|
||||
fn peek(&self, val: usize) -> Option<u8>;
|
||||
fn len(&self) -> usize;
|
||||
}
|
||||
|
||||
impl Buffer for BufferSlice<'_> {
|
||||
fn peek(&self, val: usize) -> Option<u8> {
|
||||
self.get(val).copied()
|
||||
}
|
||||
// impl Buffer for BufferSlice<'_> {
|
||||
// fn peek(&self, val: usize) -> Option<u8> {
|
||||
// self.get(val).copied()
|
||||
// }
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.iter().len()
|
||||
}
|
||||
}
|
||||
// fn len(&self) -> usize {
|
||||
// self.iter().len()
|
||||
// }
|
||||
// }
|
||||
impl<M: Memory> Buffer for M {
|
||||
fn peek(&self, val: usize) -> Option<u8> {
|
||||
self.peek(val)
|
||||
@@ -202,6 +202,7 @@ pub struct HexEdit {
|
||||
new_value: u8,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct HexEditor<B, M, R: Renderer> {
|
||||
val: B,
|
||||
font_size: Option<Pixels>,
|
||||
@@ -279,6 +280,7 @@ where
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[allow(dead_code)]
|
||||
struct HexEditorState {
|
||||
offset_y: f32,
|
||||
selected: usize,
|
||||
@@ -311,10 +313,10 @@ where
|
||||
&self,
|
||||
tree: &Tree,
|
||||
renderer: &mut R,
|
||||
theme: &T,
|
||||
style: &Style,
|
||||
_theme: &T,
|
||||
_style: &Style,
|
||||
layout: Layout<'_>,
|
||||
cursor: Cursor,
|
||||
_cursor: Cursor,
|
||||
viewport: &Rectangle,
|
||||
) {
|
||||
let state: &HexEditorState = tree.state.downcast_ref();
|
||||
|
||||
Reference in New Issue
Block a user