Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
NotebookCanvas.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include <map>
5#include <gtkmm/paned.h>
6#include <gtkmm/scrolledwindow.h>
7#include <gtkmm/separator.h>
8#ifndef USE_GTK4
9#include <gtkmm/eventbox.h>
10#endif
11#include <glibmm/dispatcher.h>
12
13#include "VisualCell.hh"
14
26
27namespace cadabra {
28
29 class NotebookWindow;
30
32 private:
33 Glib::RefPtr<Gtk::Adjustment> adjustment_;
38 sigc::connection timeout_connection_;
39
40 static constexpr double FRAME_RATE_MS = 16.67; // ~60 FPS
41
43 {
45
47 adjustment_->set_value(target_value_);
48 timeout_connection_.disconnect();
49 return false;
50 }
51
52 // Use easing function (ease-out cubic) for smooth animation
53 double progress = elapsed_ms_ / duration_ms_;
54 double cubic = 1 - std::pow(1 - progress, 3);
55
56 double current = start_value_ +
58
59 adjustment_->set_value(current);
60 return true;
61 }
62
63 public:
64 SmoothScroller(Glib::RefPtr<Gtk::Adjustment> adj)
66 , elapsed_ms_(0)
67 , duration_ms_(400) // 400ms default duration
68 {}
69
70 void scroll_to(double target)
71 {
72 if(target_value_==target && timeout_connection_.connected())
73 return;
74
75 timeout_connection_.disconnect(); // Stop any existing animation
76
78 start_value_ = adjustment_->get_value();
79 elapsed_ms_ = 0;
80
81 // Start the animation loop
82 timeout_connection_ = Glib::signal_timeout().connect(
83 sigc::mem_fun(*this, &SmoothScroller::on_timeout),
85 );
86 }
87
88 void stop() {
89 timeout_connection_.disconnect();
90 }
91
92 void set_duration(double ms) {
94 }
95 };
96
97 class NotebookCanvas : public Gtk::Paned {
98 public:
101
102 std::map<DataCell *, VisualCell> visualcells;
103
104 Gtk::ScrolledWindow scroll;
105 Gtk::Separator bottomline;
107
112 sigc::signal0<bool> scroll_event;
113
114 void refresh_all();
115
120 };
121
122 }
Definition NotebookCanvas.hh:97
NotebookCanvas()
Definition NotebookCanvas.cc:9
void connect_scroll_listener()
Connect a listener to the scroll event on the viewport; this needs to be called after the first (and ...
Definition NotebookCanvas.cc:43
~NotebookCanvas()
Definition NotebookCanvas.cc:26
Gtk::Separator bottomline
Definition NotebookCanvas.hh:105
SmoothScroller scroller
Definition NotebookCanvas.hh:106
Gtk::ScrolledWindow scroll
Definition NotebookCanvas.hh:104
void refresh_all()
Definition NotebookCanvas.cc:30
std::map< DataCell *, VisualCell > visualcells
Definition NotebookCanvas.hh:102
sigc::signal0< bool > scroll_event
Whenever a user-driven scroll happens, this event will fire.
Definition NotebookCanvas.hh:112
Definition NotebookCanvas.hh:31
double elapsed_ms_
Definition NotebookCanvas.hh:37
void scroll_to(double target)
Definition NotebookCanvas.hh:70
double duration_ms_
Definition NotebookCanvas.hh:36
sigc::connection timeout_connection_
Definition NotebookCanvas.hh:38
double target_value_
Definition NotebookCanvas.hh:34
void set_duration(double ms)
Definition NotebookCanvas.hh:92
bool on_timeout()
Definition NotebookCanvas.hh:42
static constexpr double FRAME_RATE_MS
Definition NotebookCanvas.hh:40
Glib::RefPtr< Gtk::Adjustment > adjustment_
Definition NotebookCanvas.hh:33
double start_value_
Definition NotebookCanvas.hh:35
SmoothScroller(Glib::RefPtr< Gtk::Adjustment > adj)
Definition NotebookCanvas.hh:64
void stop()
Definition NotebookCanvas.hh:88
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1140