Skip to content

Commit

Permalink
- fixed compile error
Browse files Browse the repository at this point in the history
- fixed visual bug with dark/light stripes being one pixel off
  • Loading branch information
RealRTTV committed Mar 24, 2024
1 parent 6b71b7d commit 3ae7453
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
15 changes: 6 additions & 9 deletions src/bookmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ impl Bookmarks {
pub struct BookmarkSlice([Bookmark]);

impl BookmarkSlice {
pub const EMPTY: &'static BookmarkSlice = unsafe { core::mem::transmute::<&[Bookmark], &Self>(&[]) };
pub const EMPTY_MUT: &'static mut BookmarkSlice = unsafe { core::mem::transmute::<&mut [Bookmark], &mut Self>(&mut []) };

#[inline]
pub fn increment(&mut self, value: usize, true_value: usize) {
for bookmark in &mut self.0 {
Expand Down Expand Up @@ -262,13 +259,13 @@ impl<R: RangeBounds<usize>> Index<R> for BookmarkSlice {
fn index(&self, index: R) -> &Self::Output {
match (index.start_bound().map(|&x| Bookmark::new(x, 0)), index.end_bound().map(|&x| Bookmark::new(x, 0))) {
(Bound::Unbounded, Bound::Unbounded) => self,
(Bound::Unbounded, Bound::Included(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY } else { slice!(self.0[..=end]) } },
(Bound::Unbounded, Bound::Included(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice!([]) } else { slice!(self.0[..=end]) } },
(Bound::Unbounded, Bound::Excluded(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); slice!(self.0[..end]) },
(Bound::Included(ref start), Bound::Unbounded) => { let start = self.binary_search(start).unwrap_or_else(identity); slice!(self.0[start..]) },
(Bound::Included(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY } else { slice!(self.0[start..=end]) } },
(Bound::Included(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice!([]) } else { slice!(self.0[start..=end]) } },
(Bound::Included(ref start), Bound::Excluded(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); slice!(self.0[start..end]) },
(Bound::Excluded(ref start), Bound::Unbounded) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); slice!(self.0[start..]) },
(Bound::Excluded(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY } else { slice!(self.0[start..=end]) } },
(Bound::Excluded(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice!([]) } else { slice!(self.0[start..=end]) } },
(Bound::Excluded(ref start), Bound::Excluded(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); slice!(self.0[start..end]) },
}
}
Expand All @@ -278,13 +275,13 @@ impl<R: RangeBounds<usize>> IndexMut<R> for BookmarkSlice {
fn index_mut(&mut self, index: R) -> &mut Self::Output {
match (index.start_bound().map(|&x| Bookmark::new(x, 0)), index.end_bound().map(|&x| Bookmark::new(x, 0))) {
(Bound::Unbounded, Bound::Unbounded) => self,
(Bound::Unbounded, Bound::Included(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY_MUT } else { slice_mut!(self.0[..=end]) } },
(Bound::Unbounded, Bound::Included(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice_mut!([]) } else { slice_mut!(self.0[..=end]) } },
(Bound::Unbounded, Bound::Excluded(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); slice_mut!(self.0[..end]) },
(Bound::Included(ref start), Bound::Unbounded) => { let start = self.binary_search(start).unwrap_or_else(identity); slice_mut!(self.0[start..]) },
(Bound::Included(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY_MUT } else { slice_mut!(self.0[start..=end]) } },
(Bound::Included(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice_mut!([]) } else { slice_mut!(self.0[start..=end]) } },
(Bound::Included(ref start), Bound::Excluded(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); slice_mut!(self.0[start..end]) },
(Bound::Excluded(ref start), Bound::Unbounded) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); slice_mut!(self.0[start..]) },
(Bound::Excluded(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY_MUT } else { slice_mut!(self.0[start..=end]) } },
(Bound::Excluded(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice_mut!([]) } else { slice_mut!(self.0[start..=end]) } },
(Bound::Excluded(ref start), Bound::Excluded(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); slice_mut!(self.0[start..end]) },
}
}
Expand Down
1 change: 0 additions & 1 deletion src/elements/compound.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::alloc::{alloc, Layout};
use std::cmp::Ordering;
use std::convert::identity;
use std::fmt::{Display, Formatter, Write};
use std::hash::Hasher;
use std::intrinsics::likely;
Expand Down
4 changes: 2 additions & 2 deletions src/workbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,7 @@ impl Workbench {
LIGHT_STRIPE_UV + (1, 1)
};
builder.draw_texture_region_z(
(0, n * 16 + HEADER_SIZE + (n > 0) as usize),
(0, n * 16 + HEADER_SIZE - (n == 0) as usize),
BASE_Z,
uv,
(builder.window_width(), 16 + (n == 0) as usize),
Expand Down Expand Up @@ -2324,7 +2324,7 @@ impl Workbench {
let mut ctx = RenderContext::new(selected_y, selected_key, selected_value, selecting_key, ghost, left_margin, (self.mouse_x, self.mouse_y), tab.freehand_mode);
if self.mouse_y >= HEADER_SIZE && self.action_wheel.is_none() {
builder.draw_texture_region_z(
(0, (self.mouse_y & !15) + 1),
(0, (self.mouse_y & !15)),
BASE_Z,
HOVERED_STRIPE_UV,
(builder.window_width(), 16),
Expand Down
1 change: 0 additions & 1 deletion src/workbench_action.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::convert::identity;
use std::mem::MaybeUninit;
use compact_str::{CompactString, ToCompactString};
use std::path::PathBuf;
Expand Down
3 changes: 1 addition & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import init, { open_file } from "./nbtworkbench.js?version=2";
await init();

const canvas = document.getElementById("canvas")[0];
const canvas = document.getElementById("canvas");

dialog.onchange = event => {
const file = event.target.files.item(0);
Expand All @@ -61,7 +61,6 @@
})
};


canvas.addEventListener("pointerdown", openDialog);
canvas.addEventListener("pointerup", openDialog);
canvas.addEventListener("keydown", openDialog);
Expand Down

0 comments on commit 3ae7453

Please sign in to comment.