浏览代码

fix focus

/main
fzhangtj 6 年前
当前提交
d2cf9c0e
共有 3 个文件被更改,包括 40 次插入14 次删除
  1. 13
      Runtime/editor/editor_window.cs
  2. 20
      Runtime/engine/UIWidgetsPanel.cs
  3. 21
      Runtime/widgets/focus_manager.cs

13
Runtime/editor/editor_window.cs


this.editorWindow.Repaint();
}
protected override bool hasFocus() {
return EditorWindow.focusedWindow == this.editorWindow;
}
public override GUIContent titleContent {
get { return this.editorWindow.titleContent; }
}

protected virtual void updateSafeArea() {
}
protected abstract bool hasFocus();
public void OnEnable() {
this._devicePixelRatio = this.queryDevicePixelRatio();

public void Update() {
Timer.update();
bool hasFocus = this.hasFocus();
if (hasFocus) {
WidgetsBinding.instance.focusManager.focusIfNeed();
}
else {
WidgetsBinding.instance.focusManager.unfocusIfNeed();
}
this._updateScrollInput();
TextInput.Update();
this._timerProvider.update(this.flushMicrotasks);

20
Runtime/engine/UIWidgetsPanel.cs


Screen.height - Screen.safeArea.height);
}
protected override bool hasFocus() {
return EventSystem.current != null &&
EventSystem.current.currentSelectedGameObject == this._uiWidgetsPanel.gameObject;
}
public override void scheduleFrame(bool regenerateLayerTree = true) {
base.scheduleFrame(regenerateLayerTree);
this._needsPaint = true;

PerformanceUtils.instance.updateDeltaTime(Time.unscaledDeltaTime);
this._displayMetrics.Update();
UIWidgetsMessageManager.ensureUIWidgetsMessageManagerIfNeeded();
if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != this.gameObject) {
this.unfocusIfNeeded();
}
if (this._mouseEntered) {
if (this._lastMouseMove.x != Input.mousePosition.x || this._lastMouseMove.y != Input.mousePosition.y) {
this.handleMouseMovement();

D.assert(this._windowAdapter != null);
this._windowAdapter.Update();
this._windowAdapter.OnGUI(_repaintEvent);
}
void OnGUI() {

physicalX: position.x,
physicalY: position.y
));
}
void unfocusIfNeeded() {
using (this._windowAdapter.getScope()) {
var focusNode = WidgetsBinding.instance.focusManager.currentFocus;
if (focusNode != null) {
focusNode.unfocus();
}
}
}
}
}

21
Runtime/widgets/focus_manager.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;
namespace Unity.UIWidgets.widgets {
public class FocusNode : ChangeNotifier {

this.rootScope._manager = this;
D.assert(this.rootScope._firstChild == null);
D.assert(this.rootScope._lastChild == null);
this.unfocusIfNeed();
internal readonly FocusScopeNode _noneScope = new FocusScopeNode();
internal FocusNode _currentFocus;
internal void _willDisposeFocusNode(FocusNode node) {

if (this._currentFocus != null) {
this._currentFocus._notify();
}
Debug.Log($"updated none={this._noneScope.ToString()}:\n{this.ToString()}");
public void unfocusIfNeed() {
if (this._noneScope._parent != null && this._noneScope.isFirstFocus) {
return;
}
this.rootScope.setFirstFocus(this._noneScope);
}
public void focusIfNeed() {
if (this._noneScope._parent == null) {
return;
}
this._noneScope.detach();
}
public override string ToString() {
var status = this._haveScheduledUpdate ? " UPDATE SCHEDULED" : "";
var indent = " ";

正在加载...
取消
保存