mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
fix(doc-viewer): rebuild responsive home gallery
- compose the home page from real card, field, attachment and empty widgets - place gallery cards into responsive columns on first mount and route remount - update the home layout on native window resizes and breakpoint changes - refresh navbar, docs page containers and offscreen render helpers - add gallery layout regressions for mounting, resizing, hover and icon sizing
This commit is contained in:
@@ -149,6 +149,33 @@ overview、handbook 等页面结构更自由,仅要求:
|
||||
2. `##` 小节自由组织
|
||||
3. 示例代码块须带 `title="..."` 元数据
|
||||
|
||||
手写页面(Home、部件索引)另有一条硬性约定:**页面组件的根节点必须是 `div`**。
|
||||
`lcui build` 会把根元素类型作为 page 原型的父原型(例如根节点是 `<ScrollArea>` 时,
|
||||
生成的 page 原型继承 `scrollarea`),但生成的 `page.c` 的 init 不会调用父原型的 init,
|
||||
运行时会因为缺少部件内部数据而崩溃。需要滚动时用
|
||||
`<div className="w-full h-full"><ScrollArea …>…</ScrollArea></div>` 包裹。
|
||||
|
||||
Home 页的卡片画廊使用 `app/components/home-grid.c` 的 `home-grid` 部件:卡片是它的
|
||||
直接子节点,用 `data-column="1..4"` 指定所属列(不写则按声明顺序轮转)。可见
|
||||
`home-column` 使用 `flex: 1 1 0` 与 `min-width: 0` 自动均分画廊实际宽度,不写固定像素
|
||||
列宽;部件只按 root 宽度切换列的显示状态:窗口 ≥1400px 显示 4 列,≥1024px 隐藏第
|
||||
3 列,更窄时只保留第 1、4 列。窗口尺寸经 root 的 `afterlayout` 触发显示状态更新;
|
||||
不要在 grid 的 `resize` 回调里写列样式,否则本次 updater 结束时会清掉尚未执行的
|
||||
子项样式更新。grid 在 `link` 事件中会提前标记 pending,确保预渲染页面首次挂载或
|
||||
从其它路由切回时,第一轮布局就完成列分配并使用正确宽度。新增卡片时同步调整
|
||||
`data-column`,保持各列总高度接近。
|
||||
|
||||
画廊卡片必须使用真实 `card` 部件:外层 `<card>`,内容用 `<card-content>`;有标题/描述
|
||||
的卡片用 `<card-header>` + `<card-title>` + `<card-description>`,不要再用
|
||||
`.home-preview-title` 之类的自定义文本模拟。`home-card` / `home-card-body` 只负责
|
||||
画廊的边框、圆角和间距,不重新实现 Card 的结构。
|
||||
|
||||
TSX 里给**容器部件**(`accordion-trigger`、`accordion-content`、`input-group-text`、
|
||||
`badge` 等)写字符串子节点不会显示:编译器会把纯文本写成该部件自身的 `text` 属性,
|
||||
只有 `text` 原型及其衍生的部件(`text`、`button`、`item-title`、`empty-title` 等)会
|
||||
渲染。给容器加文字必须显式写 `<Text>…</Text>`。`clip-safe` 只加在卡片 body 等内层
|
||||
容器上;加到卡片本身时它的 `margin: -4px` 会把卡片推出列边界并吞掉边框。
|
||||
|
||||
## 文档工作流
|
||||
|
||||
以中文文档为主,英文文档在中文文档更新完毕后再全量翻译。
|
||||
@@ -314,7 +341,7 @@ xmake build doc-viewer
|
||||
|
||||
## 离屏渲染截图
|
||||
|
||||
`examples/doc-viewer/scripts/render-offscreen.ps1` 在不打开窗口、不移动鼠标的情况下把指定路由渲染成 PNG,适合无法手动肉眼检查的验证场景(CI、agent):
|
||||
`examples/doc-viewer/scripts/render-offscreen.ps1` 在不打开窗口、不移动鼠标的情况下把指定路由渲染成 PNG,适合无法手动肉眼检查的验证场景(CI、agent)。脚本用 `Start-Process -WindowStyle Hidden` 启动进程,控制台窗口也不会出现;Windows 虚拟桌面的窗口归属由系统按启动进程时所在桌面决定,进程无法选择桌面,隐藏窗口是避免影响其它桌面的唯一可靠方式。
|
||||
|
||||
```powershell
|
||||
# 渲染单个路由
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "home-gallery.tsx.h"
|
||||
#include "home-gallery.h"
|
||||
@@ -0,0 +1,3 @@
|
||||
#include <ui.h>
|
||||
|
||||
void ui_load_home_gallery_resources(void);
|
||||
@@ -0,0 +1,814 @@
|
||||
import {
|
||||
Button,
|
||||
FunctionWidget,
|
||||
RouterLink,
|
||||
ScrollArea,
|
||||
ScrollAreaContent,
|
||||
Scrollbar,
|
||||
Text,
|
||||
} from "@lcui/react";
|
||||
|
||||
type Locale = "zh-CN" | "en";
|
||||
|
||||
const heroDesc: Record<Locale, string> = {
|
||||
"zh-CN": "用于开发图形用户界面的 C 语言库。",
|
||||
en: "The C library for building user interfaces.",
|
||||
};
|
||||
|
||||
const ctaLabel: Record<Locale, { start: string; widgets: string }> = {
|
||||
"zh-CN": { start: "快速开始", widgets: "浏览部件" },
|
||||
en: { start: "Get started", widgets: "Browse widgets" },
|
||||
};
|
||||
|
||||
const HomeGallery: FunctionWidget = ({ locale }: { locale: Locale }) => {
|
||||
const cta = ctaLabel[locale];
|
||||
|
||||
return (
|
||||
<div className="w-full h-full">
|
||||
<ScrollArea className="w-full h-full">
|
||||
<ScrollAreaContent>
|
||||
<div className="home-page">
|
||||
<div className="home-inner">
|
||||
<div className="home-hero">
|
||||
<Text className="home-title">LCUI</Text>
|
||||
<Text className="home-desc">{heroDesc[locale]}</Text>
|
||||
<div className="home-cta">
|
||||
<RouterLink
|
||||
className="button button-primary"
|
||||
to={`/${locale}/docs/overview/quick-start`}
|
||||
>
|
||||
<Text>{cta.start}</Text>
|
||||
</RouterLink>
|
||||
<RouterLink
|
||||
className="button button-outline"
|
||||
to={`/${locale}/docs/widgets`}
|
||||
>
|
||||
<Text>{cta.widgets}</Text>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<home-grid>
|
||||
<card className="home-card" data-column="1">
|
||||
<card-content className="home-card-body home-controls clip-safe">
|
||||
<div className="home-row">
|
||||
<Button variant="primary" size="sm">
|
||||
<Text>Button</Text>
|
||||
<icon name="arrow-right" />
|
||||
</Button>
|
||||
<Button variant="secondary" size="sm">
|
||||
Secondary
|
||||
</Button>
|
||||
<Button variant="outline" size="sm">
|
||||
Outline
|
||||
</Button>
|
||||
</div>
|
||||
<input-group>
|
||||
<textinput
|
||||
className="input-group-input"
|
||||
placeholder="Name"
|
||||
/>
|
||||
<input-group-addon align="inline-end">
|
||||
<icon name="search" />
|
||||
</input-group-addon>
|
||||
</input-group>
|
||||
<textinput
|
||||
className="home-textarea"
|
||||
multiline="true"
|
||||
placeholder="Message"
|
||||
/>
|
||||
<div className="home-row home-row-between">
|
||||
<div className="home-row">
|
||||
<badge variant="default">Badge</badge>
|
||||
<badge variant="secondary">Secondary</badge>
|
||||
</div>
|
||||
<div className="home-row">
|
||||
<radio-group value="a">
|
||||
<radio-group-item value="a" checked="true" />
|
||||
<radio-group-item value="b" />
|
||||
</radio-group>
|
||||
<checkbox checked="true" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="home-row">
|
||||
<alert-dialog>
|
||||
<alert-dialog-trigger>
|
||||
<Button variant="outline">Alert Dialog</Button>
|
||||
</alert-dialog-trigger>
|
||||
<alert-dialog-overlay>
|
||||
<alert-dialog-content>
|
||||
<alert-dialog-header>
|
||||
<alert-dialog-title>
|
||||
Allow accessory to connect?
|
||||
</alert-dialog-title>
|
||||
<alert-dialog-description>
|
||||
Do you want to allow the USB accessory to
|
||||
connect to this device and your data?
|
||||
</alert-dialog-description>
|
||||
</alert-dialog-header>
|
||||
<alert-dialog-footer>
|
||||
<alert-dialog-cancel variant="outline">
|
||||
Don't allow
|
||||
</alert-dialog-cancel>
|
||||
<alert-dialog-action variant="primary">
|
||||
Allow
|
||||
</alert-dialog-action>
|
||||
</alert-dialog-footer>
|
||||
</alert-dialog-content>
|
||||
</alert-dialog-overlay>
|
||||
</alert-dialog>
|
||||
<button-group>
|
||||
<Button variant="outline">Button Group</Button>
|
||||
<dropdown-menu>
|
||||
<dropdown-menu-trigger>
|
||||
<Button variant="outline" size="icon">
|
||||
<icon name="chevron-down" />
|
||||
</Button>
|
||||
</dropdown-menu-trigger>
|
||||
<dropdown-menu-content align="end">
|
||||
<dropdown-menu-label>
|
||||
<Text>Quick Actions</Text>
|
||||
</dropdown-menu-label>
|
||||
<dropdown-menu-item>
|
||||
<Text>Mute Conversation</Text>
|
||||
</dropdown-menu-item>
|
||||
<dropdown-menu-item>
|
||||
<Text>Mark as Read</Text>
|
||||
</dropdown-menu-item>
|
||||
<dropdown-menu-item>
|
||||
<Text>Block User</Text>
|
||||
</dropdown-menu-item>
|
||||
<dropdown-menu-separator />
|
||||
<dropdown-menu-item variant="destructive">
|
||||
<Text>Delete Conversation</Text>
|
||||
</dropdown-menu-item>
|
||||
</dropdown-menu-content>
|
||||
</dropdown-menu>
|
||||
</button-group>
|
||||
</div>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="1">
|
||||
<card-content className="home-card-body home-attachment-card">
|
||||
<card-header>
|
||||
<card-title>Attachments</card-title>
|
||||
<card-description>
|
||||
Upload, review, and manage your files.
|
||||
</card-description>
|
||||
</card-header>
|
||||
<attachment state="idle">
|
||||
<attachment-media>
|
||||
<icon name="clock" />
|
||||
</attachment-media>
|
||||
<attachment-content>
|
||||
<attachment-title>selected-file.pdf</attachment-title>
|
||||
<attachment-description>
|
||||
Ready to upload
|
||||
</attachment-description>
|
||||
</attachment-content>
|
||||
<attachment-actions>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="attachment-action"
|
||||
>
|
||||
<icon name="dismiss" />
|
||||
</Button>
|
||||
</attachment-actions>
|
||||
</attachment>
|
||||
<attachment state="uploading">
|
||||
<attachment-media>
|
||||
<spinner running="true" />
|
||||
</attachment-media>
|
||||
<attachment-content>
|
||||
<attachment-title>design-system.zip</attachment-title>
|
||||
<attachment-description>
|
||||
Uploading - 64%
|
||||
</attachment-description>
|
||||
</attachment-content>
|
||||
<attachment-actions>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="attachment-action"
|
||||
>
|
||||
<icon name="dismiss" />
|
||||
</Button>
|
||||
</attachment-actions>
|
||||
</attachment>
|
||||
<attachment state="processing">
|
||||
<attachment-media>
|
||||
<icon name="document-text" />
|
||||
</attachment-media>
|
||||
<attachment-content>
|
||||
<attachment-title>market-research.pdf</attachment-title>
|
||||
<attachment-description>
|
||||
Processing document
|
||||
</attachment-description>
|
||||
</attachment-content>
|
||||
<attachment-actions>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="attachment-action"
|
||||
>
|
||||
<icon name="dismiss" />
|
||||
</Button>
|
||||
</attachment-actions>
|
||||
</attachment>
|
||||
<attachment state="error">
|
||||
<attachment-media>
|
||||
<icon name="document-error" />
|
||||
</attachment-media>
|
||||
<attachment-content>
|
||||
<attachment-title>
|
||||
financial-model.xlsx
|
||||
</attachment-title>
|
||||
<attachment-description>
|
||||
Upload failed. Try again.
|
||||
</attachment-description>
|
||||
</attachment-content>
|
||||
<attachment-actions>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="attachment-action"
|
||||
>
|
||||
<icon name="arrow-sync" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="attachment-action"
|
||||
>
|
||||
<icon name="dismiss" />
|
||||
</Button>
|
||||
</attachment-actions>
|
||||
</attachment>
|
||||
<attachment state="done">
|
||||
<attachment-media>
|
||||
<icon name="checkmark" />
|
||||
</attachment-media>
|
||||
<attachment-content>
|
||||
<attachment-title>uploaded-report.pdf</attachment-title>
|
||||
<attachment-description>
|
||||
Uploaded - 1.8 MB
|
||||
</attachment-description>
|
||||
</attachment-content>
|
||||
<attachment-actions>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
className="attachment-action"
|
||||
>
|
||||
<icon name="dismiss" />
|
||||
</Button>
|
||||
</attachment-actions>
|
||||
</attachment>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="1">
|
||||
<card-content className="home-card-body home-savings">
|
||||
<card-header>
|
||||
<card-title>Savings Targets</card-title>
|
||||
<card-description>
|
||||
Active milestones for 2024 across your portfolio.
|
||||
Monitor how close you are to each savings goal.
|
||||
</card-description>
|
||||
</card-header>
|
||||
<div className="home-goal">
|
||||
<Text className="home-goal-label">RETIREMENT</Text>
|
||||
<Text className="home-goal-value">$420,000</Text>
|
||||
<progress value="65" className="home-goal-progress" />
|
||||
<div className="home-goal-footer">
|
||||
<Text className="home-goal-caption">65% achieved</Text>
|
||||
<Text className="home-goal-amount">$273,000</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div className="home-goal">
|
||||
<Text className="home-goal-label">REAL ESTATE</Text>
|
||||
<Text className="home-goal-value">$85,000</Text>
|
||||
<progress value="32" className="home-goal-progress" />
|
||||
<div className="home-goal-footer">
|
||||
<Text className="home-goal-caption">32% achieved</Text>
|
||||
<Text className="home-goal-amount">$27,200</Text>
|
||||
</div>
|
||||
</div>
|
||||
<Text className="home-preview-desc">
|
||||
You have not met your targets for this year.
|
||||
</Text>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="2">
|
||||
<card-content className="home-card-body home-claim">
|
||||
<Text className="home-claim-label">Claimable Balance</Text>
|
||||
<Text className="home-balance">$1,211.29</Text>
|
||||
<div className="home-row">
|
||||
<badge variant="outline">
|
||||
<div className="home-dot" />
|
||||
<Text>Pending Setup</Text>
|
||||
</badge>
|
||||
</div>
|
||||
<div className="home-summary">
|
||||
<div className="home-row home-row-between">
|
||||
<Text className="home-summary-label">
|
||||
Net Royalties
|
||||
</Text>
|
||||
<Text className="home-summary-value">$1,248.75</Text>
|
||||
</div>
|
||||
<div className="home-row home-row-between">
|
||||
<Text className="home-summary-label">
|
||||
Processing Fee
|
||||
</Text>
|
||||
<Text className="home-summary-value">-$37.46</Text>
|
||||
</div>
|
||||
<div className="home-divider" />
|
||||
<div className="home-row home-row-between">
|
||||
<Text className="home-summary-total">
|
||||
Total Ready to Claim
|
||||
</Text>
|
||||
<Text className="home-summary-total">
|
||||
$1,211.29 USD
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<Text className="home-preview-desc">
|
||||
Once your bank is connected, balances over $10 are
|
||||
automatically eligible for monthly distribution on the
|
||||
15th of each month.
|
||||
</Text>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="2">
|
||||
<card-content className="home-card-body home-accordion">
|
||||
<card-header>
|
||||
<card-title>Subscription & Billing</card-title>
|
||||
<card-description>
|
||||
Common questions about your account, plans, payments and
|
||||
cancellations.
|
||||
</card-description>
|
||||
</card-header>
|
||||
<accordion>
|
||||
<accordion-item value="plans" open="true">
|
||||
<accordion-trigger>
|
||||
<Text>What subscription plans do you offer?</Text>
|
||||
</accordion-trigger>
|
||||
<accordion-content>
|
||||
<Text>
|
||||
We offer three subscription tiers: Starter
|
||||
($9/month), Professional ($29/month), and Enterprise
|
||||
($99/month). Each plan includes increasing storage
|
||||
limits, API access, priority support, and team
|
||||
collaboration features.
|
||||
</Text>
|
||||
</accordion-content>
|
||||
</accordion-item>
|
||||
<accordion-item value="billing">
|
||||
<accordion-trigger>
|
||||
<Text>How does billing work?</Text>
|
||||
</accordion-trigger>
|
||||
<accordion-content>
|
||||
<Text>
|
||||
Billing occurs automatically at the start of each
|
||||
billing cycle. We accept all major credit cards,
|
||||
PayPal, and ACH transfers for enterprise customers.
|
||||
</Text>
|
||||
</accordion-content>
|
||||
</accordion-item>
|
||||
<accordion-item value="cancel">
|
||||
<accordion-trigger>
|
||||
<Text>How do I cancel my subscription?</Text>
|
||||
</accordion-trigger>
|
||||
<accordion-content>
|
||||
<Text>
|
||||
You can cancel your subscription anytime from your
|
||||
account settings. There are no cancellation fees or
|
||||
penalties.
|
||||
</Text>
|
||||
</accordion-content>
|
||||
</accordion-item>
|
||||
<accordion-item value="change">
|
||||
<accordion-trigger>
|
||||
<Text>Can I change plans later?</Text>
|
||||
</accordion-trigger>
|
||||
<accordion-content>
|
||||
<Text>
|
||||
Yes. Upgrades take effect immediately and downgrades
|
||||
apply at the end of the current billing period.
|
||||
</Text>
|
||||
</accordion-content>
|
||||
</accordion-item>
|
||||
</accordion>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="2">
|
||||
<card-content className="home-card-body home-deployment">
|
||||
<card-header>
|
||||
<div className="home-row home-row-between">
|
||||
<card-title>Deployment Status</card-title>
|
||||
<badge variant="outline">
|
||||
<div className="home-deploy-live-dot" />
|
||||
<Text>Live</Text>
|
||||
</badge>
|
||||
</div>
|
||||
<card-description>
|
||||
Production rollout for the documentation site.
|
||||
</card-description>
|
||||
</card-header>
|
||||
<div className="home-deploy-progress">
|
||||
<div className="home-row home-row-between">
|
||||
<Text className="home-deploy-environment">
|
||||
production
|
||||
</Text>
|
||||
<Text className="home-deploy-percent">82%</Text>
|
||||
</div>
|
||||
<progress value="82" />
|
||||
</div>
|
||||
<div className="home-deploy-steps">
|
||||
<item>
|
||||
<item-media variant="icon">
|
||||
<icon name="checkmark" />
|
||||
</item-media>
|
||||
<item-content>
|
||||
<item-title>Build & test</item-title>
|
||||
<item-description>
|
||||
Windows, Linux and macOS passed.
|
||||
</item-description>
|
||||
</item-content>
|
||||
<item-actions>
|
||||
<Text className="home-deploy-step-meta">2m 14s</Text>
|
||||
</item-actions>
|
||||
</item>
|
||||
<item>
|
||||
<item-media variant="icon">
|
||||
<icon name="checkmark" />
|
||||
</item-media>
|
||||
<item-content>
|
||||
<item-title>Database migration</item-title>
|
||||
<item-description>
|
||||
Schema changes applied successfully.
|
||||
</item-description>
|
||||
</item-content>
|
||||
<item-actions>
|
||||
<Text className="home-deploy-step-meta">38s</Text>
|
||||
</item-actions>
|
||||
</item>
|
||||
<item>
|
||||
<item-media variant="icon">
|
||||
<spinner running="true" />
|
||||
</item-media>
|
||||
<item-content>
|
||||
<item-title>Edge rollout</item-title>
|
||||
<item-description>
|
||||
Shifting traffic across regions.
|
||||
</item-description>
|
||||
</item-content>
|
||||
<item-actions>
|
||||
<Text className="home-deploy-step-meta">82%</Text>
|
||||
</item-actions>
|
||||
</item>
|
||||
</div>
|
||||
<alert variant="warning">
|
||||
<icon name="warning" />
|
||||
<alert-content>
|
||||
<alert-title>One region is warming up</alert-title>
|
||||
<alert-description>
|
||||
Traffic is still being shifted in eu-west.
|
||||
</alert-description>
|
||||
</alert-content>
|
||||
</alert>
|
||||
<div className="home-row home-deploy-actions">
|
||||
<button-group>
|
||||
<Button variant="outline">
|
||||
<Text>View logs</Text>
|
||||
</Button>
|
||||
<dropdown-menu>
|
||||
<dropdown-menu-trigger>
|
||||
<Button variant="outline" size="icon">
|
||||
<icon name="chevron-down" />
|
||||
</Button>
|
||||
</dropdown-menu-trigger>
|
||||
<dropdown-menu-content align="end">
|
||||
<dropdown-menu-item>
|
||||
<Text>Rollback release</Text>
|
||||
</dropdown-menu-item>
|
||||
<dropdown-menu-item>
|
||||
<Text>Copy commit hash</Text>
|
||||
</dropdown-menu-item>
|
||||
</dropdown-menu-content>
|
||||
</dropdown-menu>
|
||||
</button-group>
|
||||
<Button
|
||||
variant="primary"
|
||||
className="home-deploy-redeploy"
|
||||
>
|
||||
<icon name="arrow-sync" />
|
||||
<Text>Redeploy</Text>
|
||||
</Button>
|
||||
</div>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="3">
|
||||
<card-content className="home-card-body home-milestone clip-safe">
|
||||
<card-header>
|
||||
<card-title>Set a new milestone</card-title>
|
||||
<card-description>
|
||||
Define your financial target and we'll help you pace
|
||||
your savings.
|
||||
</card-description>
|
||||
</card-header>
|
||||
<field>
|
||||
<field-label>Goal Name</field-label>
|
||||
<textinput
|
||||
className="home-input"
|
||||
placeholder="e.g. New Car"
|
||||
/>
|
||||
</field>
|
||||
<div className="home-field-row clip-safe">
|
||||
<field className="home-field-half clip-safe">
|
||||
<field-label>Target Amount</field-label>
|
||||
<textinput
|
||||
className="home-input"
|
||||
placeholder="$15,000"
|
||||
/>
|
||||
</field>
|
||||
<field className="home-field-half clip-safe">
|
||||
<field-label>Target Date</field-label>
|
||||
<textinput
|
||||
className="home-input"
|
||||
placeholder="Dec 2025"
|
||||
/>
|
||||
</field>
|
||||
</div>
|
||||
<Button variant="primary" className="home-block-button">
|
||||
Create Goal
|
||||
</Button>
|
||||
<Button variant="outline" className="home-block-button">
|
||||
Cancel
|
||||
</Button>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="3">
|
||||
<card-content className="home-card-body home-payout clip-safe">
|
||||
<div className="home-row home-row-between">
|
||||
<card-title>Payout Threshold</card-title>
|
||||
<Button variant="ghost" size="icon-sm">
|
||||
<icon name="dismiss" />
|
||||
</Button>
|
||||
</div>
|
||||
<card-description>
|
||||
Set the minimum balance required before a payout is
|
||||
triggered.
|
||||
</card-description>
|
||||
<field>
|
||||
<field-label>Preferred Currency</field-label>
|
||||
<dropdown-menu>
|
||||
<dropdown-menu-trigger>
|
||||
<Button variant="outline" className="home-select">
|
||||
<Text>USD — United States Dollar</Text>
|
||||
<icon name="chevron-down" />
|
||||
</Button>
|
||||
</dropdown-menu-trigger>
|
||||
<dropdown-menu-content align="start">
|
||||
<dropdown-menu-radio-group value="usd">
|
||||
<dropdown-menu-radio-item value="usd">
|
||||
<Text>USD — United States Dollar</Text>
|
||||
</dropdown-menu-radio-item>
|
||||
<dropdown-menu-radio-item value="cny">
|
||||
<Text>CNY — Chinese Yuan</Text>
|
||||
</dropdown-menu-radio-item>
|
||||
<dropdown-menu-radio-item value="jpy">
|
||||
<Text>JPY — Japanese Yen</Text>
|
||||
</dropdown-menu-radio-item>
|
||||
<dropdown-menu-radio-item value="eur">
|
||||
<Text>EUR — Euro</Text>
|
||||
</dropdown-menu-radio-item>
|
||||
</dropdown-menu-radio-group>
|
||||
</dropdown-menu-content>
|
||||
</dropdown-menu>
|
||||
</field>
|
||||
<field>
|
||||
<field-label>Minimum Payout Amount</field-label>
|
||||
<Text className="home-payout-amount">$2500.00</Text>
|
||||
<div className="home-slider">
|
||||
<div className="home-slider-fill" />
|
||||
</div>
|
||||
<div className="home-row home-row-between">
|
||||
<Text className="home-goal-meta">$50 (MIN)</Text>
|
||||
<Text className="home-goal-meta">$10,000 (MAX)</Text>
|
||||
</div>
|
||||
</field>
|
||||
<field>
|
||||
<field-label>Notes</field-label>
|
||||
<textinput
|
||||
className="home-textarea"
|
||||
multiline="true"
|
||||
placeholder="Add a note for this payout"
|
||||
/>
|
||||
</field>
|
||||
<Button variant="primary" className="home-block-button">
|
||||
Save Threshold
|
||||
</Button>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="3">
|
||||
<card-content className="home-card-body home-account clip-safe">
|
||||
<card-header>
|
||||
<card-title>Account Access</card-title>
|
||||
<card-description>
|
||||
Update your credentials or re-authenticate.
|
||||
</card-description>
|
||||
</card-header>
|
||||
<field>
|
||||
<field-label>Email Address</field-label>
|
||||
<textinput
|
||||
className="home-input"
|
||||
placeholder="artist@studio.inc"
|
||||
/>
|
||||
</field>
|
||||
<field>
|
||||
<div className="home-row home-row-between">
|
||||
<field-label>Current Password</field-label>
|
||||
<Button
|
||||
variant="link"
|
||||
size="xs"
|
||||
className="home-field-link"
|
||||
>
|
||||
FORGOT?
|
||||
</Button>
|
||||
</div>
|
||||
<textinput
|
||||
className="home-input"
|
||||
type="password"
|
||||
placeholder="********"
|
||||
/>
|
||||
</field>
|
||||
<Button variant="primary" className="home-block-button">
|
||||
<icon name="lock-closed" />
|
||||
<Text>Update Security</Text>
|
||||
</Button>
|
||||
<item
|
||||
variant="muted"
|
||||
interactive="true"
|
||||
className="home-danger"
|
||||
>
|
||||
<item-media variant="icon">
|
||||
<icon name="error-circle" />
|
||||
</item-media>
|
||||
<item-content>
|
||||
<item-title>Danger Zone</item-title>
|
||||
<item-description>
|
||||
Archive account and remove…
|
||||
</item-description>
|
||||
</item-content>
|
||||
<item-actions>
|
||||
<icon name="chevron-right" />
|
||||
</item-actions>
|
||||
</item>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="4">
|
||||
<card-content className="home-card-body home-empty">
|
||||
<empty>
|
||||
<empty-header>
|
||||
<div className="home-empty-icon">
|
||||
<icon name="add" />
|
||||
</div>
|
||||
<empty-title>Distribute Track</empty-title>
|
||||
<empty-description>
|
||||
Upload your first master to start reaching listeners
|
||||
on Spotify, Apple Music, and more.
|
||||
</empty-description>
|
||||
</empty-header>
|
||||
<empty-content>
|
||||
<Button variant="primary">Create Release</Button>
|
||||
</empty-content>
|
||||
</empty>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="4">
|
||||
<card-content className="home-card-body home-alerts">
|
||||
<card-header>
|
||||
<card-title>Notifications</card-title>
|
||||
<card-description>
|
||||
Choose which email and push alerts you want to receive.
|
||||
</card-description>
|
||||
</card-header>
|
||||
<div className="home-alert-row">
|
||||
<checkbox checked="true" />
|
||||
<div className="home-alert-text">
|
||||
<Text className="home-alert-title">
|
||||
Transaction alerts
|
||||
</Text>
|
||||
<Text className="home-alert-desc">
|
||||
Deposits, withdrawals, and transfers.
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div className="home-alert-row">
|
||||
<checkbox checked="true" />
|
||||
<div className="home-alert-text">
|
||||
<Text className="home-alert-title">
|
||||
Security alerts
|
||||
</Text>
|
||||
<Text className="home-alert-desc">
|
||||
Login attempts and account changes.
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div className="home-alert-row">
|
||||
<checkbox />
|
||||
<div className="home-alert-text">
|
||||
<Text className="home-alert-title">
|
||||
Goal milestones
|
||||
</Text>
|
||||
<Text className="home-alert-desc">
|
||||
Updates at 25%, 50%, 75%, and 100%.
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div className="home-alert-row">
|
||||
<checkbox />
|
||||
<div className="home-alert-text">
|
||||
<Text className="home-alert-title">Market updates</Text>
|
||||
<Text className="home-alert-desc">
|
||||
Daily portfolio summary and price alerts.
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="primary" className="home-block-button">
|
||||
Save Preferences
|
||||
</Button>
|
||||
</card-content>
|
||||
</card>
|
||||
|
||||
<card className="home-card" data-column="4">
|
||||
<card-content className="home-card-body home-shortcuts">
|
||||
<breadcrumb path="/Home/Profile/Statements/Documents/Payments" />
|
||||
<item variant="muted" interactive="true">
|
||||
<item-media variant="icon">
|
||||
<icon name="settings" />
|
||||
</item-media>
|
||||
<item-content>
|
||||
<item-title>Change transfer limit</item-title>
|
||||
<item-description>
|
||||
Adjust how much you can send from your balance.
|
||||
</item-description>
|
||||
</item-content>
|
||||
<item-actions>
|
||||
<icon name="chevron-right" />
|
||||
</item-actions>
|
||||
</item>
|
||||
<item variant="muted" interactive="true">
|
||||
<item-media variant="icon">
|
||||
<icon name="calendar-agenda" />
|
||||
</item-media>
|
||||
<item-content>
|
||||
<item-title>Scheduled transfers</item-title>
|
||||
<item-description>
|
||||
Set up a transfer to send at a later date.
|
||||
</item-description>
|
||||
</item-content>
|
||||
<item-actions>
|
||||
<icon name="chevron-right" />
|
||||
</item-actions>
|
||||
</item>
|
||||
<item variant="muted" interactive="true">
|
||||
<item-media variant="icon">
|
||||
<icon name="arrow-clockwise" />
|
||||
</item-media>
|
||||
<item-content>
|
||||
<item-title>Recurring card payments</item-title>
|
||||
<item-description>
|
||||
Manage your repeated card transactions.
|
||||
</item-description>
|
||||
</item-content>
|
||||
<item-actions>
|
||||
<icon name="chevron-right" />
|
||||
</item-actions>
|
||||
</item>
|
||||
</card-content>
|
||||
</card>
|
||||
</home-grid>
|
||||
</div>
|
||||
</div>
|
||||
</ScrollAreaContent>
|
||||
<Scrollbar direction="vertical" />
|
||||
</ScrollArea>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
HomeGallery.shouldPreRender = true;
|
||||
|
||||
export default HomeGallery;
|
||||
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
* app/components/home-grid.c - Responsive gallery used by the doc-viewer home
|
||||
* page.
|
||||
*
|
||||
* Cards are declared as direct children of <home-grid>. They are distributed
|
||||
* over four flex columns once; narrow windows then hide the middle columns
|
||||
* (window >=1400: 1-2-3-4, >=1024: 1-2-4, otherwise: 1-4). Keeping the
|
||||
* assignment fixed avoids reshuffling cards when the window is resized.
|
||||
* LCUI has no media queries, so the strategy lives in C.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <LCUI.h>
|
||||
#include <css.h>
|
||||
#include <ui/mutation_observer.h>
|
||||
#include <ui/prototype.h>
|
||||
#include <ui/style.h>
|
||||
#include "home-grid.h"
|
||||
|
||||
#define HOME_GRID_COLUMNS 4
|
||||
|
||||
typedef struct {
|
||||
bool pending;
|
||||
bool distributing;
|
||||
int visible_columns;
|
||||
ui_widget_t *column_widgets[HOME_GRID_COLUMNS];
|
||||
ui_mutation_observer_t *observer;
|
||||
} home_grid_data_t;
|
||||
|
||||
static ui_widget_prototype_t *home_grid_proto;
|
||||
static ui_widget_prototype_t *home_column_proto;
|
||||
|
||||
static home_grid_data_t *home_grid_get_data(ui_widget_t *w)
|
||||
{
|
||||
return ui_widget_get_data(w, home_grid_proto);
|
||||
}
|
||||
|
||||
static bool home_grid_is_column(ui_widget_t *w)
|
||||
{
|
||||
return w->proto == home_column_proto;
|
||||
}
|
||||
|
||||
static bool home_grid_has_direct_cards(ui_widget_t *w)
|
||||
{
|
||||
list_node_t *node;
|
||||
|
||||
for (list_each(node, &w->children)) {
|
||||
ui_widget_t *child = node->data;
|
||||
|
||||
if (!home_grid_is_column(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void home_grid_ensure_columns(ui_widget_t *w, home_grid_data_t *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < HOME_GRID_COLUMNS; ++i) {
|
||||
if (data->column_widgets[i]) {
|
||||
continue;
|
||||
}
|
||||
data->column_widgets[i] =
|
||||
ui_create_widget_with_prototype(home_column_proto);
|
||||
ui_widget_append(w, data->column_widgets[i]);
|
||||
/* Force the next visibility pass to initialize the column. */
|
||||
data->visible_columns = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t home_grid_collect_cards(ui_widget_t *w, home_grid_data_t *data,
|
||||
ui_widget_t **cards)
|
||||
{
|
||||
size_t count = 0;
|
||||
size_t i;
|
||||
size_t j;
|
||||
ui_widget_t *child;
|
||||
list_node_t *node;
|
||||
|
||||
for (i = 0; i < HOME_GRID_COLUMNS; ++i) {
|
||||
for (j = 0;
|
||||
(child = ui_widget_get_child(data->column_widgets[i], j));
|
||||
++j) {
|
||||
if (cards) {
|
||||
cards[count] = child;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
}
|
||||
for (list_each(node, &w->children)) {
|
||||
child = node->data;
|
||||
if (home_grid_is_column(child)) {
|
||||
continue;
|
||||
}
|
||||
if (cards) {
|
||||
cards[count] = child;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static int home_grid_column_of(ui_widget_t *card, size_t index)
|
||||
{
|
||||
const char *value = ui_widget_get_attr(card, "data-column");
|
||||
|
||||
if (value) {
|
||||
int column = atoi(value);
|
||||
|
||||
if (column >= 1 && column <= HOME_GRID_COLUMNS) {
|
||||
return column - 1;
|
||||
}
|
||||
}
|
||||
return (int)(index % HOME_GRID_COLUMNS);
|
||||
}
|
||||
|
||||
/* Cards are spread over all four columns regardless of the current width so
|
||||
* that hiding a column only affects which cards are visible, not where the
|
||||
* remaining ones sit. */
|
||||
static void home_grid_apply(ui_widget_t *w, home_grid_data_t *data)
|
||||
{
|
||||
size_t count;
|
||||
size_t i;
|
||||
ui_widget_t **cards;
|
||||
|
||||
data->distributing = true;
|
||||
home_grid_ensure_columns(w, data);
|
||||
count = home_grid_collect_cards(w, data, NULL);
|
||||
cards = count ? malloc(sizeof(*cards) * count) : NULL;
|
||||
if (cards) {
|
||||
home_grid_collect_cards(w, data, cards);
|
||||
for (i = 0; i < count; ++i) {
|
||||
ui_widget_append(
|
||||
data->column_widgets[home_grid_column_of(cards[i],
|
||||
i)],
|
||||
cards[i]);
|
||||
}
|
||||
free(cards);
|
||||
}
|
||||
data->pending = false;
|
||||
data->distributing = false;
|
||||
}
|
||||
|
||||
/* Window breakpoints: >=1400 -> 4 columns, >=1024 -> 3, otherwise 2. Read
|
||||
* the root content width so transient widths of intermediate containers
|
||||
* (scrollbar/padding resolution) cannot change the column count. */
|
||||
static int home_grid_columns_for_window(void)
|
||||
{
|
||||
ui_widget_t *root = ui_root();
|
||||
float width;
|
||||
|
||||
if (!root) {
|
||||
return 0;
|
||||
}
|
||||
width = root->content_box.width;
|
||||
if (width <= 0) {
|
||||
return 0;
|
||||
}
|
||||
if (width >= 1400) {
|
||||
return 4;
|
||||
}
|
||||
if (width >= 1024) {
|
||||
return 3;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Wide screens show all four columns; medium hides the third one; narrow
|
||||
* keeps only the first and the last one. Column widths are left to flexbox:
|
||||
* every visible home-column has flex:1 1 0 and min-width:0, so the used grid
|
||||
* width is divided equally without feeding fixed widths back into the scroll
|
||||
* content's min-content size. */
|
||||
static void home_grid_update_visibility(ui_widget_t *w)
|
||||
{
|
||||
home_grid_data_t *data = home_grid_get_data(w);
|
||||
bool visible[HOME_GRID_COLUMNS] = { true, true, true, true };
|
||||
int columns;
|
||||
int i;
|
||||
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
columns = home_grid_columns_for_window();
|
||||
if (columns == 0 || columns == data->visible_columns) {
|
||||
return;
|
||||
}
|
||||
if (columns == 3) {
|
||||
visible[2] = false;
|
||||
} else if (columns == 2) {
|
||||
visible[1] = false;
|
||||
visible[2] = false;
|
||||
}
|
||||
data->visible_columns = columns;
|
||||
for (i = 0; i < HOME_GRID_COLUMNS; ++i) {
|
||||
ui_widget_t *column = data->column_widgets[i];
|
||||
|
||||
if (!column) {
|
||||
continue;
|
||||
}
|
||||
ui_widget_set_style_string(column, "display",
|
||||
visible[i] ? "flex" : "none");
|
||||
}
|
||||
ui_widget_request_reflow(w);
|
||||
}
|
||||
static void home_grid_on_mutation(ui_mutation_list_t *records,
|
||||
ui_mutation_observer_t *observer, void *arg)
|
||||
{
|
||||
ui_widget_t *w = arg;
|
||||
home_grid_data_t *data = home_grid_get_data(w);
|
||||
list_node_t *node;
|
||||
|
||||
if (!data || data->distributing) {
|
||||
return;
|
||||
}
|
||||
for (list_each(node, records)) {
|
||||
ui_mutation_record_t *record = node->data;
|
||||
|
||||
if (record->type != UI_MUTATION_RECORD_TYPE_CHILD_LIST) {
|
||||
continue;
|
||||
}
|
||||
/* Only newly appended cards need a placement pass. Cards that
|
||||
* are already inside a column are not direct children. */
|
||||
if (home_grid_has_direct_cards(w)) {
|
||||
data->pending = true;
|
||||
ui_widget_request_update(w);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* afterlayout is dispatched after the updater has cleared the current pass's
|
||||
* flags. Updating column styles here keeps the request alive for the next
|
||||
* pass; doing it from proto->resize during the current reflow would let
|
||||
* ui_process_mutations() clear the column's pending style update unseen. */
|
||||
static void home_grid_on_root_afterlayout(ui_widget_t *w, ui_event_t *e,
|
||||
void *arg)
|
||||
{
|
||||
home_grid_update_visibility(e->data);
|
||||
}
|
||||
|
||||
static void home_grid_on_link(ui_widget_t *w, ui_event_t *e, void *arg)
|
||||
{
|
||||
home_grid_data_t *data = home_grid_get_data(w);
|
||||
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
/* A pre-rendered page may attach a complete grid after its first
|
||||
* mutation-observer pass. Schedule the placement now so the first
|
||||
* layout after remount already uses columns and their real width. */
|
||||
if (home_grid_has_direct_cards(w)) {
|
||||
data->pending = true;
|
||||
}
|
||||
ui_widget_request_reflow(w);
|
||||
}
|
||||
|
||||
static void home_grid_on_update(ui_widget_t *w, ui_task_type_t task)
|
||||
{
|
||||
home_grid_data_t *data = home_grid_get_data(w);
|
||||
|
||||
if (!data || data->distributing || task != UI_TASK_BEFORE_UPDATE) {
|
||||
return;
|
||||
}
|
||||
if (data->pending) {
|
||||
home_grid_apply(w, data);
|
||||
}
|
||||
home_grid_update_visibility(w);
|
||||
}
|
||||
|
||||
static void home_grid_on_destroy(ui_widget_t *w)
|
||||
{
|
||||
home_grid_data_t *data = home_grid_get_data(w);
|
||||
|
||||
if (ui_root()) {
|
||||
ui_widget_off(ui_root(), "afterlayout",
|
||||
home_grid_on_root_afterlayout, w);
|
||||
}
|
||||
if (data && data->observer) {
|
||||
ui_mutation_observer_destroy(data->observer);
|
||||
data->observer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void home_grid_on_init(ui_widget_t *w)
|
||||
{
|
||||
ui_mutation_observer_init_t options = { .child_list = true };
|
||||
home_grid_data_t *data =
|
||||
ui_widget_add_data(w, home_grid_proto, sizeof(*data));
|
||||
|
||||
memset(data, 0, sizeof(*data));
|
||||
data->observer = ui_mutation_observer_create(home_grid_on_mutation, w);
|
||||
ui_mutation_observer_observe(data->observer, w, options);
|
||||
ui_widget_on(w, "link", home_grid_on_link, w);
|
||||
ui_widget_on(ui_root(), "afterlayout", home_grid_on_root_afterlayout,
|
||||
w);
|
||||
}
|
||||
|
||||
void ui_register_home_grid(void)
|
||||
{
|
||||
home_column_proto = ui_create_widget_prototype("home-column", NULL);
|
||||
home_grid_proto = ui_create_widget_prototype("home-grid", NULL);
|
||||
home_grid_proto->init = home_grid_on_init;
|
||||
home_grid_proto->update = home_grid_on_update;
|
||||
home_grid_proto->destroy = home_grid_on_destroy;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* app/components/home-grid.h - Public registration entry for the home page's
|
||||
* responsive multi-column gallery. See home-grid.c for behavior.
|
||||
*/
|
||||
|
||||
#ifndef DOC_VIEWER_COMPONENTS_HOME_GRID_H
|
||||
#define DOC_VIEWER_COMPONENTS_HOME_GRID_H
|
||||
|
||||
void ui_register_home_grid(void);
|
||||
|
||||
#endif
|
||||
@@ -215,17 +215,26 @@ static void navbar_apply_route(ui_widget_t *w, const char *path)
|
||||
{
|
||||
navbar_t *that = navbar_get(w);
|
||||
const wchar_t *title;
|
||||
const char *last_segment;
|
||||
wchar_t buf[256];
|
||||
|
||||
navbar_sync_locale_from_path(w, path);
|
||||
if (path && that->base.refs.path) {
|
||||
ui_text_set_content(that->base.refs.path, path);
|
||||
}
|
||||
title = route_title_for(path);
|
||||
if (title && *title) {
|
||||
swprintf(buf, 256, L"%ls \u00b7 LCUI", title);
|
||||
last_segment = path ? strrchr(path, '/') : NULL;
|
||||
if (last_segment && strcmp(last_segment, "/home") == 0) {
|
||||
/* Mirror the product page titles used by documentation sites:
|
||||
* the home title is the product name plus its tagline. */
|
||||
wcscpy(buf,
|
||||
L"LCUI - The C library for building user interfaces");
|
||||
} else {
|
||||
wcscpy(buf, L"LCUI");
|
||||
title = route_title_for(path);
|
||||
if (title && *title) {
|
||||
swprintf(buf, 256, L"%ls \u00b7 LCUI", title);
|
||||
} else {
|
||||
wcscpy(buf, L"LCUI");
|
||||
}
|
||||
}
|
||||
ui_widget_set_title(ui_root(), buf);
|
||||
}
|
||||
@@ -300,9 +309,19 @@ ui_widget_t *ui_create_navbar(void)
|
||||
return ui_create_widget_with_prototype(navbar_proto);
|
||||
}
|
||||
|
||||
static void navbar_on_resize(ui_widget_t *w, float width, float height)
|
||||
{
|
||||
if (width < 700.0f) {
|
||||
ui_widget_add_class(w, "compact");
|
||||
} else {
|
||||
ui_widget_remove_class(w, "compact");
|
||||
}
|
||||
}
|
||||
|
||||
void ui_register_navbar(void)
|
||||
{
|
||||
navbar_init_prototype();
|
||||
navbar_proto->init = navbar_init;
|
||||
navbar_proto->destroy = navbar_destroy;
|
||||
navbar_proto->resize = navbar_on_resize;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,24 @@
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Narrow windows: drop the path/version/GitHub columns so the three nav
|
||||
* buttons keep their full width instead of being clipped by the column. */
|
||||
.navbar.compact {
|
||||
padding: 0 8px;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.navbar.compact .navbar-center,
|
||||
.navbar.compact .navbar-version,
|
||||
.navbar.compact .navbar-link {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.navbar.compact .navbar-left,
|
||||
.navbar.compact .navbar-right {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.navbar-path {
|
||||
width: 100%;
|
||||
max-width: 320px;
|
||||
|
||||
@@ -12,7 +12,8 @@ export default function Navbar() {
|
||||
$ref="nav_home"
|
||||
onClick="navbar_on_nav_click"
|
||||
>
|
||||
Home
|
||||
<Text className="lang en">Home</Text>
|
||||
<Text className="lang zh-CN">首页</Text>
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -20,7 +21,8 @@ export default function Navbar() {
|
||||
$ref="nav_docs"
|
||||
onClick="navbar_on_nav_click"
|
||||
>
|
||||
Docs
|
||||
<Text className="lang en">Docs</Text>
|
||||
<Text className="lang zh-CN">文档</Text>
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -28,7 +30,8 @@ export default function Navbar() {
|
||||
$ref="nav_widgets"
|
||||
onClick="navbar_on_nav_click"
|
||||
>
|
||||
Widgets
|
||||
<Text className="lang en">Widgets</Text>
|
||||
<Text className="lang zh-CN">部件</Text>
|
||||
</Button>
|
||||
</div>
|
||||
<div className="navbar-center">
|
||||
@@ -40,9 +43,7 @@ export default function Navbar() {
|
||||
<dropdown-menu $ref="locale_menu">
|
||||
<dropdown-menu-trigger>
|
||||
<Button variant="ghost" size="icon" $ref="locale_btn">
|
||||
<Text className="relative left-[3px] text-xs">
|
||||
文
|
||||
</Text>
|
||||
<Text className="relative left-[3px] text-xs">文</Text>
|
||||
<Text className="relative bottom-[-5px] right-[3px] text-xs">
|
||||
A
|
||||
</Text>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {
|
||||
import {
|
||||
PropsWithChildren,
|
||||
ScrollArea,
|
||||
ScrollAreaContent,
|
||||
@@ -11,7 +11,9 @@ export default function EnDocsLayout({ children }: PropsWithChildren) {
|
||||
<div className="flex flex-1 min-h-0 h-full pl-2">
|
||||
<DocsSidebar locale="en" />
|
||||
<ScrollArea className="flex-1">
|
||||
<ScrollAreaContent>{children}</ScrollAreaContent>
|
||||
<ScrollAreaContent className="docs-scroll-content">
|
||||
{children}
|
||||
</ScrollAreaContent>
|
||||
<Scrollbar direction="vertical" />
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
@@ -29,7 +29,7 @@ function chunk(source: SidebarItemData[], size: number): SidebarItemData[][] {
|
||||
|
||||
export default function EnWidgetsPage() {
|
||||
return (
|
||||
<div className="widgets-index">
|
||||
<div className="doc-page widgets-index">
|
||||
<Text className="widgets-index-title">Widgets</Text>
|
||||
<Text className="widgets-index-desc">
|
||||
Here you can find all widgets available in the library.
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
import { Text } from "@lcui/react";
|
||||
import HomeGallery from "../../components/home-gallery";
|
||||
|
||||
export default function EnHomePage() {
|
||||
return (
|
||||
<div className="home-page">
|
||||
<Text className="home-title">LCUI</Text>
|
||||
<Text className="home-desc">
|
||||
A C UI library for desktop interfaces. Component docs and examples live here.
|
||||
</Text>
|
||||
</div>
|
||||
);
|
||||
return <HomeGallery locale="en" />;
|
||||
}
|
||||
|
||||
@@ -846,25 +846,524 @@ li {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
padding: 96px 48px;
|
||||
}
|
||||
|
||||
.home-inner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
max-width: 1560px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
padding: 72px 48px 96px;
|
||||
}
|
||||
|
||||
.home-hero {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.home-title {
|
||||
font-size: 40px;
|
||||
font-size: 48px;
|
||||
font-weight: 700;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.home-desc {
|
||||
margin-top: 16px;
|
||||
max-width: 720px;
|
||||
margin-top: 12px;
|
||||
font-size: 18px;
|
||||
color: #666666;
|
||||
line-height: 1.6;
|
||||
color: #555555;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.home-cta {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
margin-top: 28px;
|
||||
}
|
||||
|
||||
home-grid {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
gap: 24px;
|
||||
margin-top: 56px;
|
||||
}
|
||||
|
||||
home-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1 1 0;
|
||||
gap: 24px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.home-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
padding: 0;
|
||||
border: 1px solid #e5e5e5;
|
||||
border-radius: 14px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.home-card card-header {
|
||||
gap: 12px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.home-card card-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.home-card card-description {
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
.home-card .home-card-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.home-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.home-row-between {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.home-preview-desc {
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
/* Shared form pieces */
|
||||
|
||||
.home-card field {
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.home-field-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.home-field-half {
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.home-card field-label {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.home-field-link {
|
||||
font-size: 11px;
|
||||
color: #888888;
|
||||
}
|
||||
|
||||
.home-input {
|
||||
height: 36px;
|
||||
padding-top: 7px;
|
||||
padding-bottom: 7px;
|
||||
}
|
||||
|
||||
.home-textarea {
|
||||
height: 96px;
|
||||
}
|
||||
|
||||
.home-block-button {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* Controls card */
|
||||
|
||||
.home-controls {
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.home-controls .home-row {
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
.home-controls button,
|
||||
.home-controls .button {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.home-controls radio-group {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* Attachment card */
|
||||
|
||||
.home-attachment-card {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* Savings targets card */
|
||||
|
||||
.home-goal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 18px;
|
||||
border-radius: 10px;
|
||||
background: #f7f7f7;
|
||||
}
|
||||
|
||||
.home-goal-label {
|
||||
font-size: 11px;
|
||||
color: #888888;
|
||||
}
|
||||
|
||||
.home-goal-value {
|
||||
font-size: 30px;
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.home-goal-progress {
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
.home-goal-meta {
|
||||
font-size: 12px;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
.home-goal-footer {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.home-goal-caption {
|
||||
font-size: 12px;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
.home-goal-amount {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: #111111;
|
||||
}
|
||||
|
||||
/* Claimable balance card */
|
||||
|
||||
.home-claim-label {
|
||||
font-size: 13px;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
.home-balance {
|
||||
font-size: 34px;
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.home-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 4px;
|
||||
background: #f5b301;
|
||||
}
|
||||
|
||||
.home-summary {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
min-height: 120px;
|
||||
padding: 14px;
|
||||
border-radius: 10px;
|
||||
background: #f7f7f7;
|
||||
}
|
||||
|
||||
.home-summary .home-row-between .home-summary-label {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
|
||||
.home-summary .home-row-between .home-summary-value {
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.home-summary .home-row-between .home-summary-total {
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.home-summary-label {
|
||||
font-size: 13px;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
.home-summary-value {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.home-summary-total {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.home-divider {
|
||||
height: 1px;
|
||||
background: #e5e5e5;
|
||||
}
|
||||
|
||||
/* Accordion and deployment cards */
|
||||
|
||||
.home-accordion {
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.home-accordion accordion-trigger text {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
|
||||
.home-deployment {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.home-deploy-live-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background: #16a34a;
|
||||
}
|
||||
|
||||
.home-deploy-progress {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.home-deploy-environment {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #555555;
|
||||
}
|
||||
|
||||
.home-deploy-percent {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.home-deploy-steps {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.home-deploy-steps item {
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
|
||||
.home-deploy-step-meta {
|
||||
flex-shrink: 0;
|
||||
font-size: 11px;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
.home-deploy-actions {
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.home-deploy-redeploy {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Milestone, payout and account cards */
|
||||
|
||||
.home-milestone,
|
||||
.home-payout,
|
||||
.home-account {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.home-account {
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.home-payout .home-textarea {
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.home-payout-amount {
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.home-select {
|
||||
width: 100%;
|
||||
height: 36px;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.home-payout dropdown-menu,
|
||||
.home-payout dropdown-menu-trigger {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.home-slider {
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background: #eeeeee;
|
||||
}
|
||||
|
||||
.home-slider-fill {
|
||||
width: 25%;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
background: #111111;
|
||||
}
|
||||
|
||||
.home-danger {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.home-account item,
|
||||
.home-shortcuts item {
|
||||
min-height: 76px;
|
||||
}
|
||||
|
||||
.home-card item {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.home-danger item-media {
|
||||
color: #e7000b;
|
||||
}
|
||||
|
||||
/* Empty card */
|
||||
|
||||
.home-empty empty,
|
||||
.home-empty empty-header,
|
||||
.home-empty empty-content,
|
||||
.home-empty button {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.home-empty empty {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.home-empty empty-header {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.home-empty empty-title,
|
||||
.home-empty empty-description {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.home-empty empty-content {
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.home-empty-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 8px;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.home-empty-icon icon {
|
||||
top: 0;
|
||||
height: 16px;
|
||||
font-size: 16px;
|
||||
line-height: 16px;
|
||||
}
|
||||
|
||||
/* Notifications card */
|
||||
|
||||
.home-alerts {
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.home-alert-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
/* Align the 16px control with the first text line instead of its box top. */
|
||||
.home-alert-row checkbox {
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.home-alert-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1 1 auto;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.home-alert-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.home-alert-desc {
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: #777777;
|
||||
}
|
||||
|
||||
/* Shortcuts card */
|
||||
|
||||
.home-shortcuts {
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.home-shortcuts breadcrumb {
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
/* The vertical docs scroll area fills the viewport; wide content (code
|
||||
* blocks) must not stretch the scroll content, otherwise `margin: auto`
|
||||
* pages center inside an off-screen wider box. */
|
||||
.docs-scroll-content {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* -- Widgets index ---------------------------------------------------- */
|
||||
|
||||
.widgets-index {
|
||||
width: 100%;
|
||||
max-width: 960px;
|
||||
padding: 40px 48px;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "components/home-grid.h"
|
||||
#include "components/list.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
@@ -44,6 +45,7 @@ int main(int argc, char *argv[])
|
||||
app_init();
|
||||
register_semantic_text_aliases();
|
||||
ui_register_list_widgets();
|
||||
ui_register_home_grid();
|
||||
|
||||
router_t *router = router_get_by_name("AppRouter");
|
||||
const char *locale = app_get_locale();
|
||||
@@ -52,8 +54,8 @@ int main(int argc, char *argv[])
|
||||
char initial_path[128];
|
||||
router_location_t *location;
|
||||
|
||||
snprintf(initial_path, sizeof(initial_path),
|
||||
"/%s/docs/overview/quick-start", locale ? locale : "en");
|
||||
snprintf(initial_path, sizeof(initial_path), "/%s/home",
|
||||
locale ? locale : "en");
|
||||
location = router_location_create(NULL, initial_path);
|
||||
router_push(router, location);
|
||||
router_location_destroy(location);
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { PropsWithChildren, ScrollArea, ScrollAreaContent, Scrollbar } from "@lcui/react";
|
||||
import {
|
||||
PropsWithChildren,
|
||||
ScrollArea,
|
||||
ScrollAreaContent,
|
||||
Scrollbar,
|
||||
} from "@lcui/react";
|
||||
import DocsSidebar from "../../components/sidebar";
|
||||
|
||||
export default function ZhCnDocsLayout({ children }: PropsWithChildren) {
|
||||
@@ -6,7 +11,9 @@ export default function ZhCnDocsLayout({ children }: PropsWithChildren) {
|
||||
<div className="flex flex-1 min-h-0 h-full pl-2">
|
||||
<DocsSidebar locale="zh-CN" />
|
||||
<ScrollArea className="flex-1">
|
||||
<ScrollAreaContent>{children}</ScrollAreaContent>
|
||||
<ScrollAreaContent className="docs-scroll-content">
|
||||
{children}
|
||||
</ScrollAreaContent>
|
||||
<Scrollbar direction="vertical" />
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
@@ -28,7 +28,7 @@ function chunk(source: SidebarItemData[], size: number): SidebarItemData[][] {
|
||||
|
||||
export default function ZhCnWidgetsPage() {
|
||||
return (
|
||||
<div className="widgets-index">
|
||||
<div className="doc-page widgets-index">
|
||||
<Text className="widgets-index-title">部件</Text>
|
||||
<Text className="widgets-index-desc">
|
||||
这里可以找到当前提供的全部部件。
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
import { Text } from "@lcui/react";
|
||||
import HomeGallery from "../../components/home-gallery";
|
||||
|
||||
export default function ZhCnHomePage() {
|
||||
return (
|
||||
<div className="home-page">
|
||||
<Text className="home-title">LCUI</Text>
|
||||
<Text className="home-desc">
|
||||
用于构建桌面界面的 C 语言 UI 库,组件文档与示例都在这里。
|
||||
</Text>
|
||||
</div>
|
||||
);
|
||||
return <HomeGallery locale="zh-CN" />;
|
||||
}
|
||||
|
||||
@@ -77,16 +77,28 @@ $code = @"
|
||||
#include <pandagl.h>
|
||||
#include <ui/metrics.h>
|
||||
|
||||
/* 取当前树中高度最大的 scrollarea,文档页里即正文滚动区。 */
|
||||
/* 取当前树中高度最大的非侧栏 scrollarea,文档页里即正文滚动区。
|
||||
* 侧栏自己也有 ScrollArea,且与正文等高,只按高度会误选。 */
|
||||
static bool debug_inside_sidebar(ui_widget_t *w)
|
||||
{
|
||||
for (w = w->parent; w; w = w->parent) {
|
||||
if (ui_check_widget_type(w, "sidebar")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void debug_find_scrollarea(ui_widget_t *w, void *arg)
|
||||
{
|
||||
ui_widget_t **target = arg;
|
||||
|
||||
if (w->type && strcmp(w->type, "scrollarea") == 0) {
|
||||
if (!*target ||
|
||||
w->border_box.height > (*target)->border_box.height) {
|
||||
*target = w;
|
||||
}
|
||||
if (!ui_check_widget_type(w, "scrollarea") ||
|
||||
debug_inside_sidebar(w)) {
|
||||
return;
|
||||
}
|
||||
if (!*target || w->border_box.height > (*target)->border_box.height) {
|
||||
*target = w;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +164,7 @@ $restore = {
|
||||
try {
|
||||
$patched = $originalLf.Replace("#include `"main.h`"", "#include `"main.h`"`n$code")
|
||||
$patched = $patched.Replace(
|
||||
" snprintf(initial_path, sizeof(initial_path),`n `"/%s/docs/overview/quick-start`", locale ? locale : `"en`");",
|
||||
" snprintf(initial_path, sizeof(initial_path), `"/%s/home`",`n locale ? locale : `"en`");",
|
||||
" snprintf(initial_path, sizeof(initial_path), `"%s`", `"$Route`");")
|
||||
$patched = $patched.Replace(
|
||||
" ui_widget_resize(ui_root(), 1280, 720);`n lcui_bind_window_state(ui_root(), `"main`");`n`n return app_run();",
|
||||
@@ -169,10 +181,20 @@ try {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
$p = Start-Process -FilePath $exe -WorkingDirectory (Join-Path $root "examples\doc-viewer\dist") -PassThru
|
||||
$logDir = Join-Path $env:TEMP "opencode"
|
||||
if (-not (Test-Path $logDir)) {
|
||||
New-Item -ItemType Directory -Path $logDir | Out-Null
|
||||
}
|
||||
$errLog = Join-Path $logDir "docview-render.log"
|
||||
$p = Start-Process -FilePath $exe -WorkingDirectory (Join-Path $root "examples\doc-viewer\dist") -WindowStyle Hidden -RedirectStandardError $errLog -RedirectStandardOutput (Join-Path $logDir "docview-render.out") -PassThru
|
||||
$p.WaitForExit(120000) | Out-Null
|
||||
if (-not $p.HasExited) {
|
||||
Stop-Process -Id $p.Id -Force
|
||||
} else {
|
||||
Write-Output ("render exited: {0}" -f $p.ExitCode)
|
||||
}
|
||||
if (Test-Path $errLog) {
|
||||
Get-Content $errLog -ErrorAction SilentlyContinue | Select-Object -Last 20
|
||||
}
|
||||
} finally {
|
||||
& $restore
|
||||
|
||||
@@ -749,7 +749,7 @@ dropdown-menu-group {
|
||||
|
||||
dropdown-menu-label {
|
||||
display: block;
|
||||
@apply px-2 py-1.5 text-sm font-medium;
|
||||
@apply px-1.5 py-1 text-xs font-medium text-muted-foreground;
|
||||
}
|
||||
|
||||
dropdown-menu-item,
|
||||
|
||||
@@ -852,13 +852,14 @@ static const struct {
|
||||
{ "}\n", 2 },
|
||||
{ "dropdown-menu-label {\n", 22 },
|
||||
{ " display: block;\n", 18 },
|
||||
{ " padding-left: 8px;\n", 21 },
|
||||
{ " padding-right: 8px;\n", 22 },
|
||||
{ " padding-top: 6px;\n", 20 },
|
||||
{ " padding-bottom: 6px;\n", 23 },
|
||||
{ " font-size: 14px;\n", 19 },
|
||||
{ " line-height: 20px;\n", 21 },
|
||||
{ " padding-left: 6px;\n", 21 },
|
||||
{ " padding-right: 6px;\n", 22 },
|
||||
{ " padding-top: 4px;\n", 20 },
|
||||
{ " padding-bottom: 4px;\n", 23 },
|
||||
{ " font-size: 12px;\n", 19 },
|
||||
{ " line-height: 16px;\n", 21 },
|
||||
{ " font-weight: 500;\n", 20 },
|
||||
{ " color: #666666;\n", 18 },
|
||||
{ "}\n", 2 },
|
||||
{ "dropdown-menu-item,\n", 20 },
|
||||
{ "dropdown-menu-checkbox-item,\n", 29 },
|
||||
@@ -1777,7 +1778,7 @@ static const struct {
|
||||
{ " color: #000;\n", 15 },
|
||||
{ "}\n", 2 },
|
||||
};
|
||||
static const size_t css_str_style_nova_total_length = 32960;
|
||||
static const size_t css_str_style_nova_total_length = 32978;
|
||||
static inline void ui_load_css_string_style_nova_chunks(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* tests/fixtures/test_gallery_layout.css
|
||||
*
|
||||
* Mirrors the doc-viewer home gallery: a scroll area, a centered
|
||||
* max-width page container, and the home-grid widget with flexible
|
||||
* columns. The `test-*` classes keep the fixture independent from
|
||||
* style-nova.
|
||||
*/
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.test-home-scroll {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.test-home-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.test-home-inner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
max-width: 1560px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
padding: 72px 48px 96px;
|
||||
}
|
||||
|
||||
home-grid {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
gap: 24px;
|
||||
margin-top: 56px;
|
||||
}
|
||||
|
||||
home-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1 1 0;
|
||||
gap: 24px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.test-home-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
border: 1px solid #e5e5e5;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.test-home-card .test-home-card-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.test-home-body-block {
|
||||
height: 200px;
|
||||
background: #f7f7f7;
|
||||
}
|
||||
|
||||
.test-home-empty empty,
|
||||
.test-home-empty empty-header,
|
||||
.test-home-empty empty-content,
|
||||
.test-home-empty button {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.test-home-empty empty {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.test-home-empty empty-header {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.test-home-empty empty-description {
|
||||
text-align: center;
|
||||
}
|
||||
@@ -0,0 +1,890 @@
|
||||
/*
|
||||
* tests/integration/test_gallery_layout.c
|
||||
*
|
||||
* Copyright (c) 2026, Liu Chao <hello@lcui.dev> All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* This file is part of LCUI, distributed under the MIT License found in the
|
||||
* LICENSE.TXT file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The doc-viewer home gallery is a home-grid widget inside a scroll area.
|
||||
* Flexible columns must follow both programmatic and native window resizes,
|
||||
* and a hover style refresh inside a card must not reflow the card at the
|
||||
* page's max-content width before the column width is applied.
|
||||
*
|
||||
* home-grid lives in the doc-viewer app. Compiling that single component
|
||||
* into this target keeps the test against the real implementation instead
|
||||
* of a copy of its layout code.
|
||||
*/
|
||||
|
||||
#include <LCUI.h>
|
||||
#include <css.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctest-custom.h>
|
||||
#include "../../examples/doc-viewer/app/global.css.h"
|
||||
|
||||
#define HOME_GRID_COLUMNS 4
|
||||
#define HOME_GAP 24.0f
|
||||
#define PAGE_GUTTER 96.0f
|
||||
#define PAGE_MAX_WIDTH 1560.0f
|
||||
|
||||
void ui_register_home_grid(void);
|
||||
void ui_widget_get_sizehint(ui_widget_t *w, ui_sizehint_t *hint);
|
||||
|
||||
typedef struct {
|
||||
ui_widget_t *scroll;
|
||||
ui_widget_t *page;
|
||||
ui_widget_t *inner;
|
||||
ui_widget_t *grid;
|
||||
ui_widget_t *cards[HOME_GRID_COLUMNS];
|
||||
ui_widget_t *bodies[HOME_GRID_COLUMNS];
|
||||
ui_widget_t *columns[HOME_GRID_COLUMNS];
|
||||
ui_widget_t *accordion;
|
||||
ui_widget_t *accordion_triggers[2];
|
||||
ui_widget_t *accordion_contents[2];
|
||||
ui_widget_t *production_card;
|
||||
ui_widget_t *production_desc;
|
||||
ui_widget_t *production_icon_box;
|
||||
ui_widget_t *production_icon;
|
||||
ui_widget_t *empty_widget;
|
||||
ui_widget_t *empty_header;
|
||||
ui_widget_t *empty_desc;
|
||||
ui_widget_t *empty_content;
|
||||
ui_widget_t *empty_button;
|
||||
float min_empty_height;
|
||||
float max_empty_height;
|
||||
int empty_height_passes;
|
||||
float min_card_width;
|
||||
float max_card_width;
|
||||
float min_card_height;
|
||||
float max_card_height;
|
||||
int layout_passes;
|
||||
} home_grid_scene_t;
|
||||
|
||||
static home_grid_scene_t *scene;
|
||||
|
||||
static ui_widget_t *create_box(const char *class_name)
|
||||
{
|
||||
ui_widget_t *w = ui_create_widget(NULL);
|
||||
|
||||
ui_widget_add_class(w, class_name);
|
||||
return w;
|
||||
}
|
||||
|
||||
static void home_scene_collect_columns(ui_widget_t *w, void *arg)
|
||||
{
|
||||
home_grid_scene_t *s = arg;
|
||||
int i;
|
||||
|
||||
if (!ui_check_widget_type(w, "home-column")) {
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < HOME_GRID_COLUMNS; ++i) {
|
||||
if (!s->columns[i]) {
|
||||
s->columns[i] = w;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void home_scene_record_card(ui_widget_t *w, ui_event_t *e, void *arg)
|
||||
{
|
||||
home_grid_scene_t *s = e->data;
|
||||
ui_widget_t *card = w->parent ? w->parent : w;
|
||||
float width = card->border_box.width;
|
||||
float height = w->border_box.height;
|
||||
|
||||
if (width <= 0) {
|
||||
return;
|
||||
}
|
||||
++s->layout_passes;
|
||||
if (width < s->min_card_width) {
|
||||
s->min_card_width = width;
|
||||
}
|
||||
if (width > s->max_card_width) {
|
||||
s->max_card_width = width;
|
||||
}
|
||||
if (s->min_card_height == 0 || height < s->min_card_height) {
|
||||
s->min_card_height = height;
|
||||
}
|
||||
if (height > s->max_card_height) {
|
||||
s->max_card_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
static void home_scene_record_empty(ui_widget_t *w, ui_event_t *e, void *arg)
|
||||
{
|
||||
home_grid_scene_t *s = e->data;
|
||||
float height = w->border_box.height;
|
||||
|
||||
if (height <= 0) {
|
||||
return;
|
||||
}
|
||||
if (height < s->min_empty_height) {
|
||||
s->min_empty_height = height;
|
||||
}
|
||||
if (height > s->max_empty_height) {
|
||||
s->max_empty_height = height;
|
||||
}
|
||||
++s->empty_height_passes;
|
||||
}
|
||||
|
||||
static void home_scene_build_accordion(ui_widget_t *body)
|
||||
{
|
||||
ui_widget_t *header = ui_create_card_header();
|
||||
ui_widget_t *title = ui_create_card_title();
|
||||
ui_widget_t *description = ui_create_card_description();
|
||||
ui_widget_t *first = ui_create_accordion_item();
|
||||
ui_widget_t *second = ui_create_accordion_item();
|
||||
ui_widget_t *first_text = ui_create_widget("text");
|
||||
ui_widget_t *second_text = ui_create_widget("text");
|
||||
|
||||
scene->accordion = ui_create_accordion();
|
||||
scene->accordion_triggers[0] = ui_create_accordion_trigger();
|
||||
scene->accordion_triggers[1] = ui_create_accordion_trigger();
|
||||
scene->accordion_contents[0] = ui_create_accordion_content();
|
||||
scene->accordion_contents[1] = ui_create_accordion_content();
|
||||
ui_text_set_content(title, "Subscription & Billing");
|
||||
ui_text_set_content(description, "Common questions about your plan.");
|
||||
ui_text_set_content(first_text, "What plans are available?");
|
||||
ui_text_set_content(second_text,
|
||||
"Billing occurs automatically at the start of each "
|
||||
"cycle. We accept all major credit cards, PayPal "
|
||||
"and ACH transfers. Enterprise customers can also "
|
||||
"request invoices and review every past payment "
|
||||
"before changing their subscription.");
|
||||
ui_widget_append(header, title);
|
||||
ui_widget_append(header, description);
|
||||
ui_widget_append(first, scene->accordion_triggers[0]);
|
||||
ui_widget_append(first, scene->accordion_contents[0]);
|
||||
ui_widget_append(scene->accordion_contents[0], first_text);
|
||||
ui_widget_append(second, scene->accordion_triggers[1]);
|
||||
ui_widget_append(second, scene->accordion_contents[1]);
|
||||
ui_widget_append(scene->accordion_contents[1], second_text);
|
||||
ui_accordion_item_set_value(first, "plans");
|
||||
ui_accordion_item_set_value(second, "billing");
|
||||
ui_accordion_item_set_open(first, true);
|
||||
ui_widget_append(scene->accordion, first);
|
||||
ui_widget_append(scene->accordion, second);
|
||||
ui_widget_append(body, header);
|
||||
ui_widget_append(body, scene->accordion);
|
||||
}
|
||||
|
||||
static void home_scene_build_production_empty(void)
|
||||
{
|
||||
ui_widget_t *body = ui_create_card_content();
|
||||
ui_widget_t *empty = ui_create_empty();
|
||||
ui_widget_t *header = ui_create_empty_header();
|
||||
ui_widget_t *icon_box = ui_create_widget(NULL);
|
||||
ui_widget_t *icon = ui_create_fluent_icon("add");
|
||||
ui_widget_t *title = ui_create_empty_title();
|
||||
ui_widget_t *content = ui_create_empty_content();
|
||||
ui_widget_t *button = ui_create_button();
|
||||
|
||||
scene->production_desc = ui_create_empty_description();
|
||||
scene->production_icon_box = icon_box;
|
||||
scene->production_icon = icon;
|
||||
scene->production_card = ui_create_card();
|
||||
ui_widget_add_class(scene->production_card, "home-card");
|
||||
ui_widget_set_attr(scene->production_card, "data-column", "4");
|
||||
ui_widget_add_class(body, "home-card-body home-empty");
|
||||
ui_widget_add_class(icon_box, "home-empty-icon");
|
||||
ui_text_set_content(title, "Distribute Track");
|
||||
ui_text_set_content(scene->production_desc,
|
||||
"Upload your first master to start reaching "
|
||||
"listeners on Spotify, Apple Music, and more.");
|
||||
ui_button_set_text(button, "Create Release");
|
||||
ui_button_set_variant(button, UI_BUTTON_VARIANT_PRIMARY);
|
||||
ui_widget_append(icon_box, icon);
|
||||
ui_widget_append(header, icon_box);
|
||||
ui_widget_append(header, title);
|
||||
ui_widget_append(header, scene->production_desc);
|
||||
ui_widget_append(content, button);
|
||||
ui_widget_append(empty, header);
|
||||
ui_widget_append(empty, content);
|
||||
ui_widget_append(body, empty);
|
||||
ui_widget_append(scene->production_card, body);
|
||||
ui_widget_append(scene->grid, scene->production_card);
|
||||
}
|
||||
|
||||
static void home_scene_build(void)
|
||||
{
|
||||
ui_widget_t *content = ui_create_scrollarea_content();
|
||||
int i;
|
||||
char column[8];
|
||||
|
||||
scene = calloc(1, sizeof(*scene));
|
||||
scene->scroll = ui_create_scrollarea();
|
||||
scene->page = create_box("test-home-page");
|
||||
scene->inner = create_box("test-home-inner");
|
||||
scene->grid = ui_create_widget("home-grid");
|
||||
|
||||
ui_widget_add_class(scene->scroll, "test-home-scroll");
|
||||
ui_widget_append(scene->scroll, content);
|
||||
ui_widget_append(scene->scroll, ui_create_scrollbar());
|
||||
ui_widget_append(content, scene->page);
|
||||
ui_widget_append(scene->page, scene->inner);
|
||||
ui_widget_append(scene->inner, scene->grid);
|
||||
|
||||
for (i = 0; i < HOME_GRID_COLUMNS; ++i) {
|
||||
scene->cards[i] = ui_create_card();
|
||||
ui_widget_add_class(scene->cards[i], "test-home-card");
|
||||
scene->bodies[i] = ui_create_card_content();
|
||||
ui_widget_add_class(scene->bodies[i], "test-home-card-body");
|
||||
if (i == HOME_GRID_COLUMNS - 1) {
|
||||
ui_widget_t *empty = ui_create_empty();
|
||||
ui_widget_t *header = ui_create_empty_header();
|
||||
ui_widget_t *description =
|
||||
ui_create_empty_description();
|
||||
ui_widget_t *empty_content = ui_create_empty_content();
|
||||
ui_widget_t *button = ui_create_button();
|
||||
|
||||
ui_text_set_content(
|
||||
description,
|
||||
"Upload your first master to start reaching "
|
||||
"listeners on Spotify, Apple Music, and more.");
|
||||
ui_button_set_text(button, "Create Release");
|
||||
ui_button_set_variant(button,
|
||||
UI_BUTTON_VARIANT_PRIMARY);
|
||||
ui_widget_append(header, description);
|
||||
ui_widget_append(empty_content, button);
|
||||
ui_widget_append(empty, header);
|
||||
ui_widget_append(empty, empty_content);
|
||||
ui_widget_add_class(scene->bodies[i],
|
||||
"test-home-empty");
|
||||
ui_widget_add_class(scene->bodies[i], "clip-safe");
|
||||
ui_widget_append(scene->bodies[i], empty);
|
||||
scene->empty_widget = empty;
|
||||
scene->empty_header = header;
|
||||
scene->empty_desc = description;
|
||||
scene->empty_content = empty_content;
|
||||
scene->empty_button = button;
|
||||
} else if (i == 1) {
|
||||
home_scene_build_accordion(scene->bodies[i]);
|
||||
} else {
|
||||
ui_widget_append(scene->bodies[i],
|
||||
create_box("test-home-body-block"));
|
||||
}
|
||||
ui_widget_append(scene->cards[i], scene->bodies[i]);
|
||||
snprintf(column, sizeof(column), "%d", i + 1);
|
||||
ui_widget_set_attr(scene->cards[i], "data-column", column);
|
||||
ui_widget_append(scene->grid, scene->cards[i]);
|
||||
}
|
||||
home_scene_build_production_empty();
|
||||
ui_widget_append(ui_root(), scene->scroll);
|
||||
ui_widget_on(scene->bodies[HOME_GRID_COLUMNS - 1], "afterlayout",
|
||||
home_scene_record_card, scene);
|
||||
ui_widget_on(scene->empty_desc, "afterlayout", home_scene_record_empty,
|
||||
scene);
|
||||
}
|
||||
|
||||
static void home_scene_update(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* The resize pass applies flex widths and queues breakpoint changes
|
||||
* from root afterlayout; the following pass applies those changes. */
|
||||
for (i = 0; i < 2; ++i) {
|
||||
ui_update();
|
||||
}
|
||||
ui_widget_each(scene->grid, home_scene_collect_columns, scene);
|
||||
}
|
||||
|
||||
static void home_scene_resize(float width, float height)
|
||||
{
|
||||
ui_widget_resize(ui_root(), width, height);
|
||||
home_scene_update();
|
||||
}
|
||||
|
||||
static void home_scene_native_resize(float width, float height)
|
||||
{
|
||||
ptk_window_t *window = ui_server_get_window(ui_root());
|
||||
float scale = ui_get_actual_scale();
|
||||
int i;
|
||||
|
||||
ptk_window_set_size(window, (int)(width * scale),
|
||||
(int)(height * scale));
|
||||
for (i = 0; i < 8; ++i) {
|
||||
ptk_process_native_events(PTK_PROCESS_EVENTS_ALL_IF_PRESENT);
|
||||
ui_update();
|
||||
y_sleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
static int home_scene_visible_columns(void)
|
||||
{
|
||||
int i;
|
||||
int count = 0;
|
||||
|
||||
for (i = 0; i < HOME_GRID_COLUMNS; ++i) {
|
||||
if (!scene->columns[i]) {
|
||||
continue;
|
||||
}
|
||||
if (css_computed_display(&scene->columns[i]->computed_style) !=
|
||||
CSS_DISPLAY_NONE) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static float home_scene_expected_column_width(float root_width)
|
||||
{
|
||||
float page_width =
|
||||
root_width < PAGE_MAX_WIDTH ? root_width : PAGE_MAX_WIDTH;
|
||||
float available = page_width - PAGE_GUTTER;
|
||||
int columns = root_width >= 1400.0f ? 4 : root_width >= 1024.0f ? 3 : 2;
|
||||
|
||||
return (available - HOME_GAP * (columns - 1)) / columns;
|
||||
}
|
||||
|
||||
static void home_scene_destroy(void)
|
||||
{
|
||||
ui_widget_destroy(scene->scroll);
|
||||
ui_clear_trash();
|
||||
free(scene);
|
||||
scene = NULL;
|
||||
}
|
||||
|
||||
static void test_columns_follow_window(void)
|
||||
{
|
||||
static const float widths[] = { 1600.0f, 1100.0f, 800.0f, 1500.0f };
|
||||
static const int visible[] = { 4, 3, 2, 4 };
|
||||
float expected;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
home_scene_resize(1600.0f, 1000.0f);
|
||||
for (i = 0; i < sizeof(widths) / sizeof(widths[0]); ++i) {
|
||||
if (i > 0) {
|
||||
home_scene_resize(widths[i], 1000.0f);
|
||||
}
|
||||
expected = home_scene_expected_column_width(widths[i]);
|
||||
ctest_equal_int("should keep the breakpoint column count",
|
||||
home_scene_visible_columns(), visible[i]);
|
||||
ctest_equal_float(
|
||||
"gallery should fit the available page width",
|
||||
scene->grid->content_box.width,
|
||||
expected * visible[i] + HOME_GAP * (visible[i] - 1));
|
||||
ctest_equal_float(
|
||||
"page content should follow the window width",
|
||||
scene->inner->content_box.width,
|
||||
expected * visible[i] + HOME_GAP * (visible[i] - 1));
|
||||
for (j = 0; j < HOME_GRID_COLUMNS; ++j) {
|
||||
if (!scene->columns[j]) {
|
||||
continue;
|
||||
}
|
||||
if (css_computed_display(
|
||||
&scene->columns[j]->computed_style) ==
|
||||
CSS_DISPLAY_NONE) {
|
||||
continue;
|
||||
}
|
||||
ctest_equal_float(
|
||||
"visible column should follow the window width",
|
||||
scene->columns[j]->border_box.width, expected);
|
||||
ctest_equal_float(
|
||||
"visible column should share free space with flex "
|
||||
"grow",
|
||||
scene->columns[j]->computed_style.flex_grow, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ui_widget_t *columns[HOME_GRID_COLUMNS];
|
||||
int count;
|
||||
} gallery_columns_t;
|
||||
|
||||
static void collect_gallery_column(ui_widget_t *w, void *arg)
|
||||
{
|
||||
gallery_columns_t *columns = arg;
|
||||
|
||||
if (!ui_check_widget_type(w, "home-column") ||
|
||||
columns->count >= HOME_GRID_COLUMNS) {
|
||||
return;
|
||||
}
|
||||
columns->columns[columns->count++] = w;
|
||||
}
|
||||
|
||||
static void test_initial_mount_single_pass(void)
|
||||
{
|
||||
gallery_columns_t columns = { 0 };
|
||||
ui_widget_t *parent = create_box("test-home-page");
|
||||
ui_widget_t *grid = ui_create_widget("home-grid");
|
||||
float expected;
|
||||
int i;
|
||||
|
||||
ui_widget_set_style_string(parent, "display", "flex");
|
||||
ui_widget_set_style_string(parent, "flex-direction", "column");
|
||||
ui_widget_set_style_string(parent, "width", "1600px");
|
||||
for (i = 0; i < HOME_GRID_COLUMNS; ++i) {
|
||||
ui_widget_t *card = ui_create_card();
|
||||
char column[8];
|
||||
|
||||
ui_widget_add_class(card, "test-home-card");
|
||||
snprintf(column, sizeof(column), "%d", i + 1);
|
||||
ui_widget_set_attr(card, "data-column", column);
|
||||
ui_widget_append(card, create_box("test-home-body-block"));
|
||||
ui_widget_append(grid, card);
|
||||
}
|
||||
ui_widget_append(parent, grid);
|
||||
ui_widget_append(ui_root(), parent);
|
||||
ui_update();
|
||||
ui_widget_each(grid, collect_gallery_column, &columns);
|
||||
|
||||
expected = (1600.0f - HOME_GAP * 3) / 4;
|
||||
ctest_equal_int("initial mount should create all columns in one pass",
|
||||
columns.count, HOME_GRID_COLUMNS);
|
||||
for (i = 0; i < columns.count; ++i) {
|
||||
ctest_equal_float(
|
||||
"initial mount column should use the available width",
|
||||
columns.columns[i]->border_box.width, expected);
|
||||
}
|
||||
ui_widget_destroy(parent);
|
||||
}
|
||||
|
||||
static void test_remount_after_width_change(void)
|
||||
{
|
||||
float expected;
|
||||
int i;
|
||||
|
||||
home_scene_resize(1600.0f, 1000.0f);
|
||||
ui_widget_unlink(scene->scroll);
|
||||
ui_widget_resize(ui_root(), 1100.0f, 1000.0f);
|
||||
ui_widget_append(ui_root(), scene->scroll);
|
||||
home_scene_update();
|
||||
|
||||
expected = home_scene_expected_column_width(1100.0f);
|
||||
ctest_equal_int("remounted gallery should keep the breakpoint count",
|
||||
home_scene_visible_columns(), 3);
|
||||
ctest_equal_float("remounted gallery should use the current width",
|
||||
scene->grid->content_box.width,
|
||||
expected * 3 + HOME_GAP * 2);
|
||||
for (i = 0; i < HOME_GRID_COLUMNS; ++i) {
|
||||
if (!scene->columns[i] ||
|
||||
css_computed_display(&scene->columns[i]->computed_style) ==
|
||||
CSS_DISPLAY_NONE) {
|
||||
continue;
|
||||
}
|
||||
ctest_equal_float(
|
||||
"remounted visible column should use the current width",
|
||||
scene->columns[i]->border_box.width, expected);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_native_window_resize(void)
|
||||
{
|
||||
static const float widths[] = { 1600.0f, 1100.0f, 800.0f, 1500.0f };
|
||||
static const int visible[] = { 4, 3, 2, 4 };
|
||||
float expected;
|
||||
float root_width;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < sizeof(widths) / sizeof(widths[0]); ++i) {
|
||||
home_scene_native_resize(widths[i], 1000.0f);
|
||||
root_width = ui_root()->content_box.width;
|
||||
expected = home_scene_expected_column_width(root_width);
|
||||
ctest_equal_bool("native resize should update the root width",
|
||||
fabsf(root_width - widths[i]) < 2.0f, true);
|
||||
ctest_equal_int("native resize should update the column count",
|
||||
home_scene_visible_columns(), visible[i]);
|
||||
ctest_equal_float(
|
||||
"native resize should shrink the gallery content",
|
||||
scene->grid->content_box.width,
|
||||
expected * visible[i] + HOME_GAP * (visible[i] - 1));
|
||||
for (j = 0; j < HOME_GRID_COLUMNS; ++j) {
|
||||
if (!scene->columns[j] ||
|
||||
css_computed_display(
|
||||
&scene->columns[j]->computed_style) ==
|
||||
CSS_DISPLAY_NONE) {
|
||||
continue;
|
||||
}
|
||||
ctest_equal_float(
|
||||
"native resize should update the used column width",
|
||||
scene->columns[j]->border_box.width, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void home_scene_click(ui_widget_t *target)
|
||||
{
|
||||
ui_event_t e;
|
||||
|
||||
ui_event_init(&e, "click");
|
||||
e.target = target;
|
||||
ui_widget_emit_event(target, e, NULL);
|
||||
}
|
||||
|
||||
static void test_accordion_card_resize(void)
|
||||
{
|
||||
float initial;
|
||||
float expanded;
|
||||
float restored;
|
||||
float closed;
|
||||
|
||||
home_scene_resize(1600.0f, 1000.0f);
|
||||
initial = scene->cards[1]->border_box.height;
|
||||
home_scene_click(scene->accordion_triggers[1]);
|
||||
home_scene_update();
|
||||
expanded = scene->cards[1]->border_box.height;
|
||||
ctest_equal_bool("accordion card should grow for longer content",
|
||||
expanded > initial + 1.0f, true);
|
||||
|
||||
home_scene_click(scene->accordion_triggers[0]);
|
||||
home_scene_update();
|
||||
restored = scene->cards[1]->border_box.height;
|
||||
ctest_equal_float("accordion card should shrink when content changes",
|
||||
restored, initial);
|
||||
|
||||
home_scene_click(scene->accordion_triggers[0]);
|
||||
home_scene_update();
|
||||
closed = scene->cards[1]->border_box.height;
|
||||
ctest_equal_bool("accordion card should shrink when content closes",
|
||||
closed < restored - 1.0f, true);
|
||||
}
|
||||
|
||||
static void test_empty_description_hover(void)
|
||||
{
|
||||
ui_widget_t *w;
|
||||
float x;
|
||||
float width;
|
||||
float height;
|
||||
|
||||
home_scene_resize(1600.0f, 1000.0f);
|
||||
x = scene->empty_desc->border_box.x;
|
||||
width = scene->empty_desc->border_box.width;
|
||||
height = scene->empty_desc->border_box.height;
|
||||
for (w = scene->empty_desc; w; w = w->parent) {
|
||||
ui_widget_add_status(w, "hover");
|
||||
}
|
||||
home_scene_update();
|
||||
ctest_equal_float("description hover should keep its x",
|
||||
scene->empty_desc->border_box.x, x);
|
||||
ctest_equal_float("description hover should keep its width",
|
||||
scene->empty_desc->border_box.width, width);
|
||||
ctest_equal_float("description hover should keep its height",
|
||||
scene->empty_desc->border_box.height, height);
|
||||
|
||||
for (w = scene->empty_desc; w; w = w->parent) {
|
||||
ui_widget_remove_status(w, "hover");
|
||||
}
|
||||
home_scene_update();
|
||||
ctest_equal_float("leaving description hover should restore its x",
|
||||
scene->empty_desc->border_box.x, x);
|
||||
ctest_equal_float("leaving description hover should restore its width",
|
||||
scene->empty_desc->border_box.width, width);
|
||||
ctest_equal_float("leaving description hover should restore its height",
|
||||
scene->empty_desc->border_box.height, height);
|
||||
}
|
||||
|
||||
static int render_description_ink(ui_widget_t *container,
|
||||
ui_widget_t *description, double *centroid_x)
|
||||
{
|
||||
pd_canvas_t canvas;
|
||||
pd_context_t paint;
|
||||
pd_rect_t rect;
|
||||
pd_color_t color;
|
||||
float scale = ui_get_actual_scale();
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
int left;
|
||||
int top;
|
||||
int right;
|
||||
int bottom;
|
||||
int px;
|
||||
int py;
|
||||
int count = 0;
|
||||
double sum_x = 0;
|
||||
|
||||
ui_widget_get_offset(description, container, &x, &y);
|
||||
left = (int)(x * scale);
|
||||
top = (int)(y * scale);
|
||||
right = (int)((x + description->border_box.width) * scale);
|
||||
bottom = (int)((y + description->border_box.height) * scale);
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.width = (int)(container->border_box.width * scale);
|
||||
rect.height = (int)(container->border_box.height * scale);
|
||||
pd_canvas_init(&canvas);
|
||||
canvas.color_type = PD_COLOR_TYPE_ARGB;
|
||||
if (pd_canvas_create(&canvas, (unsigned)rect.width,
|
||||
(unsigned)rect.height) != 0) {
|
||||
return 0;
|
||||
}
|
||||
pd_canvas_fill(&canvas, pd_rgb(255, 255, 255));
|
||||
paint.with_alpha = true;
|
||||
paint.rect = rect;
|
||||
pd_canvas_init(&paint.canvas);
|
||||
pd_canvas_quote(&paint.canvas, &canvas, &rect);
|
||||
ui_widget_render(container, &paint);
|
||||
for (py = top; py < bottom; ++py) {
|
||||
for (px = left; px < right; ++px) {
|
||||
color = pd_canvas_get_pixel(&canvas, (unsigned)px,
|
||||
(unsigned)py);
|
||||
if (color.r < 220 || color.g < 220 || color.b < 220) {
|
||||
sum_x += px;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
pd_canvas_destroy(&paint.canvas);
|
||||
pd_canvas_destroy(&canvas);
|
||||
*centroid_x = count > 0 ? sum_x / count : -1.0;
|
||||
return count;
|
||||
}
|
||||
|
||||
static void test_production_description_hover(void)
|
||||
{
|
||||
ui_widget_t *description = scene->production_desc;
|
||||
ui_widget_t *w;
|
||||
ui_sizehint_t hint = { 0 };
|
||||
float x;
|
||||
float width;
|
||||
double ink_x;
|
||||
double hint_ink_x;
|
||||
double hover_ink_x;
|
||||
double restored_ink_x;
|
||||
int ink_pixels;
|
||||
int hint_ink_pixels;
|
||||
int hover_ink_pixels;
|
||||
int restored_ink_pixels;
|
||||
|
||||
ui_load_css_string_global_chunks();
|
||||
home_scene_resize(1600.0f, 1000.0f);
|
||||
ui_update();
|
||||
ui_update();
|
||||
|
||||
x = description->border_box.x;
|
||||
width = description->border_box.width;
|
||||
ink_pixels =
|
||||
render_description_ink(scene->production_card, description, &ink_x);
|
||||
ui_widget_get_sizehint(description, &hint);
|
||||
hint_ink_pixels = render_description_ink(scene->production_card,
|
||||
description, &hint_ink_x);
|
||||
ctest_equal_bool("sizehint should still render description text",
|
||||
hint_ink_pixels > 0, true);
|
||||
ctest_equal_float(
|
||||
"sizehint should not move already rendered description text",
|
||||
(float)(hint_ink_x - ink_x), 0.0f);
|
||||
|
||||
for (w = description; w; w = w->parent) {
|
||||
ui_widget_add_status(w, "hover");
|
||||
}
|
||||
ui_update();
|
||||
ctest_equal_float("production description hover should keep its x",
|
||||
description->border_box.x, x);
|
||||
ctest_equal_float("production description hover should keep its width",
|
||||
description->border_box.width, width);
|
||||
hover_ink_pixels = render_description_ink(scene->production_card,
|
||||
description, &hover_ink_x);
|
||||
ctest_equal_bool("production description hover should render text",
|
||||
hover_ink_pixels > 0, true);
|
||||
ctest_equal_bool("baseline description should render text",
|
||||
ink_pixels > 0, true);
|
||||
ctest_equal_float(
|
||||
"production description hover should not move rendered text",
|
||||
(float)(hover_ink_x - ink_x), 0.0f);
|
||||
|
||||
for (w = description; w; w = w->parent) {
|
||||
ui_widget_remove_status(w, "hover");
|
||||
}
|
||||
home_scene_update();
|
||||
ctest_equal_float("production description hover should restore its x",
|
||||
description->border_box.x, x);
|
||||
ctest_equal_float(
|
||||
"production description hover should restore its width",
|
||||
description->border_box.width, width);
|
||||
restored_ink_pixels = render_description_ink(
|
||||
scene->production_card, description, &restored_ink_x);
|
||||
ctest_equal_bool("restored description should render text",
|
||||
restored_ink_pixels > 0, true);
|
||||
ctest_equal_float(
|
||||
"leaving description hover should restore rendered text",
|
||||
(float)(restored_ink_x - ink_x), 0.0f);
|
||||
}
|
||||
|
||||
static void test_production_empty_icon(void)
|
||||
{
|
||||
ui_widget_t *box = scene->production_icon_box;
|
||||
ui_widget_t *icon = scene->production_icon;
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float icon_center;
|
||||
float box_center;
|
||||
|
||||
ui_load_css_string_global_chunks();
|
||||
home_scene_resize(1600.0f, 1000.0f);
|
||||
ui_update();
|
||||
ui_update();
|
||||
ui_widget_get_offset(icon, box, &x, &y);
|
||||
icon_center = y + icon->border_box.height * 0.5f;
|
||||
box_center = box->border_box.height * 0.5f;
|
||||
|
||||
ctest_equal_float("empty icon should keep a 16px border box",
|
||||
icon->border_box.height, 16.0f);
|
||||
ctest_equal_float("empty icon should be vertically centered",
|
||||
icon_center, box_center);
|
||||
}
|
||||
|
||||
static void test_gallery_empty_hover(void)
|
||||
{
|
||||
static const float widths[] = { 1600, 1500, 1400, 1300, 1280,
|
||||
1200, 1100, 1000, 900, 800 };
|
||||
ui_widget_t *w;
|
||||
float height;
|
||||
float description_x;
|
||||
float description_width;
|
||||
int i, j;
|
||||
|
||||
if (!scene->empty_desc || !scene->empty_button) {
|
||||
return;
|
||||
}
|
||||
for (j = 0; j < (int)(sizeof(widths) / sizeof(widths[0])); ++j) {
|
||||
home_scene_resize(widths[j], 1000.0f);
|
||||
height = scene->empty_desc->border_box.height;
|
||||
description_x = scene->empty_desc->border_box.x;
|
||||
description_width = scene->empty_desc->border_box.width;
|
||||
ctest_equal_bool("empty description should wrap",
|
||||
height > 30.0f, true);
|
||||
ctest_equal_float("clip-safe body should keep top padding",
|
||||
scene->bodies[3]->computed_style.padding_top,
|
||||
20.0f);
|
||||
ctest_equal_float(
|
||||
"clip-safe body should keep right padding",
|
||||
scene->bodies[3]->computed_style.padding_right, 20.0f);
|
||||
ctest_equal_float(
|
||||
"clip-safe body should keep bottom padding",
|
||||
scene->bodies[3]->computed_style.padding_bottom, 20.0f);
|
||||
ctest_equal_float("clip-safe body should keep left padding",
|
||||
scene->bodies[3]->computed_style.padding_left,
|
||||
20.0f);
|
||||
ctest_equal_bool("empty card should contain its padded body",
|
||||
scene->cards[3]->border_box.height + 0.5f >=
|
||||
scene->bodies[3]->border_box.height,
|
||||
true);
|
||||
ctest_equal_bool("empty body should contain the empty widget",
|
||||
scene->bodies[3]->content_box.height + 0.5f >=
|
||||
scene->empty_widget->border_box.height,
|
||||
true);
|
||||
ctest_equal_bool(
|
||||
"empty widget should contain the description",
|
||||
scene->empty_widget->content_box.height + 0.5f >= height,
|
||||
true);
|
||||
ctest_equal_bool(
|
||||
"empty content should contain its fixed-height button",
|
||||
scene->empty_content->content_box.height + 0.5f >=
|
||||
scene->empty_button->border_box.height,
|
||||
true);
|
||||
ctest_equal_bool(
|
||||
"empty widget should fit its stacked children",
|
||||
scene->empty_widget->border_box.height + 0.5f >=
|
||||
height + scene->empty_button->border_box.height +
|
||||
16.0f + 48.0f,
|
||||
true);
|
||||
scene->min_empty_height = FLT_MAX;
|
||||
scene->max_empty_height = 0;
|
||||
scene->empty_height_passes = 0;
|
||||
|
||||
for (w = scene->empty_button; w; w = w->parent) {
|
||||
ui_widget_add_status(w, "hover");
|
||||
}
|
||||
home_scene_update();
|
||||
ctest_equal_bool("hover should reflow the empty card",
|
||||
scene->empty_height_passes > 0, true);
|
||||
ctest_equal_float("hover should not change the empty height",
|
||||
scene->max_empty_height,
|
||||
scene->min_empty_height);
|
||||
ctest_equal_float(
|
||||
"hover should keep the empty description height",
|
||||
scene->empty_desc->border_box.height, height);
|
||||
ctest_equal_float("hover should keep the empty description x",
|
||||
scene->empty_desc->border_box.x,
|
||||
description_x);
|
||||
ctest_equal_float(
|
||||
"hover should keep the empty description width",
|
||||
scene->empty_desc->border_box.width, description_width);
|
||||
|
||||
for (w = scene->empty_button; w; w = w->parent) {
|
||||
ui_widget_remove_status(w, "hover");
|
||||
}
|
||||
for (i = 0; i < 3; ++i) {
|
||||
ui_update();
|
||||
}
|
||||
ctest_equal_float(
|
||||
"leaving hover should keep the empty description height",
|
||||
scene->empty_desc->border_box.height, height);
|
||||
ctest_equal_float(
|
||||
"leaving hover should restore the empty description x",
|
||||
scene->empty_desc->border_box.x, description_x);
|
||||
ctest_equal_float(
|
||||
"leaving hover should restore the empty description width",
|
||||
scene->empty_desc->border_box.width, description_width);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_hover_keeps_column_width(void)
|
||||
{
|
||||
float column_width;
|
||||
ui_widget_t *body = scene->bodies[HOME_GRID_COLUMNS - 1];
|
||||
|
||||
home_scene_resize(1600.0f, 1000.0f);
|
||||
if (!scene->columns[0]) {
|
||||
return;
|
||||
}
|
||||
column_width = scene->columns[0]->border_box.width;
|
||||
scene->min_card_width = FLT_MAX;
|
||||
scene->max_card_width = 0;
|
||||
scene->min_card_height = 0;
|
||||
scene->max_card_height = 0;
|
||||
scene->layout_passes = 0;
|
||||
|
||||
ui_widget_add_status(body, "hover");
|
||||
home_scene_update();
|
||||
|
||||
ctest_equal_bool("hover should reflow the card body",
|
||||
scene->layout_passes > 0, true);
|
||||
ctest_equal_bool(
|
||||
"hover reflow should not stretch the card to the page width",
|
||||
scene->max_card_width < column_width + 0.5f, true);
|
||||
ctest_equal_bool("hover reflow should not collapse the card",
|
||||
scene->min_card_width > column_width - 0.5f, true);
|
||||
ctest_equal_float("hover should not change the card height",
|
||||
scene->max_card_height - scene->min_card_height,
|
||||
0.0f);
|
||||
ui_widget_remove_status(body, "hover");
|
||||
home_scene_update();
|
||||
}
|
||||
|
||||
void test_gallery_layout(void)
|
||||
{
|
||||
lcui_init();
|
||||
ptk_window_hide(ui_server_get_window(ui_root()));
|
||||
ui_register_home_grid();
|
||||
ui_load_css_file("test_gallery_layout.css");
|
||||
ui_widget_set_title(ui_root(), L"test gallery layout");
|
||||
home_scene_build();
|
||||
|
||||
ctest_describe("gallery columns", test_columns_follow_window);
|
||||
ctest_describe("gallery initial mount", test_initial_mount_single_pass);
|
||||
ctest_describe("gallery remount", test_remount_after_width_change);
|
||||
ctest_describe("gallery native window resize",
|
||||
test_native_window_resize);
|
||||
ctest_describe("gallery accordion resize", test_accordion_card_resize);
|
||||
ctest_describe("gallery description hover",
|
||||
test_empty_description_hover);
|
||||
ctest_describe("gallery hover", test_hover_keeps_column_width);
|
||||
ctest_describe("gallery empty hover", test_gallery_empty_hover);
|
||||
ctest_describe("production description hover",
|
||||
test_production_description_hover);
|
||||
ctest_describe("production empty icon", test_production_empty_icon);
|
||||
|
||||
home_scene_destroy();
|
||||
lcui_destroy();
|
||||
}
|
||||
@@ -32,6 +32,7 @@ extern void test_flex_contract(void);
|
||||
extern void test_empty_layout(void);
|
||||
extern void test_field_layout(void);
|
||||
extern void test_home_layout(void);
|
||||
extern void test_gallery_layout(void);
|
||||
extern void test_background_style(void);
|
||||
extern void test_style_refresh(void);
|
||||
extern void test_flex_hidden_gap(void);
|
||||
@@ -92,6 +93,7 @@ static const ctest_suite_t suites[] = {
|
||||
{ "empty layout", test_empty_layout },
|
||||
{ "field layout", test_field_layout },
|
||||
{ "home layout", test_home_layout },
|
||||
{ "gallery layout", test_gallery_layout },
|
||||
{ "background style", test_background_style },
|
||||
{ "style refresh", test_style_refresh },
|
||||
{ "flex hidden gap", test_flex_hidden_gap },
|
||||
|
||||
@@ -4,7 +4,9 @@ target("lcui-tests")
|
||||
set_group("tests")
|
||||
set_rundir("fixtures")
|
||||
add_includedirs("helpers")
|
||||
add_includedirs("../examples/doc-viewer/app/components")
|
||||
add_files("main.c", "integration/*.c", "scenes/*.c")
|
||||
add_files("../examples/doc-viewer/app/components/home-grid.c")
|
||||
add_deps("lcui", "ctest")
|
||||
add_rules("tests.runnable")
|
||||
add_tests("default", {group = "tests"})
|
||||
|
||||
Reference in New Issue
Block a user