From 9c68927c6a9a5b49b92f84707cbe44ef5a158dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr> Date: Fri, 27 Oct 2023 12:11:00 +0200 Subject: [PATCH] [ivette/sandbox] icons gallery --- ivette/src/dome/renderer/controls/icons.tsx | 7 +- ivette/src/sandbox/icons.tsx | 76 +++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 ivette/src/sandbox/icons.tsx diff --git a/ivette/src/dome/renderer/controls/icons.tsx b/ivette/src/dome/renderer/controls/icons.tsx index a4d00f54121..2821f316da3 100644 --- a/ivette/src/dome/renderer/controls/icons.tsx +++ b/ivette/src/dome/renderer/controls/icons.tsx @@ -214,11 +214,16 @@ export function register(icon: CustomIcon): void { Icons[id] = jsicon; } +export interface IconData extends CustomIcon { + section?: string; + title?: string; +} + /** Iterate over icons gallery. See [[register]] to add custom icons to the gallery. */ -export function forEach(fn: (ico: CustomIcon) => void): void { +export function forEach(fn: (ico: IconData) => void): void { const ids = Object.keys(Icons); ids.forEach((id) => { const jsicon = Icons[id]; diff --git a/ivette/src/sandbox/icons.tsx b/ivette/src/sandbox/icons.tsx new file mode 100644 index 00000000000..a3d4335767f --- /dev/null +++ b/ivette/src/sandbox/icons.tsx @@ -0,0 +1,76 @@ +/* ************************************************************************ */ +/* */ +/* This file is part of Frama-C. */ +/* */ +/* Copyright (C) 2007-2023 */ +/* CEA (Commissariat à l'énergie atomique et aux énergies */ +/* alternatives) */ +/* */ +/* you can redistribute it and/or modify it under the terms of the GNU */ +/* Lesser General Public License as published by the Free Software */ +/* Foundation, version 2.1. */ +/* */ +/* It is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU Lesser General Public License for more details. */ +/* */ +/* See the GNU Lesser General Public License version 2.1 */ +/* for more details (enclosed in the file licenses/LGPLv2.1). */ +/* */ +/* ************************************************************************ */ + +/* -------------------------------------------------------------------------- */ +/* --- Sandbox Icons Gallery --- */ +/* --- Only appears in DEVEL mode. --- */ +/* -------------------------------------------------------------------------- */ + +import React from 'react'; +import { Label, Code } from 'dome/controls/labels'; +import { IconData, forEach } from 'dome/controls/icons'; +import { Section } from 'dome/frame/sidebars'; +import { Scroll, Grid } from 'dome/layout/boxes'; +import { registerSandbox } from 'ivette'; + +/* -------------------------------------------------------------------------- */ +/* --- Use Text --- */ +/* -------------------------------------------------------------------------- */ + +function Gallery(): JSX.Element { + const gallery : Map<string, JSX.Element[]> = new Map(); + forEach((icon: IconData) => { + const { id, title, section='Custom Icons' } = icon; + let icons = gallery.get(section); + if (icons === undefined) { + icons = []; + gallery.set(section, icons); + } + icons.push( + <> + <Code icon={id} label={id} /> + <Label>{title}</Label> + </> + ); + }); + const sections : JSX.Element[] = []; + gallery.forEach((icons, section) => { + sections.push( + <Section key={section} defaultUnfold label={section}> + <Grid columns="auto auto">{icons}</Grid> + </Section> + ); + }); + return <Scroll>{sections}</Scroll>; +} + +/* -------------------------------------------------------------------------- */ +/* --- Sandbox --- */ +/* -------------------------------------------------------------------------- */ + +registerSandbox({ + id: 'sandbox.icons', + label: 'Icons Gallery', + children: <Gallery />, +}); + +/* -------------------------------------------------------------------------- */ -- GitLab