issue187:inkscape
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue187:inkscape [2022/11/27 17:00] – d52fr | issue187:inkscape [2022/11/30 18:37] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
As a reminder, so far I’ve created a mock-up design consisting of three layers, each representing a different page in a website (which could equally well have been a design for an app, tutorial or presentation). By stacking the layers on top of each other, the JS code simply has to hide all the layers, then re-show the right one when the mock UI is clicked. This code is stored in the Inkscape document, and accessed via File > Document Properties, then the Scripting tab, the Embedded Scripts tab, and finally clicking on the randomly-generated Script ID in the list. Your code will appear in the Content pane at the bottom of the dialog – which is unfortunately not resizeable (you may wish to copy/paste between Inkscape and a text editor to make it easier to modify the code). After last month’s additions, the code looks like that shown above.** | As a reminder, so far I’ve created a mock-up design consisting of three layers, each representing a different page in a website (which could equally well have been a design for an app, tutorial or presentation). By stacking the layers on top of each other, the JS code simply has to hide all the layers, then re-show the right one when the mock UI is clicked. This code is stored in the Inkscape document, and accessed via File > Document Properties, then the Scripting tab, the Embedded Scripts tab, and finally clicking on the randomly-generated Script ID in the list. Your code will appear in the Content pane at the bottom of the dialog – which is unfortunately not resizeable (you may wish to copy/paste between Inkscape and a text editor to make it easier to modify the code). After last month’s additions, the code looks like that shown above.** | ||
+ | |||
+ | Au cours des deux derniers articles, j'ai présenté l' | ||
+ | |||
+ | Pour rappel, jusqu' | ||
+ | |||
**Within each interactive element, a single line of JS triggers the change to a different ‘page’ of the demo. These can be found by right-clicking on one of the elements, selecting Object Properties, then expanding the Interactivity section at the bottom of the dialog. For my examples, I’m just triggering changes on mouse clicks, so the ‘onclick’ field contains something like this: | **Within each interactive element, a single line of JS triggers the change to a different ‘page’ of the demo. These can be found by right-clicking on one of the elements, selecting Object Properties, then expanding the Interactivity section at the bottom of the dialog. For my examples, I’m just triggering changes on mouse clicks, so the ‘onclick’ field contains something like this: | ||
Ligne 10: | Ligne 15: | ||
When looking at the pages of our mock website, it’s clear that they have some common elements – in this case the whole header section. Wouldn’t it be nice if we could keep those on a separate layer, so that any changes to those elements can be made in a single place, rather than having to apply them to each separate layer in our file? This is the sort of thing for which many applications use a ‘Master’ layer. Although not as politically charged as the use of ‘master-slave’ relationships in the computing world, it’s nonetheless a term that can offend people, and which is tending to be phased out. So rather than propagate a troublesome word for no real gain, I’ll be using the term ‘Main layer’.** | When looking at the pages of our mock website, it’s clear that they have some common elements – in this case the whole header section. Wouldn’t it be nice if we could keep those on a separate layer, so that any changes to those elements can be made in a single place, rather than having to apply them to each separate layer in our file? This is the sort of thing for which many applications use a ‘Master’ layer. Although not as politically charged as the use of ‘master-slave’ relationships in the computing world, it’s nonetheless a term that can offend people, and which is tending to be phased out. So rather than propagate a troublesome word for no real gain, I’ll be using the term ‘Main layer’.** | ||
+ | |||
+ | Dans chaque élément interactif, une seule ligne de JS déclenche le passage à une autre « page » de la démo. Vous pouvez les trouver en cliquant avec le bouton droit de la souris sur l'un des éléments, en sélectionnant Propriétés de l' | ||
+ | |||
+ | showLayer(" | ||
+ | |||
+ | C'est tout ce dont nous avions besoin pour créer une maquette interactive qui s' | ||
+ | |||
+ | Lorsque l'on regarde les pages de notre site Web fictif, il est clair qu' | ||
+ | |||
**Our first step, therefore, is to split the file into a single Main layer, plus one additional layer for each page. The Main layer will contain all the common elements, and the others will contain just the page-specific parts. We therefore want our Main layer to be at the bottom of the z-stack, and to remain visible at all times. Here’s how our existing three layers are split into the four we now need: | **Our first step, therefore, is to split the file into a single Main layer, plus one additional layer for each page. The Main layer will contain all the common elements, and the others will contain just the page-specific parts. We therefore want our Main layer to be at the bottom of the z-stack, and to remain visible at all times. Here’s how our existing three layers are split into the four we now need: | ||
Ligne 16: | Ligne 30: | ||
By showing the Main layer, plus one of the others at a time, we can therefore reproduce the same appearance as the three layers in the old version. All we need to do now is to modify our code to do the same thing on our behalf. To make the new code a little more readable, we’ll first use the XML editor to change the ID of the new layer to ‘main’, in the same way that we changed the layer IDs previously. When viewed in the XML editor, the top level of our document now looks something like that shown above.** | By showing the Main layer, plus one of the others at a time, we can therefore reproduce the same appearance as the three layers in the old version. All we need to do now is to modify our code to do the same thing on our behalf. To make the new code a little more readable, we’ll first use the XML editor to change the ID of the new layer to ‘main’, in the same way that we changed the layer IDs previously. When viewed in the XML editor, the top level of our document now looks something like that shown above.** | ||
+ | |||
+ | Notre première étape consiste donc à diviser le fichier en un seul calque principal, plus un calque supplémentaire pour chaque page. Le calque principal contiendra tous les éléments communs, et les autres ne contiendront que les parties spécifiques à la page. Nous voulons donc que notre calque principal se trouve en bas de la pile z et qu'il reste visible à tout moment. Voici comment nos trois calques existants sont divisés en quatre calques dont nous avons maintenant besoin (en haut à gauche). | ||
+ | |||
+ | À gauche, nous avons les trois pages précédentes. À droite, nous avons maintenant notre calque principal en bas, avec les trois calques de contenu au-dessus. J'ai ajouté une bordure verte autour de chacune des couches de contenu pour indiquer leur étendue : elles ont toutes un arrière-plan transparent ; sans cela, leur lien avec leurs positions dans les anciennes pages ne serait pas très clair. Ces bordures vertes sont un ajout temporaire pendant le développement de la maquette, et seront retirées avant que les calques ne soient réellement utilisés. En outre, bien que j'aie étalé les pages sur cette image, dans la pratique, elles sont toutes empilées les unes sur les autres dans la fenêtre (viewBox) du document, comme auparavant. | ||
+ | |||
+ | En affichant le calque principal, plus un des autres à la fois, nous pouvons donc reproduire la même apparence que les trois calques de l' | ||
+ | |||
**Looking back at our JavaScript file from earlier, we still want our function to perform the same basic task: hide all the layers, then show a specific one. Except now we also want it to show a second layer at the same time. It’s these two lines that are responsible for re-showing the specified layer in the existing code: | **Looking back at our JavaScript file from earlier, we still want our function to perform the same basic task: hide all the layers, then show a specific one. Except now we also want it to show a second layer at the same time. It’s these two lines that are responsible for re-showing the specified layer in the existing code: | ||
Ligne 28: | Ligne 49: | ||
const layersToDisplay = [" | const layersToDisplay = [" | ||
+ | |||
+ | En regardant notre fichier JavaScript de tout à l' | ||
+ | |||
+ | const layerToShow = document.querySelector("#" | ||
+ | |||
+ | layerToShow.style.display = " | ||
+ | |||
+ | Nous pourrions simplement ajouter une paire de lignes similaires, en codant en dur l'ID dans l' | ||
+ | |||
+ | const layersToDisplay = [" | ||
+ | |||
**Now we need to step through the array, pulling out one item at a time to work with. As we pull each of them out (using a forEach() loop), we get to assign the value to a variable. By naming this variable ‘id’, we are able to reuse our existing code for finding and showing the layer. The end result is something very similar to the code that was previously at the end of the showLayer() function, just with a little more wrapped around it (shown above). | **Now we need to step through the array, pulling out one item at a time to work with. As we pull each of them out (using a forEach() loop), we get to assign the value to a variable. By naming this variable ‘id’, we are able to reuse our existing code for finding and showing the layer. The end result is something very similar to the code that was previously at the end of the showLayer() function, just with a little more wrapped around it (shown above). | ||
Ligne 34: | Ligne 66: | ||
So far, so good. But on trying out your interactive mock-up, you may have noticed that the mouse pointer doesn’t change to indicate that elements are clickable. It’s a minor visual thing, but we can definitely improve it. There are various ways to tackle this, but they all end up with us needing a line of CSS that tells the browser what cursor type to use. We want this to apply to all the elements with an ‘onclick’ handler. In our SVG, these are all implemented using ‘onclick’ attributes directly in the XML content – which means we should be able to add a style rule using an ‘[onclick]’ selector (matches any element with an ‘onclick’ attribute). That sounds like a perfect use for Inkscape’s ‘Selectors and CSS dialog’, right?** | So far, so good. But on trying out your interactive mock-up, you may have noticed that the mouse pointer doesn’t change to indicate that elements are clickable. It’s a minor visual thing, but we can definitely improve it. There are various ways to tackle this, but they all end up with us needing a line of CSS that tells the browser what cursor type to use. We want this to apply to all the elements with an ‘onclick’ handler. In our SVG, these are all implemented using ‘onclick’ attributes directly in the XML content – which means we should be able to add a style rule using an ‘[onclick]’ selector (matches any element with an ‘onclick’ attribute). That sounds like a perfect use for Inkscape’s ‘Selectors and CSS dialog’, right?** | ||
+ | |||
+ | Maintenant, nous devons parcourir l' | ||
+ | |||
+ | La dernière chose que nous devons faire est de nous assurer que tous les éléments cliquables appellent toujours la fonction showLayer(), | ||
+ | |||
+ | Jusqu' | ||
+ | |||
**Wrong. As I mentioned in part 112 of this series, the dialog doesn’t recognise the attribute selector syntax. An alternative is to create a suitable < | **Wrong. As I mentioned in part 112 of this series, the dialog doesn’t recognise the attribute selector syntax. An alternative is to create a suitable < | ||
Ligne 44: | Ligne 83: | ||
The first line of this code creates a new < | The first line of this code creates a new < | ||
+ | |||
+ | Malheusement, | ||
+ | |||
+ | let css = document.createElementNS(" | ||
+ | |||
+ | css.textContent = " | ||
+ | |||
+ | document.documentElement.appendChild(css) ; | ||
+ | |||
+ | La première ligne de ce code crée un nouveau bloc < | ||
+ | |||
**There’s one last thing I’d like to do to really make this mock-up work effectively. You may have noticed that each page includes a ‘hamburger menu’ at the top-right. Let’s see if we can make that work, at least to some extent. | **There’s one last thing I’d like to do to really make this mock-up work effectively. You may have noticed that each page includes a ‘hamburger menu’ at the top-right. Let’s see if we can make that work, at least to some extent. | ||
Ligne 52: | Ligne 102: | ||
Each of the first three entries in the menu carries the same onclick handler as the equivalent on the main layer (in fact I copied and pasted the objects from there). We’ll deal with the ‘Sign Out’ option later. Now the question is how to make the menu pop-up when we click on the hamburger button – but that’s really not so tricky. If we use the XML editor to give the ‘Menu’ layer an ID of ‘menu’, then you can probably guess what this function (shown bottom right) will do.** | Each of the first three entries in the menu carries the same onclick handler as the equivalent on the main layer (in fact I copied and pasted the objects from there). We’ll deal with the ‘Sign Out’ option later. Now the question is how to make the menu pop-up when we click on the hamburger button – but that’s really not so tricky. If we use the XML editor to give the ‘Menu’ layer an ID of ‘menu’, then you can probably guess what this function (shown bottom right) will do.** | ||
+ | |||
+ | Il reste une dernière chose que j' | ||
+ | |||
+ | Une approche consisterait à créer six pages au lieu de trois : une deuxième version de chaque page reproduirait simplement l' | ||
+ | |||
+ | Nous avons déjà découvert que nous pouvons avoir plus d'une couche visible à la fois, et nous appuyer sur la transparence pour nous assurer que toutes les bonnes parties sont affichées en même temps. C'est, après tout, ce que nous avons fait lorsque nous avons ajouté le calque principal. Alors pourquoi ne pas faire de même avec le menu ? Dans ce scénario, chaque « page » se compose de la couche principale, de la couche de page correspondante et d'une couche de menu facultative qui se trouve au-dessus de toutes ces couches. Commençons par concevoir le menu sous la forme d'un nouveau calque en haut de la pile z (voir ci-dessus). | ||
+ | |||
+ | Chacune des trois premières entrées du menu porte le même gestionnaire de clic que son équivalent sur le calque principal (en fait, j'ai copié et collé les objets à partir de là). Nous nous occuperons de l' | ||
+ | |||
**All we need to do now is to call the showMenu() function from the onclick handler of the hamburger menu that lives on the Main layer. We’re not calling the existing showLayer() function, so none of the existing layers is hidden. All that happens is that the Menu layer is displayed in addition to the others that were already visible – exactly what we wanted. | **All we need to do now is to call the showMenu() function from the onclick handler of the hamburger menu that lives on the Main layer. We’re not calling the existing showLayer() function, so none of the existing layers is hidden. All that happens is that the Menu layer is displayed in addition to the others that were already visible – exactly what we wanted. | ||
Ligne 60: | Ligne 119: | ||
alert(" | alert(" | ||
+ | |||
+ | Tout ce que nous devons faire maintenant, c'est d' | ||
+ | |||
+ | En l' | ||
+ | |||
+ | Et qu'en est-il de l' | ||
+ | |||
+ | alert(" | ||
+ | |||
**With that addition our simple mock-up is complete. The key thing to take away is that the code for doing something like this probably isn’t as complex as you thought. While the Interactive Mockup extension can definitely be useful, you can easily get more functionality, | **With that addition our simple mock-up is complete. The key thing to take away is that the code for doing something like this probably isn’t as complex as you thought. While the Interactive Mockup extension can definitely be useful, you can easily get more functionality, | ||
Ligne 68: | Ligne 136: | ||
When you take a step back and look at it, that’s really quite a lot of functionality in this interactive mock-up, for not a huge amount of code. But we’re done with this now – and with ‘Interactive Mockup’ being the last of the new extensions, we’re done with the features that were added to Inkscape 1.x. Next month, I’ll start what is sure to be a long series on the new features and additions in Inkscape 1.2.x.** | When you take a step back and look at it, that’s really quite a lot of functionality in this interactive mock-up, for not a huge amount of code. But we’re done with this now – and with ‘Interactive Mockup’ being the last of the new extensions, we’re done with the features that were added to Inkscape 1.x. Next month, I’ll start what is sure to be a long series on the new features and additions in Inkscape 1.2.x.** | ||
+ | |||
+ | Avec cet ajout, notre maquette simple est terminée. Ce qu'il faut retenir, c'est que le code pour faire quelque chose comme ça n'est probablement pas aussi complexe que vous le pensiez. Bien que l' | ||
+ | |||
+ | Si vous souhaitez reproduire quelque chose comme ma maquette, peut-être pour vous entraîner et vous familiariser avec l' | ||
+ | |||
+ | En outre, chaque élément cliquable de la page dispose d'un appel de fonction unique dans le champ « onclick » de la section « Interactivité » au bas de la boîte de dialogue Objet > Propriétés de l' | ||
+ | |||
+ | Lorsque l'on prend un peu de recul et que l'on y regarde de plus près, on s' | ||
+ |
issue187/inkscape.1669564816.txt.gz · Dernière modification : 2022/11/27 17:00 de d52fr