Skip to content

Commit

Permalink
When an error occurs, only move the model if the error item is off sc…
Browse files Browse the repository at this point in the history
…reen, then move it to the centre of the screen.
  • Loading branch information
highperformancecoder committed Oct 18, 2023
1 parent a6265b6 commit df26a53
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
13 changes: 13 additions & 0 deletions gui-js/libs/shared/src/lib/backend/minsky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ export class CSVDialog extends CppClass {
async disable(): Promise<void> {return this.$callMethod('disable');}
async draw(): Promise<void> {return this.$callMethod('draw');}
async flashNameRow(...args: boolean[]): Promise<boolean> {return this.$callMethod('flashNameRow',...args);}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async guessSpecAndLoadFile(): Promise<void> {return this.$callMethod('guessSpecAndLoadFile');}
Expand Down Expand Up @@ -413,6 +414,7 @@ export class Canvas extends CppClass {
async draw(): Promise<void> {return this.$callMethod('draw');}
async findVariableDefinition(): Promise<boolean> {return this.$callMethod('findVariableDefinition');}
async focusFollowsMouse(...args: boolean[]): Promise<boolean> {return this.$callMethod('focusFollowsMouse',...args);}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async groupSelection(): Promise<void> {return this.$callMethod('groupSelection');}
Expand Down Expand Up @@ -580,6 +582,7 @@ export class EquationDisplay extends CppClass {
async destroyFrame(): Promise<void> {return this.$callMethod('destroyFrame');}
async disable(): Promise<void> {return this.$callMethod('disable');}
async draw(): Promise<void> {return this.$callMethod('draw');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
Expand Down Expand Up @@ -632,6 +635,7 @@ export class FontDisplay extends CppClass {
async destroyFrame(): Promise<void> {return this.$callMethod('destroyFrame');}
async disable(): Promise<void> {return this.$callMethod('disable');}
async draw(): Promise<void> {return this.$callMethod('draw');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
Expand Down Expand Up @@ -742,6 +746,7 @@ export class GodleyTab extends CppClass {
async displayDelayedTooltip(a1: number,a2: number): Promise<void> {return this.$callMethod('displayDelayedTooltip',a1,a2);}
async draw(...args: any[]): Promise<void> {return this.$callMethod('draw',...args);}
async evenHeight(): Promise<boolean> {return this.$callMethod('evenHeight');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getVarName(a1: number): Promise<string> {return this.$callMethod('getVarName',a1);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
Expand Down Expand Up @@ -946,6 +951,7 @@ export class GodleyTableWindow extends CppClass {
async draw(...args: any[]): Promise<void> {return this.$callMethod('draw',...args);}
async drawButtons(...args: boolean[]): Promise<boolean> {return this.$callMethod('drawButtons',...args);}
async enableButtons(): Promise<void> {return this.$callMethod('enableButtons');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async godleyIcon(): Promise<GodleyIcon> {return this.$callMethod('godleyIcon');}
Expand Down Expand Up @@ -1492,6 +1498,7 @@ export class Panopticon extends CppClass {
async destroyFrame(): Promise<void> {return this.$callMethod('destroyFrame');}
async disable(): Promise<void> {return this.$callMethod('disable');}
async draw(): Promise<void> {return this.$callMethod('draw');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
Expand Down Expand Up @@ -1538,6 +1545,7 @@ export class PhillipsDiagram extends CppClass {
async destroyFrame(): Promise<void> {return this.$callMethod('destroyFrame');}
async disable(): Promise<void> {return this.$callMethod('disable');}
async draw(): Promise<void> {return this.$callMethod('draw');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
Expand Down Expand Up @@ -1647,6 +1655,7 @@ export class PlotTab extends CppClass {
async displayDelayedTooltip(a1: number,a2: number): Promise<void> {return this.$callMethod('displayDelayedTooltip',a1,a2);}
async draw(...args: any[]): Promise<void> {return this.$callMethod('draw',...args);}
async evenHeight(): Promise<boolean> {return this.$callMethod('evenHeight');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getVarName(a1: number): Promise<string> {return this.$callMethod('getVarName',a1);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
Expand Down Expand Up @@ -1754,6 +1763,7 @@ export class PlotWidget extends Item {
async exportAsCSV(...args: any[]): Promise<void> {return this.$callMethod('exportAsCSV',...args);}
async extendPalette(): Promise<void> {return this.$callMethod('extendPalette');}
async fontScale(...args: number[]): Promise<number> {return this.$callMethod('fontScale',...args);}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async grid(...args: boolean[]): Promise<boolean> {return this.$callMethod('grid',...args);}
Expand Down Expand Up @@ -1952,6 +1962,7 @@ export class RavelPopup extends CppClass {
async destroyFrame(): Promise<void> {return this.$callMethod('destroyFrame');}
async disable(): Promise<void> {return this.$callMethod('disable');}
async draw(): Promise<void> {return this.$callMethod('draw');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
Expand Down Expand Up @@ -1994,6 +2005,7 @@ export class RenderNativeWindow extends CppClass {
async destroyFrame(): Promise<void> {return this.$callMethod('destroyFrame');}
async disable(): Promise<void> {return this.$callMethod('disable');}
async draw(): Promise<void> {return this.$callMethod('draw');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
Expand Down Expand Up @@ -2317,6 +2329,7 @@ export class VariablePane extends CppClass {
async disable(): Promise<void> {return this.$callMethod('disable');}
async draw(): Promise<void> {return this.$callMethod('draw');}
async evenHeight(): Promise<boolean> {return this.$callMethod('evenHeight');}
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
async getItemAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getItemAt',a1,a2);}
async getWireAt(a1: number,a2: number): Promise<boolean> {return this.$callMethod('getWireAt',a1,a2);}
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
Expand Down
10 changes: 8 additions & 2 deletions model/minsky.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1236,8 +1236,14 @@ namespace minsky

canvas.itemIndicator=canvas.item.get();
if (canvas.item)
canvas.model->moveTo(100-canvas.item->x()+canvas.model->x(),
100-canvas.item->y()+canvas.model->y());
{
auto physX=canvas.item->x();
auto physY=canvas.item->y();
if (physX<100 || physX>canvas.frameArgs().childWidth-100 ||
physY<100 || physY>canvas.frameArgs().childHeight-100)
canvas.model->moveTo(0.5*canvas.frameArgs().childWidth-physX+canvas.model->x(),
0.5*canvas.frameArgs().childHeight-physY+canvas.model->y());
}
//requestRedraw calls back into TCL, so don't call it from the simulation thread. See ticket #973
if (!RKThreadRunning) canvas.requestRedraw();
}
Expand Down
1 change: 1 addition & 0 deletions model/renderNativeWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace minsky

void RenderNativeWindow::renderFrame(const RenderFrameArgs& args)
{
m_frameArgs=args;
init();
winInfoPtr.reset();
winInfoPtr = std::make_shared<WindowInformation>(stoull(args.parentWindowId), args.offsetLeft, args.offsetTop, args.childWidth, args.childHeight, args.scalingFactor, hasScrollBars(), [this](){draw();});
Expand Down
12 changes: 8 additions & 4 deletions model/renderNativeWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ namespace minsky
class WindowInformation;
class RenderNativeWindow : public ecolab::CairoSurface, public EventInterface
{
private:
CLASSDESC_ACCESS(RenderNativeWindow);
classdesc::Exclude<std::shared_ptr<WindowInformation>> winInfoPtr;

public:
static ecolab::cairo::Colour backgroundColour;
void disable();
Expand All @@ -47,6 +43,9 @@ namespace minsky
int childHeight;
double scalingFactor=0;
};


const RenderFrameArgs& frameArgs() const {return m_frameArgs;}

~RenderNativeWindow() override;
/// perform any initialisation of any subclasses of this
Expand All @@ -63,6 +62,11 @@ namespace minsky
static double scaleFactor();
/// return whether this window has scrollbars (needed for MacOSX).
virtual bool hasScrollBars() const {return false;}

private:
CLASSDESC_ACCESS(RenderNativeWindow);
classdesc::Exclude<std::shared_ptr<WindowInformation>> winInfoPtr;
RenderFrameArgs m_frameArgs;
};
} // namespace minsky

Expand Down

0 comments on commit df26a53

Please sign in to comment.