Close #128: ArchiveUI defines cursorPosition() which is used to place entries

This commit is contained in:
2022-09-28 23:05:12 +00:00
parent 36e888723f
commit 9ab0c3d671
7 changed files with 28 additions and 7 deletions

View File

@@ -44,8 +44,12 @@
(method processSystems [&opt :ArchiveUI ui]
(doFor system systems (system.process this ui)))
(prop &mut :Entry->Dynamic defaultInitializer null)
(method :Entry createEntry [:Entry->Dynamic initializer] // initializer returns Dynamic so ->:Void isn't required
(let [e (_newEntry)]
(when defaultInitializer
(defaultInitializer e))
(initializer e)
(dictSet entries e.id e)
(refreshEntry e)

View File

@@ -241,12 +241,7 @@
(ui.displayMessage "Entry ${e.id} has no $componentType component"))) [])
(defCommand CreateEntry [name (Text null)]
[(archive.createEntry ->e
{
(when (and playgroundSystem (playgroundSystem.currentDefaultTags))
(addTags archive e (playgroundSystem.currentDefaultTags)))
(addComponent archive e Name name)
})])
[(archive.createEntry ->e (addComponent archive e Name name))])
(defCommand CreateEntries [names (VarText null)]
// createEntry returns a list, so these lists must be flattened

View File

@@ -4,6 +4,8 @@ import nat.Entry;
import nat.ArchiveController;
import kiss_tools.KeyShortcutHandler;
import nat.systems.PlaygroundSystem;
import haxe.ds.Option;
import nat.components.Position;
interface ArchiveUI {
/**
@@ -63,4 +65,9 @@ interface ArchiveUI {
* Update UI to show that the set of selected entries has changed
*/
function onSelectionChanged(selectedEntries:Array<Entry>, lastSelectedEntries:Array<Entry>):Void;
/**
* A way to tell NAT where the cursor is
*/
function cursorPosition():Option<Position>;
}

View File

@@ -5,6 +5,7 @@ import kiss.List;
import nat.System;
import nat.components.*;
import haxe.DynamicAccess;
import haxe.ds.Option;
typedef PlaygroundEntryProcessor = (Archive, Entry, Position, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void
typedef PlaygroundConnectionProcessor = (Archive, Entry, Position, Entry, Position, ?ArchiveUI) -> Dynamic; // Whatever value is returned will be dropped, but this is easier than requiring ->:Void

View File

@@ -42,6 +42,14 @@
(method switchPlaygroundKey [key]
(set _playgroundKey key)
(clear (or (dictGet playgroundBGColors _playgroundKey) (object r 0.0 g 0.0 b 0.0 a 1.0)))
(set ui.controller.archive.defaultInitializer ->e
{
(when (currentDefaultTags)
(addTags ui.controller.archive e (currentDefaultTags)))
(whenLet [(Some position) (ui.cursorPosition)]
(addComponent ui.controller.archive e Positions [=>_playgroundKey position]))
})
(process ui.controller.archive ui))
(method :Void clear [:Color color]