fix initial size

This commit is contained in:
sawka 2023-03-31 12:34:13 -07:00
parent 164ae305ce
commit 576f67c5a0
3 changed files with 41 additions and 34 deletions

View File

@ -103,7 +103,7 @@ class SimpleBlobRenderer extends React.Component<{rendererContainer : RendererCo
constructor(props : any) { constructor(props : any) {
super(props); super(props);
let {rendererContainer, cmdId, initParams} = this.props; let {rendererContainer, cmdId, plugin, initParams} = this.props;
this.model = new SimpleBlobRendererModel(); this.model = new SimpleBlobRendererModel();
this.model.initialize(initParams); this.model.initialize(initParams);
rendererContainer.registerRenderer(cmdId, this.model); rendererContainer.registerRenderer(cmdId, this.model);

View File

@ -125,7 +125,6 @@ class WebLineCmdView extends React.Component<{line : T.WebLine, cmd : T.WebCmd,
cmdTextRef : React.RefObject<any> = React.createRef(); cmdTextRef : React.RefObject<any> = React.createRef();
copiedIndicator : OV<boolean> = mobx.observable.box(false, {name: "copiedIndicator"}); copiedIndicator : OV<boolean> = mobx.observable.box(false, {name: "copiedIndicator"});
lastHeight : number; lastHeight : number;
lastScreenSize : T.WindowSize;
componentDidMount() : void { componentDidMount() : void {
this.checkCmdText(); this.checkCmdText();
@ -243,9 +242,6 @@ class WebLineCmdView extends React.Component<{line : T.WebLine, cmd : T.WebCmd,
if (elem != null) { if (elem != null) {
curHeight = elem.offsetHeight; curHeight = elem.offsetHeight;
curWidth = elem.offsetWidth; curWidth = elem.offsetWidth;
if (curHeight != 0 && curWidth != 0) {
this.lastScreenSize = {height: curHeight, width: curWidth};
}
} }
if (this.lastHeight == curHeight) { if (this.lastHeight == curHeight) {
return; return;
@ -304,35 +300,11 @@ class WebLineCmdView extends React.Component<{line : T.WebLine, cmd : T.WebCmd,
}, 600); }, 600);
} }
getMaxContentSize() : T.WindowSize {
if (this.lastScreenSize == null) {
let width = termWidthFromCols(80, WebShareModel.getTermFontSize());
let height = termHeightFromRows(25, WebShareModel.getTermFontSize());
return {width, height};
}
let winSize = this.lastScreenSize;
let width = util.boundInt(winSize.width-50, 100, 5000);
let height = util.boundInt(winSize.height-100, 100, 5000);
return {width, height};
}
getIdealContentSize() : T.WindowSize {
if (this.lastScreenSize == null) {
let width = termWidthFromCols(80, WebShareModel.getTermFontSize());
let height = termHeightFromRows(25, WebShareModel.getTermFontSize());
return {width, height};
}
let winSize = this.lastScreenSize;
let width = util.boundInt(Math.ceil((winSize.width-50)*0.7), 100, 5000);
let height = util.boundInt(Math.ceil((winSize.height-100)*0.5), 100, 5000);
return {width, height};
}
getRendererOpts(cmd : T.WebCmd) : T.RendererOpts { getRendererOpts(cmd : T.WebCmd) : T.RendererOpts {
return { return {
maxSize: this.getMaxContentSize(), maxSize: WebShareModel.getMaxContentSize(),
idealSize: this.getIdealContentSize(), idealSize: WebShareModel.getIdealContentSize(),
termOpts: cmd.termopts, termOpts: mobx.toJS(cmd.termopts),
termFontSize: WebShareModel.getTermFontSize(), termFontSize: WebShareModel.getTermFontSize(),
}; };
} }
@ -582,7 +554,7 @@ class WebLineView extends React.Component<{line : T.WebLine, cmd : T.WebCmd, top
class WebScreenView extends React.Component<{}, {}> { class WebScreenView extends React.Component<{}, {}> {
viewRef : React.RefObject<any> = React.createRef(); viewRef : React.RefObject<any> = React.createRef();
width : OV<number> = mobx.observable.box(0, {name: "WebScreenView-width"}); width : OV<number> = mobx.observable.box(0, {name: "WebScreenView-width"});
handleResize_debounced : (entries : any) => void; handleResize_debounced : () => void;
rszObs : ResizeObserver; rszObs : ResizeObserver;
constructor(props : any) { constructor(props : any) {
@ -599,18 +571,20 @@ class WebScreenView extends React.Component<{}, {}> {
if (width > 0) { if (width > 0) {
mobx.action(() => { mobx.action(() => {
this.width.set(width); this.width.set(width);
this.handleResize();
})(); })();
} }
} }
} }
handleResize(entries : any) : void { handleResize() : void {
let viewElem = this.viewRef.current; let viewElem = this.viewRef.current;
if (viewElem == null) { if (viewElem == null) {
return; return;
} }
let width = viewElem.offsetWidth; let width = viewElem.offsetWidth;
let height = viewElem.offsetHeight; let height = viewElem.offsetHeight;
WebShareModel.setLastScreenSize({width, height});
if (width != this.width.get()) { if (width != this.width.get()) {
WebShareModel.resizeWindow({width: width, height: height}); WebShareModel.resizeWindow({width: width, height: height});
mobx.action(() => { mobx.action(() => {

View File

@ -5,6 +5,7 @@ import {handleJsonFetchResponse, isModKeyPress, base64ToArray} from "./util";
import * as T from "./types"; import * as T from "./types";
import {TermWrap} from "./term"; import {TermWrap} from "./term";
import * as lineutil from "./lineutil"; import * as lineutil from "./lineutil";
import * as util from "./util";
import {windowWidthToCols, windowHeightToRows, termWidthFromCols, termHeightFromRows} from "./textmeasure"; import {windowWidthToCols, windowHeightToRows, termWidthFromCols, termHeightFromRows} from "./textmeasure";
import {WebShareWSControl} from "./webshare-ws"; import {WebShareWSControl} from "./webshare-ws";
@ -37,6 +38,7 @@ class WebShareModelClass {
anchor : {anchorLine : number, anchorOffset : number} = {anchorLine: 0, anchorOffset: 0}; anchor : {anchorLine : number, anchorOffset : number} = {anchorLine: 0, anchorOffset: 0};
selectedLine : OV<number> = mobx.observable.box(0, {name: "selectedLine"}); selectedLine : OV<number> = mobx.observable.box(0, {name: "selectedLine"});
syncSelectedLine : OV<boolean> = mobx.observable.box(true, {name: "syncSelectedLine"}); syncSelectedLine : OV<boolean> = mobx.observable.box(true, {name: "syncSelectedLine"});
lastScreenSize : T.WindowSize = null;
constructor() { constructor() {
let urlParams = new URLSearchParams(window.location.search); let urlParams = new URLSearchParams(window.location.search);
@ -65,6 +67,37 @@ class WebShareModelClass {
})(); })();
} }
setLastScreenSize(winSize : T.WindowSize) {
if (winSize == null || winSize.height == 0 || winSize.width == 0) {
return;
}
this.lastScreenSize = winSize;
}
getMaxContentSize() : T.WindowSize {
if (this.lastScreenSize == null) {
let width = termWidthFromCols(80, WebShareModel.getTermFontSize());
let height = termHeightFromRows(25, WebShareModel.getTermFontSize());
return {width, height};
}
let winSize = this.lastScreenSize;
let width = util.boundInt(winSize.width-50, 100, 5000);
let height = util.boundInt(winSize.height-100, 100, 5000);
return {width, height};
}
getIdealContentSize() : T.WindowSize {
if (this.lastScreenSize == null) {
let width = termWidthFromCols(80, WebShareModel.getTermFontSize());
let height = termHeightFromRows(25, WebShareModel.getTermFontSize());
return {width, height};
}
let winSize = this.lastScreenSize;
let width = util.boundInt(Math.ceil((winSize.width-50)*0.7), 100, 5000);
let height = util.boundInt(Math.ceil((winSize.height-100)*0.5), 100, 5000);
return {width, height};
}
getSelectedLine() : number { getSelectedLine() : number {
return this.selectedLine.get(); return this.selectedLine.get();
} }