Skip to content

Commit e5f1cbf

Browse files
committed
Small updates
- add label rotation - add points label text independant of points name - remove label entry type - remove inlined node Expr field - redraw on style changes and removing points - nicer short expr edit boxes - support (by default) point lines not being selectable
1 parent 55f9008 commit e5f1cbf

8 files changed

Lines changed: 506 additions & 303 deletions

File tree

src/app_ui.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,13 @@ pub fn graph_panel<T: EvalexprFloat>(
562562

563563
let plot_res = plot.show(ui, |plot_ui| {
564564
scope!("graph_show");
565-
plot_ui.hline(HLine::new("", 0.0).color(Color32::WHITE));
566-
plot_ui.vline(VLine::new("", 0.0).color(Color32::WHITE));
565+
566+
if ui_state.graph_config.show_grid[0] {
567+
plot_ui.hline(HLine::new("", 0.0).color(Color32::WHITE));
568+
}
569+
if ui_state.graph_config.show_grid[1] {
570+
plot_ui.vline(VLine::new("", 0.0).color(Color32::WHITE));
571+
}
567572
for mesh in ui_state.processed_shapess.draw_meshes.iter() {
568573
match &mesh.ty {
569574
DrawMeshType::EguiPlotMesh(mesh) => {
@@ -623,7 +628,7 @@ pub fn graph_panel<T: EvalexprFloat>(
623628
plot_ui.points(draw_point.points);
624629
}
625630
for draw_text in ui_state.processed_shapess.draw_texts.iter() {
626-
plot_ui.text(draw_text.text.clone());
631+
plot_ui.add(draw_text.text.clone());
627632
}
628633
});
629634

@@ -649,7 +654,7 @@ pub fn graph_panel<T: EvalexprFloat>(
649654

650655
if force_create_elements || changed {
651656
scope!("schedule_entry_create_plot_elements");
652-
ui_state.eval_errors.clear();
657+
ui_state.eval_errors.clear();
653658
let plot_params = entry::PlotParams::new(ui_state);
654659
let main_context = Arc::new(state.ctx.clone());
655660
for (i, entry) in state.entries.iter_mut().enumerate() {
@@ -665,6 +670,7 @@ pub fn graph_panel<T: EvalexprFloat>(
665670
ui_state.force_process_elements = true;
666671
}
667672

673+
let mut dragging_point = false;
668674
if let Some(drag_result) = point_dragging(
669675
&mut state.entries,
670676
&mut state.ctx,
@@ -673,6 +679,7 @@ pub fn graph_panel<T: EvalexprFloat>(
673679
hovered_point.as_ref(),
674680
&plot_params,
675681
) {
682+
dragging_point = true;
676683
state.clear_cache = true;
677684
ui_state.showing_custom_label = true;
678685
let screen_x = plot_res.transform.position_from_point_x(drag_result.x);
@@ -725,7 +732,10 @@ pub fn graph_panel<T: EvalexprFloat>(
725732
);
726733
}
727734

728-
if let Some(hovered_id) = plot_res.hovered_plot_item.or(p_draw_buffer.hovered_id) {
735+
if let Some(hovered_id) = plot_res.hovered_plot_item.or(p_draw_buffer.hovered_id) && hovered_point.is_none(){
736+
// if dragging_point {
737+
// ui_state.selected_plot_line = None;
738+
// }
729739
if plot_res.response.clicked()
730740
|| plot_res.response.drag_started()
731741
|| (ui_state.selected_plot_line.is_none() && plot_res.response.is_pointer_button_down_on())
@@ -806,11 +816,6 @@ fn add_new_entry_btn<T: EvalexprFloat>(
806816
*next_id += 1;
807817
needs_recompilation = true;
808818
}
809-
let new_label = Entry::new_label(*next_id);
810-
if ui.button(new_label.symbol_with_name()).clicked() {
811-
entries.push(new_label);
812-
*next_id += 1;
813-
}
814819
if can_add_folder {
815820
let new_folder = Entry::new_folder(*next_id);
816821
if ui.button(new_folder.symbol_with_name()).clicked() {

src/draw_buffer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::entry::{Entry, EntryType};
1919
use crate::marching_squares::MeshBuilder;
2020
use crate::math::{closest_point_on_segment, dist_sq, intersect_segs};
2121
use crate::thread_local_get;
22+
use crate::widgets::TextPlotItem;
2223

2324
pub struct ProcessedShapes {
2425
tesselator: eframe::epaint::Tessellator,
@@ -773,10 +774,10 @@ impl DrawPolygonGroup {
773774
}
774775
#[derive(Clone)]
775776
pub struct DrawText {
776-
pub text: egui_plot::Text,
777+
pub text: TextPlotItem,
777778
}
778779
impl DrawText {
779-
pub fn new(text: egui_plot::Text) -> Self { Self { text } }
780+
pub fn new(text: TextPlotItem) -> Self { Self { text } }
780781
}
781782

782783
/// SAFETY: Not Sync because of `ExplicitGenerator` callbacks, but we dont use those.

src/entry.rs

Lines changed: 57 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ pub struct Expr<T: EvalexprFloat> {
106106
pub text: String,
107107
pub display_rational: bool,
108108
pub node: Option<FlatNode<T>>,
109-
pub inlined_node: Option<FlatNode<T>>,
110109
pub expr_function: Option<ExpressionFunction<T>>,
111110
pub args: Vec<IStr>,
112111
pub equation_type: EquationType,
@@ -118,7 +117,6 @@ impl<T: EvalexprFloat> Default for Expr<T> {
118117
text: Default::default(),
119118
display_rational: false,
120119
node: Default::default(),
121-
inlined_node: Default::default(),
122120
args: Default::default(),
123121
expr_function: Default::default(),
124122
equation_type: Default::default(),
@@ -132,21 +130,14 @@ impl<T: EvalexprFloat> Expr<T> {
132130
// if unoptimized node is constant, no need to display it
133131
return None;
134132
}
135-
if let Some(func) = &self.expr_function {
136-
func.as_constant()
137-
} else if let Some(inlined_node) = &self.inlined_node {
138-
inlined_node.as_constant()
139-
} else {
140-
None
141-
}
133+
if let Some(func) = &self.expr_function { func.as_constant() } else { None }
142134
}
143135
fn from_text(text: &str) -> Self {
144136
// TODO preprocess here too
145137
Self {
146138
node: evalexpr::build_flat_node::<T>(text).ok(),
147139
equation_type: EquationType::None,
148140
display_rational: false,
149-
inlined_node: None,
150141
expr_function: None,
151142
text: text.to_string(),
152143
args: Vec::new(),
@@ -176,7 +167,6 @@ pub enum FunctionType {
176167
pub enum EntryType<T: EvalexprFloat> {
177168
Function {
178169
can_be_drawn: bool,
179-
selectable: bool,
180170
identifier: IStr,
181171
func: Expr<T>,
182172
style: LineStyleConfig,
@@ -204,36 +194,30 @@ pub enum EntryType<T: EvalexprFloat> {
204194
Points {
205195
identifier: IStr,
206196
points: Vec<PointEntry<T>>,
207-
style: PointStyle,
208-
},
209-
Label {
210-
x: Expr<T>,
211-
y: Expr<T>,
212-
size: Expr<T>,
213-
underline: bool,
197+
style: PointStyle<T>,
214198
},
215199
Folder {
216200
entries: Vec<Entry<T>>,
217201
},
218202
}
219203

220-
#[derive(Clone, Default, PartialEq, Debug, Serialize, Deserialize)]
204+
#[derive(Clone, Copy, Default, PartialEq, Debug, Serialize, Deserialize)]
221205
pub enum LabelSize {
222206
#[default]
223207
Small,
224208
Medium,
225209
Large,
226210
}
227211
impl LabelSize {
228-
pub fn size(&self) -> f32 {
212+
pub fn size(self) -> f32 {
229213
match self {
230214
LabelSize::Small => 10.0,
231215
LabelSize::Medium => 16.0,
232216
LabelSize::Large => 20.0,
233217
}
234218
}
235219
}
236-
#[derive(Clone, Default, PartialEq, Debug, Serialize, Deserialize)]
220+
#[derive(Clone, Copy, Default, PartialEq, Debug, Serialize, Deserialize)]
237221
pub enum LabelPosition {
238222
#[default]
239223
Bottom,
@@ -244,9 +228,10 @@ pub enum LabelPosition {
244228
TRight,
245229
BLeft,
246230
BRight,
231+
Center,
247232
}
248233
impl LabelPosition {
249-
fn symbol(&self) -> &'static str {
234+
fn symbol(self) -> &'static str {
250235
match self {
251236
LabelPosition::Top => "⮉",
252237
LabelPosition::Bottom => "⮋",
@@ -256,9 +241,10 @@ impl LabelPosition {
256241
LabelPosition::TRight => "⬈",
257242
LabelPosition::BLeft => "⬋",
258243
LabelPosition::BRight => "⬊",
244+
LabelPosition::Center => "o",
259245
}
260246
}
261-
fn dir(&self) -> egui::Vec2 {
247+
fn dir(self) -> egui::Vec2 {
262248
match self {
263249
LabelPosition::Top => egui::Vec2::new(0.0, 1.0),
264250
LabelPosition::Bottom => egui::Vec2::new(0.0, -1.0),
@@ -268,45 +254,51 @@ impl LabelPosition {
268254
LabelPosition::TRight => egui::Vec2::new(0.71, 0.71),
269255
LabelPosition::BLeft => egui::Vec2::new(-0.71, -0.71),
270256
LabelPosition::BRight => egui::Vec2::new(0.71, -0.71),
257+
LabelPosition::Center => egui::Vec2::new(0.0, 0.0),
271258
}
272259
}
273260
}
274261

275-
#[derive(Clone, Default, PartialEq, Debug, Serialize, Deserialize)]
276-
pub struct LabelConfig {
277-
#[serde(default)]
278-
size: LabelSize,
279-
#[serde(default)]
280-
pos: LabelPosition,
281-
#[serde(default)]
282-
italic: bool,
262+
#[derive(Clone, Debug)]
263+
pub struct LabelConfig<T: EvalexprFloat> {
264+
pub text: String,
265+
pub size: LabelSize,
266+
pub pos: LabelPosition,
267+
pub italic: bool,
268+
pub angle: Expr<T>,
269+
}
270+
impl<T: EvalexprFloat> Default for LabelConfig<T> {
271+
fn default() -> Self {
272+
Self {
273+
text: String::new(),
274+
size: LabelSize::Small,
275+
pos: LabelPosition::Bottom,
276+
italic: false,
277+
angle: Expr::default(),
278+
}
279+
}
283280
}
284281

285-
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
286-
pub struct PointStyle {
287-
show_lines: bool,
288-
#[serde(default)]
289-
show_arrows: bool,
290-
show_points: bool,
291-
line_style: LineStyleConfig,
292-
#[serde(default)]
293-
label_config: Option<LabelConfig>,
294-
#[serde(default)]
295-
fill: bool,
296-
#[serde(default)]
297-
fill_rule: FillRule,
298-
#[serde(default)]
299-
connect_first_and_last: bool,
282+
#[derive(Clone, Debug)]
283+
pub struct PointStyle<T: EvalexprFloat> {
284+
pub show_lines: bool,
285+
pub show_arrows: bool,
286+
pub show_points: bool,
287+
pub line_style: LineStyleConfig,
288+
pub label_config: Option<LabelConfig<T>>,
289+
pub fill: bool,
290+
pub fill_rule: FillRule,
291+
pub connect_first_and_last: bool,
300292
}
301293

302-
impl Default for PointStyle {
294+
impl<T: EvalexprFloat> Default for PointStyle<T> {
303295
fn default() -> Self {
304296
Self {
305297
show_lines: true,
306298
show_points: true,
307299
show_arrows: false,
308-
label_config: Some(LabelConfig::default()),
309-
line_style: LineStyleConfig::default(),
300+
label_config: None,
301+
line_style: LineStyleConfig::new(false),
310302
fill: false,
311303
connect_first_and_last: false,
312304
fill_rule: FillRule::default(),
@@ -323,13 +315,27 @@ pub enum LineStyleType {
323315
}
324316
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
325317
pub struct LineStyleConfig {
318+
#[serde(default)]
319+
selectable: bool,
326320
line_width: f32,
327321
#[serde(default)]
328322
line_style: LineStyleType,
329323
line_style_size: f32,
330324
}
331325
impl Default for LineStyleConfig {
332-
fn default() -> Self { Self { line_width: 1.5, line_style: LineStyleType::Solid, line_style_size: 5.5 } }
326+
fn default() -> Self {
327+
Self {
328+
selectable: false,
329+
line_width: 1.5,
330+
line_style: LineStyleType::Solid,
331+
line_style_size: 5.5,
332+
}
333+
}
334+
}
335+
impl LineStyleConfig {
336+
fn new(selectable: bool) -> Self {
337+
Self { selectable, ..Self::default()}
338+
}
333339
}
334340
impl LineStyleConfig {
335341
fn egui_line_style(&self) -> egui_plot::LineStyle {
@@ -353,7 +359,6 @@ impl<T: EvalexprFloat> Entry<T> {
353359
}
354360
},
355361
EntryType::Points { .. } => "◊",
356-
EntryType::Label { .. } => "📃",
357362
EntryType::Folder { .. } => {
358363
if self.active {
359364
"📂"
@@ -368,7 +373,6 @@ impl<T: EvalexprFloat> Entry<T> {
368373
EntryType::Function { .. } => "λ Function",
369374
EntryType::Constant { .. } => "⏵ Constant",
370375
EntryType::Points { .. } => "◊ Points",
371-
EntryType::Label { .. } => "📃 Label",
372376
EntryType::Folder { .. } => "📂 Folder",
373377
}
374378
}
@@ -377,7 +381,6 @@ impl<T: EvalexprFloat> Entry<T> {
377381
EntryType::Function { .. } => "Function",
378382
EntryType::Constant { .. } => "Constant",
379383
EntryType::Points { .. } => "Points",
380-
EntryType::Label { .. } => "Label",
381384
EntryType::Folder { .. } => "Folder",
382385
}
383386
}
@@ -391,7 +394,6 @@ impl<T: EvalexprFloat> Entry<T> {
391394
draw_buffer_scheduler: DrawBufferScheduler::new(),
392395
ty: EntryType::Function {
393396
identifier: istr_empty(),
394-
selectable: true,
395397
can_be_drawn: true,
396398

397399
func: Expr::from_text(text),
@@ -401,7 +403,7 @@ impl<T: EvalexprFloat> Entry<T> {
401403
range_end: Expr::from_text("2"),
402404
ty: FunctionType::Expression,
403405
fill_rule: FillRule::default(),
404-
style: LineStyleConfig::default(),
406+
style: LineStyleConfig::new(true),
405407
implicit_resolution: DEFAULT_IMPLICIT_RESOLUTION,
406408
},
407409
}
@@ -437,21 +439,6 @@ impl<T: EvalexprFloat> Entry<T> {
437439
},
438440
}
439441
}
440-
pub fn new_label(id: u64) -> Self {
441-
Self {
442-
id,
443-
color: id as usize % NUM_COLORS,
444-
active: true,
445-
name: String::new(),
446-
draw_buffer_scheduler: DrawBufferScheduler::new(),
447-
ty: EntryType::Label {
448-
x: Expr::default(),
449-
y: Expr::default(),
450-
size: Expr::default(),
451-
underline: false,
452-
},
453-
}
454-
}
455442
pub fn new_folder(id: u64) -> Self {
456443
Self {
457444
id,

0 commit comments

Comments
 (0)