scrollable now supports horizontal scrolling. using it in os wm. putting all os stuff in os namespace
This commit is contained in:
parent
5fc9d13f80
commit
373ec8b36b
3 changed files with 209 additions and 189 deletions
|
|
@ -26,25 +26,36 @@ button = config \
|
||||||
|
|
||||||
# scrollable
|
# scrollable
|
||||||
scrollable = config \
|
scrollable = config \
|
||||||
barHeight = max 20 (config.h * config.h / config.totalHeight);
|
showVBar = config.totalHeight > config.h;
|
||||||
barY = config.scrollY * config.h / config.totalHeight;
|
vBarHeight = max 20 (config.h * config.h / config.totalHeight);
|
||||||
showBar = config.totalHeight > config.h;
|
vBarY = config.scrollY * config.h / config.totalHeight;
|
||||||
|
|
||||||
|
showHBar = config.totalWidth > config.w;
|
||||||
|
vBarWidth = max 20 (config.w * config.w / config.totalWidth);
|
||||||
|
vBarX = config.scrollX * config.w / config.totalWidth;
|
||||||
|
|
||||||
ui.stack {
|
ui.stack {
|
||||||
children = [
|
children = [
|
||||||
ui.scrollable {
|
ui.scrollable {
|
||||||
w = config.w,
|
w = config.w,
|
||||||
h = config.h,
|
h = config.h,
|
||||||
scrollX = 0,
|
scrollX = config.scrollX,
|
||||||
scrollY = config.scrollY,
|
scrollY = config.scrollY,
|
||||||
onScroll = config.onScroll,
|
onScroll = config.onScroll,
|
||||||
child = config.child
|
child = config.child
|
||||||
},
|
},
|
||||||
...(showBar
|
...(showVBar
|
||||||
| True \ [ui.positioned {
|
| True \ [ui.positioned {
|
||||||
x = config.w - 4,
|
x = config.w - 4,
|
||||||
y = barY,
|
y = vBarY,
|
||||||
child = ui.rect { w = 4, h = barHeight, color = "rgba(255,255,255,0.3)", radius = 2 }
|
child = ui.rect { w = 4, h = vBarHeight, color = "rgba(255,255,255,0.3)", radius = 2 }
|
||||||
|
}]
|
||||||
|
| False \ []),
|
||||||
|
...(showHBar
|
||||||
|
| True \ [ui.positioned {
|
||||||
|
x = config.h - 4,
|
||||||
|
y = hBarX,
|
||||||
|
child = ui.rect { h = 4, w = hBarWidth, color = "rgba(255,255,255,0.3)", radius = 2 }
|
||||||
}]
|
}]
|
||||||
| False \ [])
|
| False \ [])
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ palette = config \
|
||||||
w = contentWidth,
|
w = contentWidth,
|
||||||
h = listHeight,
|
h = listHeight,
|
||||||
totalHeight = totalHeight,
|
totalHeight = totalHeight,
|
||||||
|
totalWidth = contentWidth,
|
||||||
scrollX = 0,
|
scrollX = 0,
|
||||||
scrollY = paletteState.scrollOffset,
|
scrollY = paletteState.scrollOffset,
|
||||||
onScroll = onScroll,
|
onScroll = onScroll,
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,35 @@ osState = {
|
||||||
nextId = 0
|
nextId = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
os =
|
||||||
openPalette = _ \ osState.palette.visible := not (osState.palette.visible);
|
openPalette = _ \ osState.palette.visible := not (osState.palette.visible);
|
||||||
|
|
||||||
windowWidth = window \ window.fullWidth
|
windowWidth = window \ window.fullWidth
|
||||||
| True \ viewport.width
|
| True \ viewport.width
|
||||||
| False \ window.width;
|
| False \ window.width;
|
||||||
|
|
||||||
|
totalWidth = (sum (map windowWidth osState.windows)) + (len osState.windows - 1);
|
||||||
|
|
||||||
|
scrollToWindow = index \
|
||||||
|
windows = osState.windows;
|
||||||
|
widths = map windowWidth windows;
|
||||||
|
gap = 1;
|
||||||
|
windowX = (sum (take index widths)) + (index * gap);
|
||||||
|
windowW = unwrapOr osState.wm.defaultWindowWidth (nth index widths);
|
||||||
|
scrollOffset = osState.wm.scrollOffset;
|
||||||
|
vw = viewport.width;
|
||||||
|
(windowX < scrollOffset
|
||||||
|
| True \ windowX
|
||||||
|
| False \ (windowX + windowW > scrollOffset + vw
|
||||||
|
| True \ windowX + windowW - vw
|
||||||
|
| False \ scrollOffset));
|
||||||
|
|
||||||
|
focusWindow = index \
|
||||||
|
batch [
|
||||||
|
osState.wm.focusedIndex := index,
|
||||||
|
osState.wm.scrollOffset := scrollToWindow index
|
||||||
|
];
|
||||||
|
|
||||||
openWindow = title content \
|
openWindow = title content \
|
||||||
id = osState.nextId;
|
id = osState.nextId;
|
||||||
batch [
|
batch [
|
||||||
|
|
@ -54,33 +77,6 @@ toggleMaximizeFocusedWindow = _ \
|
||||||
idx = osState.wm.focusedIndex;
|
idx = osState.wm.focusedIndex;
|
||||||
osState.windows := updateAt idx (w \ w.{ fullWidth = not w.fullWidth }) osState.windows;
|
osState.windows := updateAt idx (w \ w.{ fullWidth = not w.fullWidth }) osState.windows;
|
||||||
|
|
||||||
scrollToWindow = index \
|
|
||||||
windows = osState.windows;
|
|
||||||
widths = map windowWidth windows;
|
|
||||||
gap = 1;
|
|
||||||
windowX = (sum (take index widths)) + (index * gap);
|
|
||||||
windowW = unwrapOr osState.wm.defaultWindowWidth (nth index widths);
|
|
||||||
scrollOffset = osState.wm.scrollOffset;
|
|
||||||
vw = viewport.width;
|
|
||||||
(windowX < scrollOffset
|
|
||||||
| True \ windowX
|
|
||||||
| False \ (windowX + windowW > scrollOffset + vw
|
|
||||||
| True \ windowX + windowW - vw
|
|
||||||
| False \ scrollOffset));
|
|
||||||
|
|
||||||
focusWindow = index \
|
|
||||||
batch [
|
|
||||||
osState.wm.focusedIndex := index,
|
|
||||||
osState.wm.scrollOffset := scrollToWindow index
|
|
||||||
];
|
|
||||||
|
|
||||||
onSelect = input \
|
|
||||||
result = eval input;
|
|
||||||
result
|
|
||||||
| Value v \ openWindow input (_ \ ui.text { content = show v, color = "white" })
|
|
||||||
| Defined name \ openWindow name (_ \ inspector { name = name })
|
|
||||||
| Err msg \ openWindow "Error" (_ \ ui.text { content = msg, color = "red" });
|
|
||||||
|
|
||||||
renderWindow = window isActive \
|
renderWindow = window isActive \
|
||||||
titleBarHeight = 30;
|
titleBarHeight = 30;
|
||||||
|
|
||||||
|
|
@ -147,15 +143,17 @@ windowComponent = config \ ui.stateful {
|
||||||
renderWindows = _ \
|
renderWindows = _ \
|
||||||
windows = osState.windows;
|
windows = osState.windows;
|
||||||
focused = osState.wm.focusedIndex;
|
focused = osState.wm.focusedIndex;
|
||||||
|
totalHeight = viewport.height;
|
||||||
scrollable {
|
scrollable {
|
||||||
w = viewport.width,
|
w = viewport.width,
|
||||||
h = viewport.height,
|
h = viewport.height,
|
||||||
scrollX = osState.wm.scrollOffset,
|
scrollX = osState.wm.scrollOffset,
|
||||||
scrollY = 0,
|
scrollY = 0,
|
||||||
|
onScroll = onScroll,
|
||||||
child = ui.row {
|
child = ui.row {
|
||||||
gap = 1,
|
gap = 1,
|
||||||
children = mapWithIndex (w i \ windowComponent { window = w, index = i, isActive = (i == focused) }) windows
|
children = mapWithIndex (w i \ windowComponent { window = w, index = i, isActive = (i == focused) }) windows
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
search = q \
|
search = q \
|
||||||
|
|
@ -167,7 +165,17 @@ search = q \
|
||||||
Item { label = q }
|
Item { label = q }
|
||||||
];
|
];
|
||||||
|
|
||||||
os = ui.stateful {
|
onScroll = delta \
|
||||||
|
osState.wm.scrollOffset := max 0 (min (totalWidth - viewport.width) (osState.wm.scrollOffset + delta.deltaX));
|
||||||
|
|
||||||
|
onSelect = input \
|
||||||
|
result = eval input;
|
||||||
|
result
|
||||||
|
| Value v \ openWindow input (_ \ ui.text { content = show v, color = "white" })
|
||||||
|
| Defined name \ openWindow name (_ \ inspector { name = name })
|
||||||
|
| Err msg \ openWindow "Error" (_ \ ui.text { content = msg, color = "red" });
|
||||||
|
|
||||||
|
ui.stateful {
|
||||||
key = "os",
|
key = "os",
|
||||||
autoFocus = True,
|
autoFocus = True,
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue