Skip to content

Commit

Permalink
Attempt to fix TeXView reflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper Peeters committed Nov 29, 2024
1 parent c3bb459 commit af42fcc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions frontend/gtkmm/NotebookWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ void NotebookWindow::resize_codeinput_texview_all(int width)
// have a maximum width equal to the window width (minus scrollbar),
// except when they contain Python code (which does not word-wrap).
auto it=doc.begin();
std::cerr << "----" << std::endl;
while(it!=doc.end()) {
resize_codeinput_texview(it, width);
++it;
Expand Down Expand Up @@ -937,11 +938,20 @@ void NotebookWindow::resize_codeinput_texview(DTree::iterator it, int width)
auto fnd = canvasses[i]->visualcells.find(&(*it));
if(fnd != canvasses[i]->visualcells.end()) {
TeXView *tex_view = fnd->second.outbox;
Gtk::Allocation allocation = tex_view->get_allocation();
allocation.set_width(width - 20);
tex_view->size_allocate(allocation);
tex_view->window_width = width;

Gtk::Allocation allocation = tex_view->image.get_allocation();
allocation.set_width(width - 20);
int need_height = tex_view->image.need_height(width - 20);
std::cerr << "Need height " << need_height << std::endl;
allocation.set_height(need_height+100);
tex_view->image.size_allocate(allocation);

tex_view->queue_draw();
Glib::signal_timeout().connect_once([tex_view]()
{
tex_view->queue_resize();
}, 50);
}
}
}
Expand Down Expand Up @@ -1949,6 +1959,7 @@ bool NotebookWindow::cell_content_execute(DTree::iterator it, int canvas_number,
else {
(*vis).second.inbox->edit.hide();
it->hidden=true;
// resize_codeinput_texview(it, last_configure_width);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions frontend/gtkmm/TeXView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ void TeXView::TeXArea::get_preferred_height_for_width_vfunc(int width,
}
}

int TeXView::TeXArea::need_height(int width) const
{
int h1, h2;
get_preferred_height_for_width_vfunc(width, h1, h2);
return h1;
}

void TeXView::TeXArea::get_preferred_width_for_height_vfunc(int height,
int& minimum_width, int& natural_width) const
{
Expand Down
1 change: 1 addition & 0 deletions frontend/gtkmm/TeXView.hh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace cadabra {

bool use_microtex;

int need_height(int width) const;
protected:
Gtk::SizeRequestMode get_request_mode_vfunc() const override;
void get_preferred_height_for_width_vfunc(int width, int& minimum_height,
Expand Down

0 comments on commit af42fcc

Please sign in to comment.