Adding the files that were pretty printed
This commit is contained in:
parent
5c75d30e44
commit
f7c3dff80f
2 changed files with 96 additions and 105 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
@os
|
@os
|
||||||
|
|
||||||
osState = {
|
osState = {
|
||||||
palette = { visible = True },
|
palette = { visible = False },
|
||||||
windows = [],
|
windows = [],
|
||||||
blah = 53,
|
blah = 53,
|
||||||
wm = {
|
wm = {
|
||||||
|
|
@ -9,9 +9,11 @@ osState = {
|
||||||
scrollOffset = 0,
|
scrollOffset = 0,
|
||||||
defaultWindowWidth = 800
|
defaultWindowWidth = 800
|
||||||
},
|
},
|
||||||
nextId = 0
|
nextId = 6
|
||||||
};
|
};
|
||||||
|
|
||||||
|
paletteHistory = ["textEditor \"palette\"", "gt", "textEditor \"os\""];
|
||||||
|
|
||||||
os = openPalette = _ \ osState.palette.visible := not osState.palette.visible;
|
os = openPalette = _ \ osState.palette.visible := not osState.palette.visible;
|
||||||
|
|
||||||
windowWidth = window \
|
windowWidth = window \
|
||||||
|
|
@ -184,9 +186,7 @@ search = q \
|
||||||
|
|
||||||
onSelect = input \
|
onSelect = input \
|
||||||
historyEvent = paletteHistory := take 50 [input, ...filter (e \ e != input) paletteHistory];
|
historyEvent = paletteHistory := take 50 [input, ...filter (e \ e != input) paletteHistory];
|
||||||
|
|
||||||
dw = osState.wm.defaultWindowWidth;
|
dw = osState.wm.defaultWindowWidth;
|
||||||
|
|
||||||
appWidth = app \
|
appWidth = app \
|
||||||
hasField "width" app
|
hasField "width" app
|
||||||
| True \ app.width
|
| True \ app.width
|
||||||
|
|
|
||||||
|
|
@ -4,122 +4,116 @@ paletteState = {
|
||||||
query = "",
|
query = "",
|
||||||
focusedIndex = 0,
|
focusedIndex = 0,
|
||||||
scrollOffset = 0,
|
scrollOffset = 0,
|
||||||
opacity = 0.95
|
opacity = 0.95,
|
||||||
|
scrollIndex = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
paletteHistory = [];
|
|
||||||
|
|
||||||
palette = config \
|
palette = config \
|
||||||
windowHeight = 400;
|
windowHeight = 400;
|
||||||
windowWidth = 600;
|
windowWidth = 600;
|
||||||
|
|
||||||
results = take 100 (config.search paletteState.query);
|
results = take 100 (config.search paletteState.query);
|
||||||
|
|
||||||
nextSelectable = items index direction \
|
nextSelectable = items index direction \
|
||||||
next = index + direction;
|
next = index + direction;
|
||||||
nth next items
|
nth next items
|
||||||
| Some (Section _) \ nextSelectable items next direction
|
| (Some (Section _)) \ nextSelectable items next direction
|
||||||
| Some (Item _) \ next
|
| (Some (Item _)) \ next
|
||||||
| None \ index;
|
| None \ index;
|
||||||
|
|
||||||
effectiveIndex = nth paletteState.focusedIndex results
|
effectiveIndex = nth paletteState.focusedIndex results
|
||||||
| Some (Section _) \ nextSelectable results paletteState.focusedIndex 1
|
| (Some (Section _)) \ nextSelectable results paletteState.focusedIndex 1
|
||||||
| _ \ paletteState.focusedIndex;
|
| _ \ paletteState.focusedIndex;
|
||||||
|
|
||||||
dialogPadding = 0;
|
dialogPadding = 0;
|
||||||
|
|
||||||
itemGap = 1;
|
itemGap = 1;
|
||||||
textInputHeight = 40;
|
textInputHeight = 40;
|
||||||
sectionHeight = 30;
|
sectionHeight = 30;
|
||||||
contentWidth = windowWidth - (dialogPadding * 2);
|
contentWidth = windowWidth - (dialogPadding * 2);
|
||||||
contentHeight = windowHeight - (dialogPadding * 2);
|
contentHeight = windowHeight - (dialogPadding * 2);
|
||||||
listHeight = contentHeight - 40;
|
listHeight = contentHeight - 40;
|
||||||
|
itemHeight = entry \
|
||||||
itemHeight = entry \ entry
|
entry
|
||||||
| Section _ \ sectionHeight
|
| (Section _) \ sectionHeight
|
||||||
| Item _ \ textInputHeight
|
| (Item _) \ textInputHeight
|
||||||
| _ \ 0;
|
| _ \ 0;
|
||||||
|
totalHeight = (sum (map itemHeight results)) + (itemGap * ((len results) - 1));
|
||||||
totalHeight = (sum (map itemHeight results)) + itemGap * (len results - 1);
|
|
||||||
|
|
||||||
itemY = i \ (sum (map itemHeight (take i results))) + i;
|
itemY = i \ (sum (map itemHeight (take i results))) + i;
|
||||||
|
|
||||||
onScroll = delta \ paletteState.scrollOffset := max 0 (min (totalHeight - listHeight) (paletteState.scrollOffset + delta.deltaY));
|
onScroll = delta \ paletteState.scrollOffset := max 0 (min (totalHeight - listHeight) (paletteState.scrollOffset + delta.deltaY));
|
||||||
|
|
||||||
scrollTo = index \
|
scrollTo = index \
|
||||||
y = itemY index;
|
y = itemY index;
|
||||||
h = unwrapOr 0 (nth index (map itemHeight results));
|
h = unwrapOr 0 (nth index (map itemHeight results));
|
||||||
offset = paletteState.scrollOffset;
|
offset = paletteState.scrollOffset;
|
||||||
(y < offset
|
y < offset
|
||||||
| True \ y
|
| True \ y
|
||||||
| False \ (y + h > offset + listHeight
|
| False \ ((y + h) > (offset + listHeight)
|
||||||
| True \ y + h - listHeight
|
| True \ (y + h) - listHeight
|
||||||
| False \ offset));
|
| False \ offset);
|
||||||
|
onSelect = text \ batch [
|
||||||
onSelect = text \
|
|
||||||
batch [
|
|
||||||
paletteState.query := "",
|
paletteState.query := "",
|
||||||
paletteState.focusedIndex := 0,
|
paletteState.focusedIndex := 0,
|
||||||
paletteState.scrollOffset := 0,
|
paletteState.scrollOffset := 0,
|
||||||
config.onSelect text,
|
config.onSelect text
|
||||||
];
|
];
|
||||||
|
|
||||||
paletteRow = config \
|
paletteRow = config \
|
||||||
color = (config.selected | True \ "rgba(255,255,255,0.2)" | False \ "transparent");
|
color = config.selected
|
||||||
|
| True \ "rgba(255,255,255,0.2)"
|
||||||
|
| False \ "transparent";
|
||||||
ui.clickable {
|
ui.clickable {
|
||||||
onClick = config.onClick,
|
onClick = config.onClick,
|
||||||
child = ui.stack {
|
child = ui.stack { children = [
|
||||||
children = [
|
|
||||||
ui.rect { w = config.w, h = config.h, color = color },
|
ui.rect { w = config.w, h = config.h, color = color },
|
||||||
|
ui.positioned { x = 6, y = 12, child = text config.child }
|
||||||
ui.positioned {
|
] }
|
||||||
x = 6,
|
|
||||||
y = 12,
|
|
||||||
child = text config.child
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# stateful, just so it can get keyboard events
|
|
||||||
ui.stateful {
|
ui.stateful {
|
||||||
key = "palette",
|
key = "palette",
|
||||||
focusable = False,
|
focusable = False,
|
||||||
|
|
||||||
init = { },
|
init = { },
|
||||||
|
update = state event \
|
||||||
update = state event \ event
|
event
|
||||||
| Key { printable = True } \ { state = state, emit = [paletteState.focusedIndex := nextSelectable results 0 1, paletteState.scrollIndex := 0] }
|
| (Key {printable = True}) \ {
|
||||||
| Key { key = "ArrowUp" } \ (
|
state = state,
|
||||||
newIndex = nextSelectable results effectiveIndex (0 - 1);
|
emit = [
|
||||||
{ state = state, emit = [paletteState.focusedIndex := newIndex, paletteState.scrollOffset := scrollTo newIndex] })
|
paletteState.focusedIndex := nextSelectable results 0 1,
|
||||||
| Key { key = "ArrowDown" } \ (
|
paletteState.scrollIndex := 0
|
||||||
newIndex = nextSelectable results effectiveIndex 1;
|
]
|
||||||
{ state = state, emit = [paletteState.focusedIndex := newIndex, paletteState.scrollOffset := scrollTo newIndex] })
|
}
|
||||||
| Key { key = "Enter" } \
|
| (Key {key = "ArrowUp"}) \ (newIndex = nextSelectable results effectiveIndex (0 - 1);
|
||||||
(nth effectiveIndex results
|
{
|
||||||
| Some (Item data) \ { state = state, emit = [onSelect data.label] }
|
state = state,
|
||||||
|
emit = [
|
||||||
|
paletteState.focusedIndex := newIndex,
|
||||||
|
paletteState.scrollOffset := scrollTo newIndex
|
||||||
|
]
|
||||||
|
})
|
||||||
|
| (Key {key = "ArrowDown"}) \ (newIndex = nextSelectable results effectiveIndex 1;
|
||||||
|
{
|
||||||
|
state = state,
|
||||||
|
emit = [
|
||||||
|
paletteState.focusedIndex := newIndex,
|
||||||
|
paletteState.scrollOffset := scrollTo newIndex
|
||||||
|
]
|
||||||
|
})
|
||||||
|
| (Key {key = "Enter"}) \ (nth effectiveIndex results
|
||||||
|
| (Some (Item data)) \ { state = state, emit = [onSelect data.label] }
|
||||||
| _ \ { state = state, emit = [] })
|
| _ \ { state = state, emit = [] })
|
||||||
| Key { key = "Tab" } \ (
|
| (Key {key = "Tab"}) \ (newQuery = nth effectiveIndex results
|
||||||
newQuery = (nth effectiveIndex results
|
| (Some (Item data)) \ data.label
|
||||||
| Some (Item data) \ data.label
|
| None \ paletteState.query;
|
||||||
| None \ paletteState.query);
|
|
||||||
{ state = state, emit = [paletteState.query := newQuery] })
|
{ state = state, emit = [paletteState.query := newQuery] })
|
||||||
| Key { key = "Escape" } \ { state = state, emit = [osState.palette.visible := False] }
|
| (Key {key = "Escape"}) \ { state = state, emit = [osState.palette.visible := False] }
|
||||||
| _ \ { state = state, emit = [] },
|
| _ \ { state = state, emit = [] },
|
||||||
|
view = state emit \ ui.positioned {
|
||||||
view = state emit \
|
|
||||||
ui.positioned {
|
|
||||||
x = (config.viewport.width - windowWidth) / 2,
|
x = (config.viewport.width - windowWidth) / 2,
|
||||||
y = (config.viewport.height - windowHeight) / 2,
|
y = (config.viewport.height - windowHeight) / 2,
|
||||||
|
|
||||||
child = ui.opacity {
|
child = ui.opacity {
|
||||||
|
|
||||||
opacity = paletteState.opacity,
|
opacity = paletteState.opacity,
|
||||||
child = ui.stack {
|
child = ui.stack { children = [
|
||||||
children = [
|
ui.rect {
|
||||||
ui.rect { w = windowWidth, h = windowHeight, color = "#063351", radius = 0, strokeWidth = 1, strokeColor = "#1A5F80" },
|
w = windowWidth,
|
||||||
|
h = windowHeight,
|
||||||
|
color = "#063351",
|
||||||
|
radius = 0,
|
||||||
|
strokeWidth = 1,
|
||||||
|
strokeColor = "#1A5F80"
|
||||||
|
},
|
||||||
ui.padding {
|
ui.padding {
|
||||||
amount = dialogPadding,
|
amount = dialogPadding,
|
||||||
child = ui.column {
|
child = ui.column {
|
||||||
|
|
@ -133,9 +127,8 @@ palette = config \
|
||||||
backgroundColor = "rgba(0,0,0,0.2)",
|
backgroundColor = "rgba(0,0,0,0.2)",
|
||||||
w = contentWidth,
|
w = contentWidth,
|
||||||
h = textInputHeight,
|
h = textInputHeight,
|
||||||
onChange = text \ batch [paletteState.query := text],
|
onChange = text \ batch [paletteState.query := text]
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollable {
|
scrollable {
|
||||||
w = contentWidth,
|
w = contentWidth,
|
||||||
h = listHeight,
|
h = listHeight,
|
||||||
|
|
@ -146,34 +139,32 @@ palette = config \
|
||||||
onScroll = onScroll,
|
onScroll = onScroll,
|
||||||
child = ui.column {
|
child = ui.column {
|
||||||
gap = itemGap,
|
gap = itemGap,
|
||||||
children = [
|
children = [...mapWithIndex (entry i \
|
||||||
...(mapWithIndex (entry i \ entry
|
entry
|
||||||
| Section title \ box {
|
| (Section title) \ box {
|
||||||
w = contentWidth,
|
w = contentWidth,
|
||||||
h = sectionHeight,
|
h = sectionHeight,
|
||||||
color = "transparent",
|
color = "transparent",
|
||||||
paddingLeft = 6,
|
paddingLeft = 6,
|
||||||
paddingTop = 8,
|
paddingTop = 8,
|
||||||
child = renderText { content = title, color = "#bbb" },
|
child = renderText { content = title, color = "#bbb" }
|
||||||
}
|
}
|
||||||
| Item data \ paletteRow {
|
| (Item data) \ paletteRow {
|
||||||
child = data.label,
|
child = data.label,
|
||||||
w = contentWidth,
|
w = contentWidth,
|
||||||
h = textInputHeight,
|
h = textInputHeight,
|
||||||
selected = (effectiveIndex == i),
|
selected = effectiveIndex == i,
|
||||||
onClick = _ \ onSelect data.label
|
onClick = _ \ onSelect data.label
|
||||||
}
|
}
|
||||||
| _ \ empty
|
| _ \ empty) results]
|
||||||
) results)
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
] }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@
|
@
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue