Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Track API changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Aug 30, 2023
1 parent 5b54797 commit 89c00aa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/com/telnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use web_time::Duration;
pub struct ComTelnetImpl {
tcp_stream: TcpStream,
state: ParserState,
window_size: Size<u16>, // width, height
window_size: Size, // width, height
terminal: Terminal,
use_raw_transfer: bool,
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Connection {
&self,
call_adr: &Address,
timeout: Duration,
window_size: icy_engine::Size<u16>,
window_size: icy_engine::Size,
) -> TerminalResult<()> {
self.tx
.send(SendData::OpenConnection(OpenConnectionData::from(
Expand Down Expand Up @@ -168,11 +168,11 @@ pub struct OpenConnectionData {
pub password: String,
pub protocol: crate::Protocol,
pub timeout: Duration,
pub window_size: icy_engine::Size<u16>,
pub window_size: icy_engine::Size,
}

impl OpenConnectionData {
pub fn from(call_adr: &Address, timeout: Duration, window_size: icy_engine::Size<u16>) -> Self {
pub fn from(call_adr: &Address, timeout: Duration, window_size: icy_engine::Size) -> Self {
Self {
address: call_adr.address.clone(),
user_name: call_adr.user_name.clone(),
Expand Down
43 changes: 26 additions & 17 deletions src/ui/dialogs/find_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use egui::{FontFamily, FontId, Rect, RichText, SelectableLabel, TextEdit, Ui, Vec2};
use i18n_embed_fl::fl;
use icy_engine::{AttributedChar, Buffer, BufferParser, Position, Selection};
use icy_engine::{AttributedChar, Buffer, BufferParser, Selection, UPosition};
use icy_engine_egui::BufferView;

#[derive(Default)]
Expand All @@ -11,8 +11,8 @@ pub struct DialogState {
pub case_sensitive: bool,

cur_sel: usize,
cur_pos: Position,
results: Vec<Position>,
cur_pos: UPosition,
results: Vec<UPosition>,
}

pub enum Message {
Expand All @@ -23,14 +23,14 @@ pub enum Message {
SetCasing(bool),
}

fn set_lead(sel: &mut Selection, pos: Position, len: usize) {
fn set_lead(sel: &mut Selection, pos: UPosition, len: usize) {
sel.set_lead(pos.x as f32 + len as f32, pos.y as f32);
}

impl DialogState {
pub fn search_pattern(&mut self, buf: &Buffer, buffer_parser: &dyn BufferParser) {
let mut cur_len = 0;
let mut start_pos = Position::default();
let mut start_pos = UPosition::default();
self.results.clear();
if self.pattern.is_empty() {
return;
Expand All @@ -43,18 +43,18 @@ impl DialogState {
}
for y in 0..buf.get_line_count() {
for x in 0..buf.get_width() {
let ch = buf.get_char_xy(x, y);
let ch = buf.get_char((x, y));
if self.compare(buffer_parser, cur_len, ch) {
if cur_len == 0 {
start_pos = Position::new(x, y);
start_pos = UPosition::new(x, y);
}
cur_len += 1;
if cur_len >= self.pattern.len() {
self.results.push(start_pos);
cur_len = 0;
}
} else if self.compare(buffer_parser, 0, ch) {
start_pos = Position::new(x, y);
start_pos = UPosition::new(x, y);
cur_len = 1;
} else {
cur_len = 0;
Expand Down Expand Up @@ -82,25 +82,25 @@ impl DialogState {
if self.results.is_empty() || self.pattern.is_empty() {
return;
}
self.cur_pos.x += 1;
for (i, pos) in self.results.iter().enumerate() {
if pos >= &self.cur_pos {
let mut sel = Selection::new(pos.x as f32, pos.y as f32);
set_lead(&mut sel, *pos, self.pattern.len());
buf.set_selection(sel);
self.cur_pos = *pos;
self.cur_pos.x += 1;
self.cur_sel = i;
return;
}
}
self.cur_pos = Position::new(-1, -1);
self.cur_pos = UPosition::default();
self.find_next(buf);
}

pub(crate) fn update_pattern(&mut self, buf: &mut BufferView) {
if let Some(sel) = buf.get_selection() {
if self.results.contains(&sel.anchor_pos) {
let p = sel.anchor_pos;
if self.results.contains(&sel.anchor_pos.as_uposition()) {
let p = sel.anchor_pos.as_uposition();
set_lead(sel, p, self.pattern.len());
return;
}
Expand All @@ -109,26 +109,35 @@ impl DialogState {
self.find_next(buf);
}

pub(crate) fn find_prev(&mut self, buf: &mut BufferView) {
pub(crate) fn find_prev(&mut self, buffer_view: &mut BufferView) {
if self.results.is_empty() || self.pattern.is_empty() {
return;
}
self.cur_pos.x -= 1;
let mut i = self.results.len() as i32 - 1;
let w = buffer_view.buf.get_width();
if self.cur_pos.x == 0 {
if self.cur_pos.y == 0 {
self.cur_pos = UPosition::new(usize::MAX, usize::MAX);
self.find_prev(buffer_view);
return;
}
self.cur_pos.y -= 1;
self.cur_pos.x = w - 1;
}

for pos in self.results.iter().rev() {
if pos < &self.cur_pos {
let mut sel = Selection::new(pos.x as f32, pos.y as f32);
set_lead(&mut sel, *pos, self.pattern.len());
buf.set_selection(sel);
buffer_view.set_selection(sel);
self.cur_pos = *pos;
self.cur_sel = i as usize;
return;
}
i -= 1;
}
self.cur_pos = Position::new(i32::MAX, i32::MAX);
self.find_prev(buf);
self.cur_pos = UPosition::new(usize::MAX, usize::MAX);
self.find_prev(buffer_view);
}

pub fn show_ui(&self, ui: &mut Ui, rect: Rect) -> Option<Message> {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/terminal_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl MainWindow {
let ch = buffer_view
.lock()
.buf
.get_char_xy(click_pos.x as i32, click_pos.y as i32);
.get_char((click_pos.x as usize, click_pos.y as usize));
println!("ch: {ch:?}");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/util/screen_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ impl ScreenMode {
}
}

pub fn get_window_size(&self) -> Size<u16> {
pub fn get_window_size(&self) -> Size {
match self {
// ScreenMode::Cga(w, h) | ScreenMode::Ega(w, h) |
ScreenMode::Vga(w, h) => {
Size::new(u16::try_from(*w).unwrap(), u16::try_from(*h).unwrap())
Size::new(*w as usize, *h as usize)
}
ScreenMode::Vic => Size::new(40, 25),
ScreenMode::Antic | ScreenMode::Videotex => Size::new(40, 24),
Expand Down

0 comments on commit 89c00aa

Please sign in to comment.