Skip to content

Commit

Permalink
added icons
Browse files Browse the repository at this point in the history
  • Loading branch information
RealRTTV committed Feb 29, 2024
1 parent 207d72b commit 287eeb1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub const LONG_ARRAY_GHOST_UV: Vec2u = Vec2u::new(0, 48);
pub const CHUNK_GHOST_UV: Vec2u = Vec2u::new(64, 48);
pub const ALERT_UV: Vec2u = Vec2u::new(112, 144);
pub const BACKDROP_UV: Vec2u = Vec2u::new(32, 160);
pub const ADD_SEARCH_BOOKMARKS: Vec2u = Vec2u::new(48, 160);
pub const REMOVE_SEARCH_BOOKMARKS: Vec2u = Vec2u::new(64, 160);

pub const BASE_Z: u8 = 5;
pub const JUST_OVERLAPPING_BASE_Z: u8 = BASE_Z + 1;
Expand Down
Binary file modified src/assets/atlas.hex
Binary file not shown.
Binary file modified src/assets/build/atlas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#![feature(stmt_expr_attributes)]
#![feature(unchecked_math)]
#![feature(const_collections_with_hasher)]
#![feature(slice_first_last_chunk)]
#![feature(const_maybe_uninit_zeroed)]
#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")]

use std::cell::UnsafeCell;
Expand Down
23 changes: 17 additions & 6 deletions src/search_box.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::ops::{Deref, DerefMut};

use winit::keyboard::KeyCode;
use crate::assets::DARK_STRIPE_UV;
use crate::assets::{ADD_SEARCH_BOOKMARKS, DARK_STRIPE_UV, HOVERED_WIDGET_UV, REMOVE_SEARCH_BOOKMARKS, SELECTED_WIDGET_UV, UNSELECTED_WIDGET_UV};

use crate::color::TextColor;
use crate::StrExt;
use crate::{Bookmark, RenderContext, StrExt};
use crate::elements::element::NbtElement;
use crate::text::{Cachelike, KeyResult, Text};
use crate::vertex_buffer_builder::{Vec2u, VertexBufferBuilder};

Expand Down Expand Up @@ -68,16 +69,17 @@ impl SearchBox {
Self(Text::uninit())
}

pub fn render(&self, builder: &mut VertexBufferBuilder) {
pub fn render(&self, builder: &mut VertexBufferBuilder, shift: bool, pos: (usize, usize)) {
use std::fmt::Write;

let (mouse_x, mouse_y) = pos;
let pos = Vec2u::new(284, 23);

builder.draw_texture_region_z(
pos,
0,
DARK_STRIPE_UV,
(builder.window_width() - 215 - pos.x, 22),
(builder.window_width() - 215 - pos.x - 16, 22),
(16, 16),
);

Expand All @@ -95,6 +97,12 @@ impl SearchBox {
let _ = write!(builder, "{}", self.value);
}
builder.horizontal_scroll = 0;

let bookmark_uv = if shift { REMOVE_SEARCH_BOOKMARKS } else { ADD_SEARCH_BOOKMARKS };
let widget_uv = if (builder.window_width() - 215 - 16..builder.window_width() - 215).contains(&mouse_x) && (26..42).contains(&mouse_y) { HOVERED_WIDGET_UV } else { UNSELECTED_WIDGET_UV };

builder.draw_texture_z((builder.window_width() - 215 - 16, 26), 0, widget_uv, (16, 16));
builder.draw_texture_z((builder.window_width() - 215 - 16, 26), 0, bookmark_uv, (16, 16));
}

#[inline]
Expand Down Expand Up @@ -125,8 +133,11 @@ impl SearchBox {
}

#[inline]
pub fn search(&mut self) {
todo!()
pub fn search(&mut self, root: &NbtElement) -> Vec<Bookmark> {
let mut bookmarks = Vec::new();
let target = &*self.value;
root.search(|k, v| k.is_some_and(|k| k == target) || v.is_some_and(|v| v == target), 1, 0, &mut bookmarks);
bookmarks
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<Additional: Clone, Cache: Cachelike<Additional>> Text<Additional, Cache> {
editable: true,
undos: LinkedQueue::new(),
redos: LinkedQueue::new(),
additional: unsafe { core::mem::zeroed() },
additional: unsafe { core::mem::MaybeUninit::zeroed().assume_init() },
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/workbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ impl Workbench {
raw_window_height: 0,
window_width: 0,
raw_window_width: 0,
held_mouse_keys: FxHashSet::with_hasher(unsafe { core::mem::zeroed() }),
held_keys: FxHashSet::with_hasher(unsafe { core::mem::zeroed() }),
held_mouse_keys: FxHashSet::with_hasher(unsafe { core::mem::MaybeUninit::zeroed().assume_init() }),
held_keys: FxHashSet::with_hasher(unsafe { core::mem::MaybeUninit::zeroed().assume_init() }),
held_entry: HeldEntry::Empty,
cache_cursor_x: None,
tab_scroll: 0,
Expand Down Expand Up @@ -1346,7 +1346,7 @@ impl Workbench {

#[inline]
fn try_select_search_box(&mut self) -> bool {
if (283..self.window_width - 215).contains(&self.mouse_x) && (23..45).contains(&self.mouse_y) {
if (283..self.window_width - 215 - 16).contains(&self.mouse_x) && (23..45).contains(&self.mouse_y) {
self.search_box.select(self.mouse_x - 283);
true
} else {
Expand Down Expand Up @@ -1964,7 +1964,7 @@ impl Workbench {
}
KeyResult::Finish => {
self.search_box.post_input((self.window_width, self.window_height));
self.search_box.search();
self.search_box.search(&mut tab.value);
return true;
}
}
Expand Down Expand Up @@ -2343,7 +2343,7 @@ impl Workbench {
(2, 23),
(2, 16),
);
self.search_box.render(builder);
self.search_box.render(builder, self.held_keys.contains(&KeyCode::ShiftLeft) || self.held_keys.contains(&KeyCode::ShiftRight), (self.mouse_x, self.mouse_y));
}

builder.draw_texture_region_z(
Expand Down

0 comments on commit 287eeb1

Please sign in to comment.