Commit ee35f0ec authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

First stab at fixing the excalibur bug: unpredictable scrollbar display

* still need to query the scrollbar size at runtime
* need to see how this plays with Ico's scrollbar implementation and how
  to merge them
parent 9c940366
......@@ -5807,8 +5807,8 @@ function canvas_params(nw_win)
// the scrollbars from appearing. Here, we just subtract 4 from both
// of them. This could lead to some problems with event handlers but I
// haven't had a problem with it yet.
min_width = nw_win.window.innerWidth - 4;
min_height = nw_win.window.innerHeight - 4;
min_width = nw_win.window.innerWidth;
min_height = nw_win.window.innerHeight;
// Since we don't do any transformations on the patchsvg,
// let's try just using ints for the height/width/viewBox
// to keep things simple.
......@@ -5832,8 +5832,67 @@ function do_getscroll(cid) {
// errors wrt the rendering context disappearing.
gui(cid).get_nw_window(function(nw_win) {
var svg_elem = nw_win.window.document.getElementById("patchsvg");
var overflow_x,
overflow_y,
scrollbar_x_would_overlap_content,
scrollbar_y_would_overlap_content,
x_offset = 0,
y_offset = 0,
scrollbar_pix = 15; // width of scrollbarY/height of scrollbarX... need to query this at runtime
var { x: x, y: y, w: width, h: height,
mw: min_width, mh: min_height } = canvas_params(nw_win);
// Let's get to it. First we want to know if our SVG has any child
// elements overflowing our viewport
overflow_x = width > min_width;
overflow_y = height > min_height;
// Now let's see if drawing a scrollbar would hide objects at the
// extremities of the viewport
scrollbar_x_would_overlap_content = height > min_height - scrollbar_pix;
scrollbar_y_would_overlap_content = width > min_width - scrollbar_pix;
if (overflow_x) {
// We have a horizontal scrollbar.
if (scrollbar_x_would_overlap_content) {
// If there are objects underneath the horizontal scrollbar,
// we want to make sure that the height of our SVG covers
// the entire viewport. That way the browser will give us
// a vertical scrollbar in order to view those objects
y_offset = 0;
} else {
// If there are no objects that would be hidden by the
// horizontal scrollbar, we don't need the vertical scrollbar
// after all. So make the canvas $scrollbar_pix pixels shorter
// so the vertical scrollbar doesn't show up
y_offset = -scrollbar_pix;
}
}
if (overflow_y) {
// See comments above
if (scrollbar_y_would_overlap_content) {
x_offset = 0;
} else {
x_offset = -15;
}
}
// Finally, if we overflow the viewport, let's add some padding so
// that objects at the edge aren't flush against the scrollbar when
// the user scrolls to them. At least I find that a real pain at the
// bottom of the window when trying to add more objects
if (overflow_x) {
x_offset = 5;
}
if (overflow_y) {
y_offset = 5;
}
if (width < min_width) {
width = min_width;
}
......@@ -5842,9 +5901,13 @@ function do_getscroll(cid) {
// room for making connections and manipulating the objects. As it
// stands objects will be flush with the scrollbars and window
// edges.
width += x_offset;
if (height < min_height) {
height = min_height;
}
height += y_offset;
configure_item(svg_elem, {
viewBox: [x, y, width, height].join(" "),
width: width,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment