mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-08-22 01:56:39 +08:00
Improve example style. (#1101)
Some checks failed
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (cl, cl, windows-latest) (push) Has been cancelled
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (clang, clang++, macos-latest) (push) Has been cancelled
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (clang, clang++, ubuntu-latest) (push) Has been cancelled
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (gcc, g++, macos-latest) (push) Has been cancelled
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (gcc, g++, ubuntu-latest) (push) Has been cancelled
Build / CMake, ${{ matrix.compiler }}, ${{ matrix.os }} (cl, Windows MSVC, windows-latest) (push) Has been cancelled
Build / CMake, ${{ matrix.compiler }}, ${{ matrix.os }} (gcc, Linux GCC, ubuntu-latest) (push) Has been cancelled
Build / CMake, ${{ matrix.compiler }}, ${{ matrix.os }} (llvm, llvm-cov gcov, Linux Clang, ubuntu-latest) (push) Has been cancelled
Build / CMake, ${{ matrix.compiler }}, ${{ matrix.os }} (llvm, llvm-cov gcov, MacOS clang, macos-latest) (push) Has been cancelled
Build / Test modules (llvm, ubuntu-latest) (push) Has been cancelled
Documentation / documentation (push) Has been cancelled
Some checks failed
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (cl, cl, windows-latest) (push) Has been cancelled
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (clang, clang++, macos-latest) (push) Has been cancelled
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (clang, clang++, ubuntu-latest) (push) Has been cancelled
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (gcc, g++, macos-latest) (push) Has been cancelled
Build / Bazel, ${{ matrix.cxx }}, ${{ matrix.os }} (gcc, g++, ubuntu-latest) (push) Has been cancelled
Build / CMake, ${{ matrix.compiler }}, ${{ matrix.os }} (cl, Windows MSVC, windows-latest) (push) Has been cancelled
Build / CMake, ${{ matrix.compiler }}, ${{ matrix.os }} (gcc, Linux GCC, ubuntu-latest) (push) Has been cancelled
Build / CMake, ${{ matrix.compiler }}, ${{ matrix.os }} (llvm, llvm-cov gcov, Linux Clang, ubuntu-latest) (push) Has been cancelled
Build / CMake, ${{ matrix.compiler }}, ${{ matrix.os }} (llvm, llvm-cov gcov, MacOS clang, macos-latest) (push) Has been cancelled
Build / Test modules (llvm, ubuntu-latest) (push) Has been cancelled
Documentation / documentation (push) Has been cancelled
Based uppon @yurenchen000 suggestion. Fixed:https://github.com/ArthurSonzogni/FTXUI/issues/1090
This commit is contained in:
parent
21b24a1b78
commit
e56ff89cf3
@ -1,5 +1,9 @@
|
|||||||
@import url(https://fonts.googleapis.com/css?family=Khula:700);
|
@import url(https://fonts.googleapis.com/css?family=Khula:700);
|
||||||
|
|
||||||
|
html {
|
||||||
|
--toc-width: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-color: #EEE;
|
background-color: #EEE;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
@ -41,7 +45,8 @@ h1 {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#selectExample, #selectExample option {
|
#selectExample,
|
||||||
|
#selectExample option {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
@ -61,7 +66,8 @@ h1 {
|
|||||||
height: calc(clamp(200px, 100vh - 300px, 900px));
|
height: calc(clamp(200px, 100vh - 300px, 900px));
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border: none;
|
border: none;
|
||||||
background-color:black;
|
padding: 10px;
|
||||||
|
margin: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#terminalContainer {
|
#terminalContainer {
|
||||||
@ -69,6 +75,7 @@ h1 {
|
|||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.75),
|
box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.75),
|
||||||
0px 2px 80px 0px rgba(0, 0, 0, 0.50);
|
0px 2px 80px 0px rgba(0, 0, 0, 0.50);
|
||||||
|
background-color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fakeButtons {
|
.fakeButtons {
|
||||||
@ -105,3 +112,69 @@ h1 {
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.toc-container {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: var(--toc-width);
|
||||||
|
background: white;
|
||||||
|
padding: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-title {
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: #555;
|
||||||
|
|
||||||
|
position: sticky;
|
||||||
|
transition: position 1.0s ease-in-out;
|
||||||
|
top: 0;
|
||||||
|
z-index: 1;
|
||||||
|
padding: 20px;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
|
||||||
|
/* Gradient background for the title */
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item {
|
||||||
|
padding: 3px 8px;
|
||||||
|
margin: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.85em;
|
||||||
|
border-radius: 3px;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item:hover {
|
||||||
|
background: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-item.selected {
|
||||||
|
background: #e0e0e0;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 1024px) {
|
||||||
|
.toc-container {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 1025px) {
|
||||||
|
.page {
|
||||||
|
margin-left: calc(var(--toc-width) + 20px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,13 +9,18 @@
|
|||||||
<script type="module" src="index.mjs"></script>
|
<script type="module" src="index.mjs"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div class="toc-container">
|
||||||
|
<div class="toc-list"></div>
|
||||||
|
</div>
|
||||||
<script id="example_script"></script>
|
<script id="example_script"></script>
|
||||||
|
|
||||||
<div class="page">
|
<div class="page">
|
||||||
<p>
|
<p>
|
||||||
<a href="https://github.com/ArthurSonzogni/FTXUI">FTXUI</a> is a simple
|
<a href="https://github.com/ArthurSonzogni/FTXUI">FTXUI</a> is a simple
|
||||||
functional C++ library for terminal user interface. <br/>
|
functional C++ library for terminal user interface. <br/>
|
||||||
This showcases the: <a href="https://github.com/ArthurSonzogni/FTXUI/tree/master/examples">./example/</a> folder. <br/>
|
This showcases the: <a
|
||||||
|
href="https://github.com/ArthurSonzogni/FTXUI/tree/master/examples">./example/</a>
|
||||||
|
folder. See <a id="source">source</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div id="terminalContainer">
|
<div id="terminalContainer">
|
||||||
|
@ -92,6 +92,69 @@ window.Module = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const source = document.querySelector("#source");
|
||||||
|
source.href = "https://github.com/ArthurSonzogni/FTXUI/blob/main/examples/" + example + ".cpp";
|
||||||
|
|
||||||
const words = example.split('/')
|
const words = example.split('/')
|
||||||
words[1] = "ftxui_example_" + words[1] + ".js"
|
words[1] = "ftxui_example_" + words[1] + ".js"
|
||||||
document.querySelector("#example_script").src = words.join('/');
|
document.querySelector("#example_script").src = words.join('/');
|
||||||
|
|
||||||
|
|
||||||
|
// Table of Contents (TOC) for quick navigation.
|
||||||
|
|
||||||
|
// Get select element
|
||||||
|
const selectEl = document.querySelector('select#selectExample');
|
||||||
|
if (!selectEl) {
|
||||||
|
console.error('select#selectExample not found');
|
||||||
|
} else {
|
||||||
|
// Get TOC container
|
||||||
|
const tocContainer = document.querySelector('.toc-container');
|
||||||
|
const tocList = tocContainer.querySelector('.toc-list');
|
||||||
|
|
||||||
|
// Group options by directory
|
||||||
|
const groupedOptions = Array.from(selectEl.options).reduce((acc, option) => {
|
||||||
|
const [dir, file] = option.text.split('/');
|
||||||
|
if (!acc[dir]) {
|
||||||
|
acc[dir] = [];
|
||||||
|
}
|
||||||
|
acc[dir].push({ option, file });
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
// Generate TOC items
|
||||||
|
for (const dir in groupedOptions) {
|
||||||
|
const dirContainer = document.createElement('div');
|
||||||
|
|
||||||
|
const dirHeader = document.createElement('div');
|
||||||
|
dirHeader.textContent = dir;
|
||||||
|
dirHeader.className = 'toc-title';
|
||||||
|
dirContainer.appendChild(dirHeader);
|
||||||
|
|
||||||
|
groupedOptions[dir].forEach(({ option, file }) => {
|
||||||
|
const tocItem = document.createElement('div');
|
||||||
|
tocItem.textContent = file;
|
||||||
|
tocItem.className = 'toc-item';
|
||||||
|
|
||||||
|
if (selectEl.options[selectEl.selectedIndex].value === option.value) {
|
||||||
|
tocItem.classList.add('selected');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Click handler
|
||||||
|
tocItem.addEventListener('click', () => {
|
||||||
|
for(let i=0; i<selectEl.options.length; ++i) {
|
||||||
|
if (selectEl.options[i].value == option.value) {
|
||||||
|
selectEl.selectedIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
history.pushState({}, "", "?file=" + option.value);
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
dirContainer.appendChild(tocItem);
|
||||||
|
});
|
||||||
|
|
||||||
|
tocList.appendChild(dirContainer);
|
||||||
|
}
|
||||||
|
}''
|
||||||
|
Loading…
Reference in New Issue
Block a user