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