Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 加速ComposableModel new openWithSpec(在Pharo v3中)_User Interface_Smalltalk_Pharo - Fatal编程技术网

User interface 加速ComposableModel new openWithSpec(在Pharo v3中)

User interface 加速ComposableModel new openWithSpec(在Pharo v3中),user-interface,smalltalk,pharo,User Interface,Smalltalk,Pharo,我需要一个有81个框的GUI,用户可以选择输入一个数字(是一个游戏的棋盘) 因此,我将一个ComposableModel子类化,其中包含81个实例变量,每个变量初始化为一个新的TextInputFieldModel实例 问题是打开大约需要6秒钟。为什么要花这么长时间才能打开81个文本框?我可以做些什么来加快开场白吗?您可以使用探查器进行此操作。我试图重新创建您的UI需求,并在工具->时间档案器中运行它。代码如下: | specArray widgets view layout | " Confi

我需要一个有81个框的GUI,用户可以选择输入一个数字(是一个游戏的棋盘)

因此,我将一个
ComposableModel
子类化,其中包含81个实例变量,每个变量初始化为一个新的
TextInputFieldModel
实例


问题是打开大约需要6秒钟。为什么要花这么长时间才能打开81个文本框?我可以做些什么来加快开场白吗?

您可以使用探查器进行此操作。我试图重新创建您的UI需求,并在工具->时间档案器中运行它。代码如下:

| specArray widgets view layout |
" Configure the Spec models "
specArray := OrderedCollection new: 81 * 2.
1 to: 81 do: [ : index | specArray 
    add: ('textInput' , index asString) asSymbol;
    add: #TextInputFieldModel ].
view := DynamicComposableModel new
        instantiateModels: specArray;
        extent: 300@800;
        title: 'Title'
        yourself.
" Configure the Spec layout "
widgets := specArray reject: [ : ti | ti = #TextInputFieldModel ].
layout := SpecLayout composed
        newColumn: [ : r | 
        widgets doWithIndex: [ : ti : index | r add: ti ] ];
        yourself.
" Set up the widgets "
widgets doWithIndex: [ : each : index | (view perform: each) text: index asString  ].
" Open the Window "
(view openWithSpecLayout: layout) delete.
正如您在屏幕截图中看到的,大部分时间都花在TextInputFieldModel>>defaultEntryCompletion上,因此您可以尝试加快该部分的速度(不幸的是,该方法未记录)

如果你应用Leandro的建议,你可以加快

  • 3902次计数,3912毫秒
  • 3916次计数,3927毫秒

  • 1985年计数,1988年毫秒
TextInputFieldModel>>defaultEntryCompletion中的代码是:

defaultEntryCompletion

    | applicants |
    applicants := (Array streamContents: [:strm | 
                    Smalltalk globals keysDo: [ : each | (each notEmpty and: [each first canBeGlobalVarInitial]) 
                        ifTrue: [ strm nextPut: each ] ] ]) sort.

    ^ EntryCompletion new
                dataSourceBlock: [:currText | applicants];
                filterBlock: [:currApplicant :currText | currText size > 3
                        and: [currApplicant asUppercase includesSubstring: currText asString asUppercase]].

处理这个问题的传统方法是使用一个矩阵变形和一个文本字段变形。矩阵负责将文本字段放在正确的位置,确保文本字段得到更新,并为没有焦点的字段绘制文本


它是flyweight模式的一个实现

它看起来像是
streamContents:
块的内容可以重写为
Smalltalk globals keydo:[:each |(每个notEmpty和:[每个first canBeGlobalVarInitial])如果真的话:[strm nextPut:each]