diff --git a/Cargo.lock b/Cargo.lock index d9ae3e72e..017118f42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,7 +54,7 @@ checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618" [[package]] name = "acadrust" version = "0.3.4" -source = "git+https://github.com/HakanSeven12/acadrust?branch=main#5b09ccc00d92bb55dcccbef97c0fcecf94417e16" +source = "git+https://github.com/HakanSeven12/acadrust?branch=main#c117f98c3d33dc173e3ee01f39a7729d58bc0347" dependencies = [ "ahash", "anyhow", diff --git a/src/app/mod.rs b/src/app/mod.rs index 9b8ffa22e..a477ebff6 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -305,6 +305,12 @@ pub(super) struct OpenCADStudio { textstyle_width: String, /// Edit buffer for oblique angle (degrees). textstyle_oblique: String, + /// Edit buffer for fixed text height (0 = variable). + textstyle_height: String, + /// Edit buffer for big-font file name. + textstyle_bigfont: String, + /// Edit buffer for TrueType font name. + textstyle_ttf: String, // ── Color Scheme ────────────────────────────────────────────────────── active_theme: Theme, @@ -880,6 +886,9 @@ pub enum Message { TextStyleApply, /// Select a font from the built-in font list. TextStyleFontPick(String), + /// Flip a boolean flag on the selected text style (backward / upside_down / + /// vertical / annotative), applied immediately. + TextStyleToggle(&'static str), // ── TableStyle Dialog ───────────────────────────────────────────────── TableStyleDialogOpen, #[allow(dead_code)] @@ -1053,6 +1062,9 @@ impl OpenCADStudio { textstyle_font: String::new(), textstyle_width: "1.0".to_string(), textstyle_oblique: "0.0".to_string(), + textstyle_height: "0.0".to_string(), + textstyle_bigfont: String::new(), + textstyle_ttf: String::new(), // TableStyle dialog tablestyle_selected: "Standard".to_string(), // MLineStyle dialog diff --git a/src/app/update.rs b/src/app/update.rs index a8365333d..b18738092 100644 --- a/src/app/update.rs +++ b/src/app/update.rs @@ -5634,10 +5634,31 @@ impl OpenCADStudio { "font" => self.textstyle_font = value, "width" => self.textstyle_width = value, "oblique" => self.textstyle_oblique = value, + "height" => self.textstyle_height = value, + "bigfont" => self.textstyle_bigfont = value, + "ttf" => self.textstyle_ttf = value, _ => {} } Task::none() } + Message::TextStyleToggle(field) => { + let i = self.active_tab; + let name = self.textstyle_selected.clone(); + if self.tabs[i].scene.document.text_styles.get(&name).is_some() { + self.push_undo_snapshot(i, "STYLE EDIT"); + if let Some(s) = self.tabs[i].scene.document.text_styles.get_mut(&name) { + match field { + "backward" => s.flags.backward = !s.flags.backward, + "upside_down" => s.flags.upside_down = !s.flags.upside_down, + "annotative" => s.annotative = !s.annotative, + _ => {} + } + } + self.tabs[i].scene.bump_geometry(); + self.tabs[i].dirty = true; + } + Task::none() + } Message::TextStyleApply => { let i = self.active_tab; let name = self.textstyle_selected.clone(); @@ -5646,15 +5667,24 @@ impl OpenCADStudio { let font = self.textstyle_font.clone(); let width_str = self.textstyle_width.clone(); let oblique_str = self.textstyle_oblique.clone(); + let height_str = self.textstyle_height.clone(); + let bigfont = self.textstyle_bigfont.clone(); + let ttf = self.textstyle_ttf.clone(); if let Some(s) = self.tabs[i].scene.document.text_styles.get_mut(&name) { s.font_file = font; + s.big_font_file = bigfont; + s.true_type_font = ttf; if let Ok(w) = width_str.trim().parse::() { s.width_factor = w; } if let Ok(a) = oblique_str.trim().parse::() { s.oblique_angle = a.to_radians(); } + if let Ok(h) = height_str.trim().parse::() { + s.height = h.max(0.0); + } } + self.tabs[i].scene.bump_geometry(); self.tabs[i].dirty = true; } Task::none() @@ -6635,6 +6665,9 @@ impl OpenCADStudio { self.textstyle_font = s.font_file.clone(); self.textstyle_width = format!("{:.4}", s.width_factor); self.textstyle_oblique = format!("{:.2}", s.oblique_angle.to_degrees()); + self.textstyle_height = format!("{:.4}", s.height); + self.textstyle_bigfont = s.big_font_file.clone(); + self.textstyle_ttf = s.true_type_font.clone(); } } } diff --git a/src/app/view.rs b/src/app/view.rs index 49a3ecf67..4077bddab 100644 --- a/src/app/view.rs +++ b/src/app/view.rs @@ -65,13 +65,26 @@ impl OpenCADStudio { .iter() .map(|s| s.name.clone()) .collect(); - return crate::ui::textstyle::view_window( + let (backward, upside_down, annotative) = tab + .scene + .document + .text_styles + .get(&self.textstyle_selected) + .map(|s| (s.flags.backward, s.flags.upside_down, s.annotative)) + .unwrap_or((false, false, false)); + return crate::ui::textstyle::view_window(crate::ui::textstyle::TextStyleView { styles, - &self.textstyle_selected, - &self.textstyle_font, - &self.textstyle_width, - &self.textstyle_oblique, - ); + selected: &self.textstyle_selected, + font_buf: &self.textstyle_font, + width_buf: &self.textstyle_width, + oblique_buf: &self.textstyle_oblique, + height_buf: &self.textstyle_height, + bigfont_buf: &self.textstyle_bigfont, + ttf_buf: &self.textstyle_ttf, + backward, + upside_down, + annotative, + }); } if Some(window_id) == self.tablestyle_window { use acadrust::objects::ObjectType; diff --git a/src/ui/textstyle.rs b/src/ui/textstyle.rs index 8c4d45e07..83c49fed8 100644 --- a/src/ui/textstyle.rs +++ b/src/ui/textstyle.rs @@ -1,9 +1,24 @@ //! Text Style Font Browser window — fills the entire OS window. use crate::app::Message; -use iced::widget::{button, column, container, row, scrollable, text, text_input, Space}; +use iced::widget::{button, checkbox, column, container, row, scrollable, text, text_input, Space}; use iced::{Background, Border, Color, Element, Fill, Theme}; +/// View-model for the Text Style editor window. +pub struct TextStyleView<'a> { + pub styles: Vec, + pub selected: &'a str, + pub font_buf: &'a str, + pub width_buf: &'a str, + pub oblique_buf: &'a str, + pub height_buf: &'a str, + pub bigfont_buf: &'a str, + pub ttf_buf: &'a str, + pub backward: bool, + pub upside_down: bool, + pub annotative: bool, +} + const TB: Color = Color { r: 0.13, g: 0.13, @@ -169,13 +184,20 @@ fn vsep<'a>() -> Element<'a, Message> { .into() } -pub fn view_window<'a>( - styles: Vec, - selected: &'a str, - font_buf: &'a str, - width_buf: &'a str, - oblique_buf: &'a str, -) -> Element<'a, Message> { +pub fn view_window<'a>(v: TextStyleView<'a>) -> Element<'a, Message> { + let TextStyleView { + styles, + selected, + font_buf, + width_buf, + oblique_buf, + height_buf, + bigfont_buf, + ttf_buf, + backward, + upside_down, + annotative, + } = v; // ── Toolbar ─────────────────────────────────────────────────────────── let toolbar = container( row![ @@ -296,36 +318,48 @@ pub fn view_window<'a>( .height(Fill) .padding([12, 8]); + // Labeled numeric/text field row → TextStyleEdit { field, value }. + fn frow<'a>(label: &'a str, ph: &'a str, buf: &'a str, field: &'static str) -> Element<'a, Message> { + row![ + text(label).size(11).color(DIM).width(120), + text_input(ph, buf) + .on_input(move |v| Message::TextStyleEdit { field, value: v }) + .style(field_style) + .size(11) + .width(140), + ] + .spacing(6) + .align_y(iced::Center) + .into() + } + // ── Right: Properties ───────────────────────────────────────────────── let props_panel = container( column![ text("Properties").size(11).color(ACCENT), + frow("Big Font:", "big-font file…", bigfont_buf, "bigfont"), + frow("TrueType Font:", "e.g. Arial", ttf_buf, "ttf"), + frow("Fixed Height:", "0 = variable", height_buf, "height"), + frow("Width Factor:", "1.0", width_buf, "width"), + frow("Oblique (°):", "0.0", oblique_buf, "oblique"), row![ - text("Width Factor:").size(11).color(DIM).width(120), - text_input("1.0", width_buf) - .on_input(|v| Message::TextStyleEdit { - field: "width", - value: v - }) - .style(field_style) - .size(11) - .width(90), + checkbox(backward) + .label("Backward") + .on_toggle(|_| Message::TextStyleToggle("backward")) + .size(15) + .text_size(11), + checkbox(upside_down) + .label("Upside down") + .on_toggle(|_| Message::TextStyleToggle("upside_down")) + .size(15) + .text_size(11), ] - .spacing(6) - .align_y(iced::Center), - row![ - text("Oblique (°):").size(11).color(DIM).width(120), - text_input("0.0", oblique_buf) - .on_input(|v| Message::TextStyleEdit { - field: "oblique", - value: v - }) - .style(field_style) - .size(11) - .width(90), - ] - .spacing(6) - .align_y(iced::Center), + .spacing(16), + checkbox(annotative) + .label("Annotative") + .on_toggle(|_| Message::TextStyleToggle("annotative")) + .size(15) + .text_size(11), Space::new().height(8), text("Preview").size(10).color(DIM), container(text("AaBbCc 0123").size(20))