Skip to content

Commit

Permalink
Fixed widget UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Jan 18, 2025
1 parent 0fff53f commit a3209ec
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 117 deletions.
30 changes: 10 additions & 20 deletions crates/icy_draw/src/ui/dialogs/new_file_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ impl Template for Dos16Template {
buf.palette_mode = icy_engine::PaletteMode::Fixed16;
buf.font_mode = icy_engine::FontMode::Sauce;

let id = window.create_id();
let editor = AnsiEditor::new(&window.gl, id, buf);
let editor = AnsiEditor::new(&window.gl, buf);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -92,8 +91,7 @@ impl Template for Ice16Template {
buf.palette_mode = icy_engine::PaletteMode::Fixed16;
buf.font_mode = icy_engine::FontMode::Sauce;

let id = window.create_id();
let editor = AnsiEditor::new(&window.gl, id, buf);
let editor = AnsiEditor::new(&window.gl, buf);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -127,8 +125,7 @@ impl Template for XB16Template {
buf.palette_mode = icy_engine::PaletteMode::Free16;
buf.font_mode = icy_engine::FontMode::Single;

let id = window.create_id();
let editor = AnsiEditor::new(&window.gl, id, buf);
let editor = AnsiEditor::new(&window.gl, buf);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -162,8 +159,7 @@ impl Template for XBExtTemplate {
buf.palette_mode = icy_engine::PaletteMode::Free16;
buf.font_mode = icy_engine::FontMode::FixedSize;
buf.set_font(1, BitFont::default());
let id = window.create_id();
let editor = AnsiEditor::new(&window.gl, id, buf);
let editor = AnsiEditor::new(&window.gl, buf);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -197,8 +193,7 @@ impl Template for AnsiTemplate {
buf.palette_mode = icy_engine::PaletteMode::RGB;
buf.font_mode = icy_engine::FontMode::Unlimited;

let id = window.create_id();
let editor = AnsiEditor::new(&window.gl, id, buf);
let editor = AnsiEditor::new(&window.gl, buf);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -231,8 +226,7 @@ impl Template for FileIdTemplate {
buf.ice_mode = icy_engine::IceMode::Blink;
buf.palette_mode = icy_engine::PaletteMode::Fixed16;
buf.font_mode = icy_engine::FontMode::Sauce;
let id = window.create_id();
let editor = AnsiEditor::new(&window.gl, id, buf);
let editor = AnsiEditor::new(&window.gl, buf);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -276,8 +270,7 @@ impl Template for AtasciiTemplate {
buf.set_font(0, font);
buf.palette = Palette::from_slice(&ATARI_DEFAULT_PALETTE);

let id = window.create_id();
let editor = AnsiEditor::new(&window.gl, id, buf);
let editor = AnsiEditor::new(&window.gl, buf);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -323,7 +316,6 @@ impl Template for AnsiMationTemplate {
}

fn create_file(&self, window: &mut MainWindow<'_>) -> crate::TerminalResult<Option<Message>> {
let id = window.create_id();
let txt = r#"local buf = new_buffer(80, 25)
for i=0,9,1 do
Expand All @@ -333,7 +325,7 @@ for i=0,9,1 do
buf:print("Hello World " .. cur_frame)
next_frame(buf)
end"#;
let editor = crate::AnimationEditor::new(window.gl.clone(), id, Path::new("."), txt.into());
let editor = crate::AnimationEditor::new(window.gl.clone(), Path::new("."), txt.into());
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -363,7 +355,6 @@ impl Template for BitFontTemplate {
}

fn create_file(&self, window: &mut MainWindow<'_>) -> crate::TerminalResult<Option<Message>> {
let id = window.create_id();
let font = if self.width == 8 && self.height == 16 {
BitFont::default()
} else if self.width == 8 && self.height == 8 {
Expand All @@ -378,7 +369,7 @@ impl Template for BitFontTemplate {
&vec![0; 256 * self.height as usize],
)
};
let editor = crate::BitFontEditor::new(&window.gl, id, font);
let editor = crate::BitFontEditor::new(&window.gl, font);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down Expand Up @@ -431,9 +422,8 @@ impl Template for TdfFontTemplate {
}

fn create_file(&self, window: &mut MainWindow<'_>) -> crate::TerminalResult<Option<Message>> {
let id = window.create_id();
let fonts = vec![TheDrawFont::new(self.title(), self.font_type, 1)];
let editor = crate::CharFontEditor::new(&window.gl, id, fonts);
let editor = crate::CharFontEditor::new(&window.gl, fonts);
add_child(&mut window.document_tree, None, Box::new(editor));
Ok(None)
}
Expand Down
1 change: 0 additions & 1 deletion crates/icy_draw/src/ui/dialogs/settings_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ impl SettingsDialog {
let opt = icy_engine_gui::TerminalOptions {
stick_to_bottom: false,
scale: Some(Vec2::new(2.0, 2.0)),
id: Some(egui::Id::new(200 + id)),
terminal_size: Some(Vec2::new(font_dims.width as f32 * 10. * 2.0, font_dims.height as f32 * 2.0)),
force_focus: self.selected_view == i,
..Default::default()
Expand Down
1 change: 0 additions & 1 deletion crates/icy_draw/src/ui/editor/animation/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ pub fn start_encoding_thread(
let mut opt = icy_engine_gui::TerminalOptions {
stick_to_bottom: false,
scale: Some(Vec2::new(1.0, 1.0)),
id: Some(egui::Id::new("gif")),
..Default::default()
};

Expand Down
7 changes: 2 additions & 5 deletions crates/icy_draw/src/ui/editor/animation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use crate::{model::Tool, AnsiEditor, ClipboardHandler, Document, DocumentOptions, Message, TerminalResult, UndoHandler};
use eframe::{
egui::{self, Id, ImageButton, RichText, Slider, TextEdit, TopBottomPanel},
egui::{self, ImageButton, RichText, Slider, TextEdit, TopBottomPanel},
epaint::Vec2,
};
use egui::{Image, ProgressBar};
Expand All @@ -24,7 +24,6 @@ mod highlighting;

pub struct AnimationEditor {
gl: Arc<glow::Context>,
id: usize,

undostack: usize,

Expand Down Expand Up @@ -55,7 +54,7 @@ pub struct AnimationEditor {
}

impl AnimationEditor {
pub fn new(gl: Arc<glow::Context>, id: usize, path: &Path, txt: String) -> Self {
pub fn new(gl: Arc<glow::Context>, path: &Path, txt: String) -> Self {
let mut buffer = Buffer::new(Size::new(80, 25));
buffer.is_terminal_buffer = false;
let mut buffer_view = BufferView::from_buffer(&gl, buffer);
Expand All @@ -66,7 +65,6 @@ impl AnimationEditor {
let export_path = path.with_extension("gif");
Self {
gl,
id,
buffer_view,
animator,
txt,
Expand Down Expand Up @@ -294,7 +292,6 @@ impl Document for AnimationEditor {
stick_to_bottom: false,
scale: Some(scale),
monitor_settings,
id: Some(Id::new(self.id + 20000)),
..Default::default()
};
ui.allocate_ui(Vec2::new(ui.available_width(), ui.available_height() - 100.0), |ui| {
Expand Down
9 changes: 2 additions & 7 deletions crates/icy_draw/src/ui/editor/ansi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

use eframe::{
egui::{self, Id, Key, Response},
egui::{self, Key, Response},
epaint::{mutex::Mutex, Vec2},
};
use i18n_embed_fl::fl;
Expand Down Expand Up @@ -41,7 +41,6 @@ pub enum DragMode {
}

pub struct AnsiEditor {
pub id: usize,
pub drag_pos: DragPos,
pub half_block_click_pos: Position,
pub drag_started: DragMode,
Expand All @@ -54,7 +53,6 @@ pub struct AnsiEditor {
pub reference_image: Option<PathBuf>,
// pub outline_changed: std::boxed::Box<dyn Fn(&Editor)>,
//pub request_refresh: Box<dyn Fn ()>,
pub egui_id: Id,
pub next_scroll_x_position: Option<f32>,
pub next_scroll_y_position: Option<f32>,
pub guide: Option<Vec2>,
Expand Down Expand Up @@ -197,7 +195,6 @@ impl Document for AnsiEditor {
fit_width: options.fit_width,
monitor_settings: unsafe { SETTINGS.monitor_settings.clone() },
marker_settings: unsafe { SETTINGS.marker_settings.clone() },
id: Some(Id::new(self.id + 10000)),
raster: self.raster,
guide: self.guide,
scroll_offset_y: self.next_scroll_y_position.take(),
Expand Down Expand Up @@ -244,17 +241,15 @@ impl Document for AnsiEditor {
}

impl AnsiEditor {
pub fn new(gl: &Arc<glow::Context>, id: usize, buf: Buffer) -> Self {
pub fn new(gl: &Arc<glow::Context>, buf: Buffer) -> Self {
let buffer_view = Arc::new(Mutex::new(BufferView::from_buffer(gl, buf)));
// let buffer_parser = ansi::Parser::default();
AnsiEditor {
id,
buffer_view,
is_inactive: false,
reference_image: None,
drag_started: DragMode::Off,
drag_pos: DragPos::default(),
egui_id: Id::new(id),
guide: None,
raster: None,
outline_font_mode: false,
Expand Down
7 changes: 2 additions & 5 deletions crates/icy_draw/src/ui/editor/bitfont/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod undo;
use std::{path::Path, sync::Arc};

use eframe::{
egui::{self, Id, Layout, RichText, Sense},
egui::{self, Layout, RichText, Sense},
emath::Align2,
epaint::{mutex::Mutex, Color32, FontFamily, FontId, Pos2, Rect, Rounding, Vec2},
};
Expand All @@ -19,7 +19,6 @@ use crate::{model::Tool, to_message, AnsiEditor, ClipboardHandler, Document, Doc
use self::undo::UndoOperation;

pub struct BitFontEditor {
id: usize,
original_font: BitFont,
last_updated_font: BitFont,
font: BitFont,
Expand All @@ -45,7 +44,7 @@ pub enum DrawGlyphStyle {
}

impl BitFontEditor {
pub fn new(gl: &Arc<glow::Context>, id: usize, font: BitFont) -> Self {
pub fn new(gl: &Arc<glow::Context>, font: BitFont) -> Self {
let mut buffer = Buffer::new(Size::new(10, 10));
buffer.is_terminal_buffer = false;
let mut buffer_view = BufferView::from_buffer(gl, buffer);
Expand All @@ -54,7 +53,6 @@ impl BitFontEditor {
let size = font.size;
let last_updated_font = font.clone();
Self {
id,
buffer_view,
original_font: font.clone(),
last_updated_font,
Expand Down Expand Up @@ -593,7 +591,6 @@ impl Document for BitFontEditor {
scale: Some(Vec2::new(2.0, 2.0)),
monitor_settings: unsafe { SETTINGS.monitor_settings.clone() },
marker_settings: unsafe { SETTINGS.marker_settings.clone() },
id: Some(Id::new(self.id + 20000)),
..Default::default()
};
self.buffer_view.lock().get_caret_mut().set_is_visible(false);
Expand Down
7 changes: 2 additions & 5 deletions crates/icy_draw/src/ui/editor/charfont/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{
};

pub struct CharFontEditor {
id: usize,
font: BitFont,
selected_char_opt: Option<char>,
old_selected_char_opt: Option<char>,
Expand Down Expand Up @@ -291,7 +290,6 @@ impl Document for CharFontEditor {
scale: Some(Vec2::new(2.0, 2.0)),
monitor_settings: unsafe { SETTINGS.monitor_settings.clone() },
marker_settings: unsafe { SETTINGS.marker_settings.clone() },
id: Some(egui::Id::new(self.id + 20000)),
..Default::default()
};

Expand Down Expand Up @@ -433,10 +431,10 @@ fn set_attribute(layer: &mut Layer, attr: TextAttribute) {
}

impl CharFontEditor {
pub fn new(gl: &Arc<glow::Context>, id: usize, fonts: Vec<TheDrawFont>) -> Self {
pub fn new(gl: &Arc<glow::Context>, fonts: Vec<TheDrawFont>) -> Self {
let mut buffer = Buffer::new(Size::new(30, 12));
set_up_layers(&mut buffer);
let ansi_editor = AnsiEditor::new(gl, id, buffer);
let ansi_editor = AnsiEditor::new(gl, buffer);

let mut buffer = Buffer::new(Size::new(30, 12));
buffer.is_terminal_buffer = false;
Expand All @@ -445,7 +443,6 @@ impl CharFontEditor {
let outline_previewbuffer_view = Arc::new(Mutex::new(buffer_view));

let mut res = Self {
id,
font: BitFont::default(),
ansi_editor,
selected_char_opt: Some('A'),
Expand Down
20 changes: 4 additions & 16 deletions crates/icy_draw/src/ui/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,24 +207,18 @@ impl<'a> MainWindow<'a> {
}
let file_name_str = file_name.unwrap_or_default().to_str().unwrap_or_default().to_string();
if let Ok(font) = BitFont::from_bytes(file_name_str, data) {
let id = self.create_id();
add_child(
&mut self.document_tree,
Some(full_path.clone()),
Box::new(BitFontEditor::new(&self.gl, id, font)),
);
add_child(&mut self.document_tree, Some(full_path.clone()), Box::new(BitFontEditor::new(&self.gl, font)));
return;
}
}

if "icyanim" == ext {
let id = self.create_id();
match std::str::from_utf8(data) {
Ok(txt) => {
add_child(
&mut self.document_tree,
Some(full_path.clone()),
Box::new(crate::AnimationEditor::new(self.gl.clone(), id, full_path, txt.to_string())),
Box::new(crate::AnimationEditor::new(self.gl.clone(), full_path, txt.to_string())),
);
}
Err(err) => {
Expand All @@ -240,22 +234,16 @@ impl<'a> MainWindow<'a> {
return;
}
if let Ok(fonts) = TheDrawFont::from_tdf_bytes(data) {
let id = self.create_id();
add_child(
&mut self.document_tree,
Some(full_path.clone()),
Box::new(CharFontEditor::new(&self.gl, id, fonts)),
);
add_child(&mut self.document_tree, Some(full_path.clone()), Box::new(CharFontEditor::new(&self.gl, fonts)));
return;
}
}
}
}
match Buffer::from_bytes(file_name, true, data, None, terminal_width) {
Ok(mut buf) => {
let id = self.create_id();
buf.is_terminal_buffer = false;
let editor = AnsiEditor::new(&self.gl, id, buf);
let editor = AnsiEditor::new(&self.gl, buf);
add_child(&mut self.document_tree, full_path, Box::new(editor));
}
Err(err) => {
Expand Down
3 changes: 1 addition & 2 deletions crates/icy_draw/src/ui/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,9 @@ impl<'a> MainWindow<'a> {
layer.set_title(buf.layers[0].get_title());
buf.layers.clear();
buf.layers.push(layer);
let id = self.create_id();
buf.is_terminal_buffer = false;
buf.set_height(buf.get_line_count());
let editor = AnsiEditor::new(&self.gl, id, buf);
let editor = AnsiEditor::new(&self.gl, buf);
crate::add_child(&mut self.document_tree, None, Box::new(editor));
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/icy_draw/src/ui/tools/layer_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ impl LayerToolWindow {
scale: Some(Vec2::new(scale, scale)),
use_terminal_height: false,
hide_scrollbars: true,
id: Some(ui.id().with(i)),
clip_rect: Some(ui.clip_rect()),
..Default::default()
};
Expand Down
Loading

0 comments on commit a3209ec

Please sign in to comment.