forked from Blendman974/faceclaw
Screen test for dithering experimentation; landscape layout for phone preview
This commit is contained in:
1 parent
8d6fe60c79
commit
468291aac3
9 files changed
+215
-34
No files matched your search
+42
-15
@@ -1,4 +1,4 @@
|
||||
import { Color, EventData, isAndroid, Observable, Page, ScrollView, TextField } from '@nativescript/core'
|
||||
import { Application, Color, EventData, isAndroid, Observable, Page, ScrollView, TextField } from '@nativescript/core'
|
||||
import { MainViewModel } from './main-view-model'
|
||||
import { dashboardController } from '../g2/dashboard-controller'
|
||||
|
||||
@@ -12,9 +12,12 @@ export function navigatingTo(args: EventData) {
|
||||
}
|
||||
|
||||
type MainPageState = {
|
||||
model: MainViewModel
|
||||
isPinnedToBottom: boolean
|
||||
scrollHandler: () => void
|
||||
scrollViews: ScrollView[]
|
||||
scrollHandler: (args: EventData) => void
|
||||
propertyChangeHandler: (args: EventData & { propertyName?: string }) => void
|
||||
orientationHandler: () => void
|
||||
}
|
||||
|
||||
function getPageState(page: Page): MainPageState | undefined {
|
||||
@@ -27,14 +30,15 @@ function setPageState(page: Page, state?: MainPageState): void {
|
||||
|
||||
function cleanupPage(page: Page): void {
|
||||
const state = getPageState(page)
|
||||
const model = page.bindingContext as MainViewModel | null
|
||||
const scrollView = page.getViewById<ScrollView>('logScrollView')
|
||||
if (!state || !model || !scrollView) {
|
||||
if (!state) {
|
||||
setPageState(page, undefined)
|
||||
return
|
||||
}
|
||||
scrollView.off(ScrollView.scrollEvent, state.scrollHandler)
|
||||
model.off(Observable.propertyChangeEvent, state.propertyChangeHandler)
|
||||
for (const scrollView of state.scrollViews) {
|
||||
scrollView.off(ScrollView.scrollEvent, state.scrollHandler)
|
||||
}
|
||||
state.model.off(Observable.propertyChangeEvent, state.propertyChangeHandler)
|
||||
Application.off(Application.orientationChangedEvent, state.orientationHandler)
|
||||
setPageState(page, undefined)
|
||||
}
|
||||
|
||||
@@ -48,6 +52,12 @@ function scrollToBottom(scrollView: ScrollView): void {
|
||||
}, 0)
|
||||
}
|
||||
|
||||
function scrollLogsToBottom(scrollViews: ScrollView[]): void {
|
||||
for (const scrollView of scrollViews) {
|
||||
scrollToBottom(scrollView)
|
||||
}
|
||||
}
|
||||
|
||||
function applySettingsTextFieldContrast(textField: TextField): void {
|
||||
textField.color = SETTINGS_TEXT_COLOR
|
||||
textField.backgroundColor = SETTINGS_BACKGROUND_COLOR
|
||||
@@ -82,25 +92,39 @@ export function loaded(args: EventData) {
|
||||
dashboardController.refreshEvenAppStatus()
|
||||
|
||||
const model = page.bindingContext as MainViewModel | null
|
||||
const scrollView = page.getViewById<ScrollView>('logScrollView')
|
||||
const scrollViews = [
|
||||
page.getViewById<ScrollView>('logScrollView'),
|
||||
page.getViewById<ScrollView>('logScrollViewLandscape'),
|
||||
].filter((scrollView): scrollView is ScrollView => !!scrollView)
|
||||
const settingsTextField = page.getViewById<TextField>('settingsTextField')
|
||||
model?.refreshLayoutMetrics()
|
||||
if (settingsTextField) {
|
||||
applySettingsTextFieldContrast(settingsTextField)
|
||||
}
|
||||
if (!model || !scrollView) {
|
||||
if (!model || scrollViews.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const state: MainPageState = {
|
||||
model,
|
||||
isPinnedToBottom: true,
|
||||
scrollHandler: () => {
|
||||
state.isPinnedToBottom = isAtBottom(scrollView)
|
||||
scrollViews,
|
||||
scrollHandler: (scrollArgs) => {
|
||||
state.isPinnedToBottom = isAtBottom(scrollArgs.object as ScrollView)
|
||||
},
|
||||
orientationHandler: () => {
|
||||
setTimeout(() => {
|
||||
model.refreshLayoutMetrics()
|
||||
if (state.isPinnedToBottom) {
|
||||
scrollLogsToBottom(scrollViews)
|
||||
}
|
||||
}, 0)
|
||||
},
|
||||
propertyChangeHandler: (propertyArgs) => {
|
||||
if (propertyArgs.propertyName === 'showLog') {
|
||||
if (model.showLog) {
|
||||
state.isPinnedToBottom = true
|
||||
scrollToBottom(scrollView)
|
||||
scrollLogsToBottom(scrollViews)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -114,15 +138,18 @@ export function loaded(args: EventData) {
|
||||
return
|
||||
}
|
||||
if (state.isPinnedToBottom) {
|
||||
scrollToBottom(scrollView)
|
||||
scrollLogsToBottom(scrollViews)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
scrollView.on(ScrollView.scrollEvent, state.scrollHandler)
|
||||
for (const scrollView of scrollViews) {
|
||||
scrollView.on(ScrollView.scrollEvent, state.scrollHandler)
|
||||
}
|
||||
model.on(Observable.propertyChangeEvent, state.propertyChangeHandler)
|
||||
Application.on(Application.orientationChangedEvent, state.orientationHandler)
|
||||
setPageState(page, state)
|
||||
scrollToBottom(scrollView)
|
||||
scrollLogsToBottom(scrollViews)
|
||||
if (model.isTextSettingEditorActive) {
|
||||
focusSystemNameField(page)
|
||||
}
|
||||
|
||||
+40
-13
@@ -5,30 +5,57 @@
|
||||
<ActionItem text="{{ showLogMenuLabel }}" tap="{{ onToggleLogTap }}" android.position="popup" />
|
||||
</ActionBar>
|
||||
|
||||
<GridLayout rows="auto,*">
|
||||
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
|
||||
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}" />
|
||||
</StackLayout>
|
||||
<GridLayout row="1" rows="auto,auto,auto,*" class="p-20">
|
||||
<GridLayout>
|
||||
<GridLayout rows="auto,*" visibility="{{ portraitLayoutVisibility }}">
|
||||
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
|
||||
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}" />
|
||||
</StackLayout>
|
||||
<GridLayout row="1" rows="auto,auto,auto,*" class="p-20">
|
||||
<StackLayout row="0" class="m-b-8" visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
</StackLayout>
|
||||
<StackLayout row="1">
|
||||
<GridLayout rows="auto,auto,auto" columns="*,*,*" class="m-t-8">
|
||||
<Button row="0" col="1" text="Swipe up" tap="{{ onSyntheticUpTap }}" />
|
||||
<Button row="1" col="0" text="Double-click" tap="{{ onSyntheticLeftTap }}" />
|
||||
<Button row="1" col="2" text="Click" tap="{{ onSyntheticRightTap }}" />
|
||||
<Button row="2" col="1" text="Swipe down" tap="{{ onSyntheticDownTap }}" />
|
||||
</GridLayout>
|
||||
</StackLayout>
|
||||
<Label row="2" text="{{ status }}" class="m-t-16" textWrap="true" />
|
||||
<ScrollView id="logScrollView" row="3" class="m-t-16" visibility="{{ showLogVisibility }}">
|
||||
<Label text="{{ log }}" textWrap="true" verticalAlignment="top" />
|
||||
</ScrollView>
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
|
||||
<GridLayout rows="auto,*" class="p-20" visibility="{{ landscapeLayoutVisibility }}">
|
||||
<StackLayout row="0" class="m-b-8" visibility="{{ evenAppConflictWarningVisibility }}">
|
||||
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
|
||||
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
|
||||
</StackLayout>
|
||||
<StackLayout row="1">
|
||||
<GridLayout rows="auto,auto,auto" columns="*,*,*" class="m-t-8">
|
||||
<GridLayout row="1" rows="auto,auto,*" columns="*,260">
|
||||
<StackLayout row="0" col="0" visibility="{{ displayPreviewVisibility }}" horizontalAlignment="left">
|
||||
<Image
|
||||
src="{{ displayPreview }}"
|
||||
stretch="fill"
|
||||
width="{{ landscapeDisplayPreviewWidth }}"
|
||||
height="{{ landscapeDisplayPreviewHeight }}" />
|
||||
</StackLayout>
|
||||
<GridLayout row="0" col="1" rows="auto,auto,auto" columns="*,*,*" class="m-l-16">
|
||||
<Button row="0" col="1" text="Swipe up" tap="{{ onSyntheticUpTap }}" />
|
||||
<Button row="1" col="0" text="Double-click" tap="{{ onSyntheticLeftTap }}" />
|
||||
<Button row="1" col="2" text="Click" tap="{{ onSyntheticRightTap }}" />
|
||||
<Button row="2" col="1" text="Swipe down" tap="{{ onSyntheticDownTap }}" />
|
||||
</GridLayout>
|
||||
</StackLayout>
|
||||
<Label row="2" text="{{ status }}" class="m-t-16" textWrap="true" />
|
||||
<ScrollView id="logScrollView" row="3" class="m-t-16" visibility="{{ showLogVisibility }}">
|
||||
<Label text="{{ log }}" textWrap="true" verticalAlignment="top" />
|
||||
</ScrollView>
|
||||
<Label row="1" col="0" colSpan="2" text="{{ status }}" class="m-t-16" textWrap="true" />
|
||||
<ScrollView id="logScrollViewLandscape" row="2" col="0" colSpan="2" class="m-t-16" visibility="{{ showLogVisibility }}">
|
||||
<Label text="{{ log }}" textWrap="true" verticalAlignment="top" />
|
||||
</ScrollView>
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
<StackLayout
|
||||
row="0"
|
||||
class="system-name-modal"
|
||||
visibility="{{ textSettingEditorVisibility }}"
|
||||
horizontalAlignment="stretch"
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { Frame, ImageSource, Observable, Screen } from "@nativescript/core";
|
||||
import { Application, Frame, ImageSource, Observable, Screen } from "@nativescript/core";
|
||||
import { dashboardController, type TextSettingEditorKind } from "../g2/dashboard-controller";
|
||||
|
||||
type LayoutOrientation = "portrait" | "landscape";
|
||||
|
||||
export class MainViewModel extends Observable {
|
||||
private _status = "Disconnected.";
|
||||
private _log = "";
|
||||
private _displayPreview: ImageSource | null = null;
|
||||
private _layoutOrientation: LayoutOrientation = this.readLayoutOrientation();
|
||||
private _systemCardName = "Faceclaw";
|
||||
private _editingSystemCardName = false;
|
||||
private _activeTextSettingEditorKind: TextSettingEditorKind | null = null;
|
||||
@@ -79,6 +82,36 @@ export class MainViewModel extends Observable {
|
||||
return Screen.mainScreen.widthDIPs / 2;
|
||||
}
|
||||
|
||||
get landscapeDisplayPreviewWidth(): number {
|
||||
const screenWidth = Screen.mainScreen.widthDIPs;
|
||||
const sidePanelWidth = 260;
|
||||
return Math.max(240, Math.floor(screenWidth - sidePanelWidth - 56));
|
||||
}
|
||||
|
||||
get landscapeDisplayPreviewHeight(): number {
|
||||
return Math.floor(this.landscapeDisplayPreviewWidth / 2);
|
||||
}
|
||||
|
||||
get portraitLayoutVisibility(): "visible" | "collapse" {
|
||||
return this._layoutOrientation === "portrait" ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get landscapeLayoutVisibility(): "visible" | "collapse" {
|
||||
return this._layoutOrientation === "landscape" ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
refreshLayoutMetrics(): void {
|
||||
const nextOrientation = this.readLayoutOrientation();
|
||||
if (this._layoutOrientation !== nextOrientation) {
|
||||
this._layoutOrientation = nextOrientation;
|
||||
this.notifyPropertyChange("portraitLayoutVisibility", this.portraitLayoutVisibility);
|
||||
this.notifyPropertyChange("landscapeLayoutVisibility", this.landscapeLayoutVisibility);
|
||||
}
|
||||
this.notifyPropertyChange("displayPreviewHeight", this.displayPreviewHeight);
|
||||
this.notifyPropertyChange("landscapeDisplayPreviewWidth", this.landscapeDisplayPreviewWidth);
|
||||
this.notifyPropertyChange("landscapeDisplayPreviewHeight", this.landscapeDisplayPreviewHeight);
|
||||
}
|
||||
|
||||
get showLog(): boolean {
|
||||
return this._showLog;
|
||||
}
|
||||
@@ -287,6 +320,14 @@ export class MainViewModel extends Observable {
|
||||
this.log = this.log ? `${this.log}\n[${stamp}] ${line}` : `[${stamp}] ${line}`;
|
||||
}
|
||||
|
||||
private readLayoutOrientation(): LayoutOrientation {
|
||||
const applicationOrientation = Application.orientation();
|
||||
if (applicationOrientation === "landscape" || applicationOrientation === "portrait") {
|
||||
return applicationOrientation;
|
||||
}
|
||||
return Screen.mainScreen.widthDIPs > Screen.mainScreen.heightDIPs ? "landscape" : "portrait";
|
||||
}
|
||||
|
||||
private formatError(error: unknown): string {
|
||||
const raw = (error as Error)?.message ?? String(error);
|
||||
const sanitized = raw.replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
|
||||
|
||||
Reference in new issue
Block a user