Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Show hints to guide a new user, when editor is used for first time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mammad900 committed Jan 24, 2021
1 parent 69c2e39 commit 7fd494a
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 47 deletions.
36 changes: 20 additions & 16 deletions Gui900 visual editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!--Loads All JS and CSS files-->
<script src="res/loader.js"></script>
</head>
<body onload="LP()" onunload=" if((window.docWin!=undefined) && (!window.docWin.closed)){
<body onunload=" if((window.docWin!=undefined) && (!window.docWin.closed)){
window.docWin.close();
}">
<noscript style="text-align: center; color:red">
Expand Down Expand Up @@ -51,7 +51,7 @@ <h2>
<span class="float-right" id="properties-header-details">No item selected</span>
<i class="fa fa-chevron-down" id="properties-openclose-button" onclick="$('#properties').toggleClass('hiddenbox');cetnbtp()"></i>
</div>
<div>
<div style="border-bottom-right-radius: var(--box-border-radius); overflow: hidden;">
<div id="properties-shadow-top"></div>
<div id="properties-content">
</div>
Expand Down Expand Up @@ -91,7 +91,7 @@ <h2>
</section>
</div>
<div class="l6 m6 s12" id="pages-table-column">
<section class="box" style="padding: 0;">
<section class="box" style="padding: 0; min-width: fit-content;">
<table class="table np" style="border-radius: 10px;" id="pages_table">
<tr style="border-radius: 10px;">
<th style="padding: 0;">
Expand All @@ -101,7 +101,7 @@ <h2>
Pages
</h2>
<button class="float-right button size38 noselect" title="New page"
style="margin-right: 10px;" id="new_page_button" onclick="pages.create()">
style="margin-right: 10px;" id="new_page_button">
<i class="fa fa-plus"></i>
</button>
</div>
Expand All @@ -116,20 +116,24 @@ <h2>
<i class="fas fa-chevron-down" onclick="$('#code-editor').toggleClass('hiddenbox')"></i
><h2>Code</h2>
</div>
<div id="codeParts">
<div>
<span data-name="globalBeginning" data-selected="true">Code in the biginning (global)</span
><span data-name="globalAfterConfig">Code after config defines</span
><span data-name="globalAfterLibrary">Code after Gui900 include</span
><span data-name="setupBeginning">Code in the beginning of <code>setup()</code></span
><span data-name="setupBeforeStart">Code before <code>start()</code></span
><span data-name="setupAfterStart">Code after <code>start()</code></span
><span data-name="loop">Code in <code>loop()</code></span
><span data-name="globalAfterLoop">Code after <code>loop()</code></span>
<div></div>
<div id="codeParts-container">
<div id="codeParts">
<div>
<span data-name="globalBeginning" data-selected="true">Code in the biginning (global)</span
><span data-name="globalAfterConfig">Code after config defines</span
><span data-name="globalAfterLibrary">Code after Gui900 include</span
><span data-name="setupBeginning">Code in the beginning of <code>setup()</code></span
><span data-name="setupBeforeStart">Code before <code>start()</code></span
><span data-name="setupAfterStart">Code after <code>start()</code></span
><span data-name="loop">Code in <code>loop()</code></span
><span data-name="globalAfterLoop">Code after <code>loop()</code></span>
<div></div>
</div>
</div>
</div>
<div id="monaco-container" style="height: 500px;"></div>
<div id="monaco-container" style="height: 500px; overflow: hidden;
border-bottom-left-radius: var(--box-border-radius);
border-bottom-right-radius: var(--box-border-radius);"></div>
</section>
</div>

Expand Down
6 changes: 5 additions & 1 deletion res/elements/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var elements={
*
* @param {"Button"|"Label"|"Check-box"|"Slider"|"Radio-button"|Object} el
*/
function (el) {
async function (el) {
var type;
var elementData;
if(typeof(el)=="object"){
Expand All @@ -28,6 +28,10 @@ var elements={
elements.selectElement(num);
}
});
await createHint("selectElement",$(tr.children()[0]), "Click on the empty area to select the element.", true, "top");
await createHint("moveElementUp",$("#elements_table tr:last-child .buttons>*:first-child"), "Click on this to move this element above the element above it (move it up).<br> It's disabled for the first element.<br>You can use it to move an element behind another.", true, "right");
await createHint("moveElementDown",$("#elements_table tr:last-child .buttons>*:nth-child(2)"), "Click on this to move this element below the element below it (move it down).<br> It's disabled for the last element.<br>You can use it to move an element in front of another.", true, "right");
await createHint("deleteElement",$("#elements_table tr:last-child .buttons>*:nth-child(3)"), "Click on this to delete the element.", false, "right");
},
types: {},
selectElement:
Expand Down
20 changes: 10 additions & 10 deletions res/elements/ui/table/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@ elements.table={
};
}
function LP_HandleNewElementButton(){
$("#new-element-button").on("click",function(){
elements.create("Button");
$("#new-element-button").on("click",async function(){
await elements.create("Button");
});
$("#new-element-label").on("click",function(){
elements.create("Label");
$("#new-element-label").on("click",async function(){
await elements.create("Label");
});
$("#new-element-checkbox").on("click",function(){
elements.create("Check-box");
$("#new-element-checkbox").on("click",async function(){
await elements.create("Check-box");
});
$("#new-element-slider").on("click",function(){
elements.create("Slider", true);
$("#new-element-slider").on("click",async function(){
await elements.create("Slider", true);
});
$("#new-element-radio-button").on("click",function(){
elements.create("Radio button");
$("#new-element-radio-button").on("click",async function(){
await elements.create("Radio button");
});
}

Expand Down
25 changes: 19 additions & 6 deletions res/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function loadJsCssFile(filename){
"res/file/load.js", // Load the project
"res/code-generator/config.js", // Generates Arduino config code
"res/code-generator/generateCode.js", // Generates Arduino code
"res/ui/hint/hint.js",

"res/elements/types/button/createDefaultDataObject.js",
"res/elements/types/button/createProperties.js",
Expand Down Expand Up @@ -99,16 +100,17 @@ function loadJsCssFile(filename){
"res/ui/notification/notification.css", // Notifications
"res/settings/special-styles.css", // Project settings special styles
"res/code-editor/styles.css", // Code editor styles
"res/ui/hint/styles.css",

"res/js/loader-end.js", // Finishes loading

].forEach(function(value){
loadJsCssFile(value);
});

function LP(){
async function LP(){
try{
[
var LP_funcs=[
LP_SetTheme,

LP_GV_ElementsTableButtons,
Expand Down Expand Up @@ -163,9 +165,17 @@ function LP(){
LP_LoadEditor,
LP_HandleColorPickerInput,
LP_loaderEnd,
].forEach(function(value){
value();
});
[LP_Hints],
];
for(var i=0;i<LP_funcs.length;i++){
var value=LP_funcs[i];
if(typeof value=='object'){
await value[0]();
}
else{
value();
}
}
}
catch(err){
console.error(err);
Expand All @@ -176,4 +186,7 @@ function LP(){
<button class="button" style="font-size: 1.5rem;margin:20px;padding:10px;background:var(--back-color);" onclick="window.location.reload()">Refresh</button
</p>`;
}
};
};
window.onload= async function () {
await LP();
}
5 changes: 5 additions & 0 deletions res/pages/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ var pages = {
}

function LP_createFirstPage() {
$("#new_page_button").on("click", function (e) {
if(!(e.target.innerHTML=='OK')){
pages.create()
}
})
if(!localStorage.getItem("fileToBeLoaded")){
pages.create();
}
Expand Down
22 changes: 22 additions & 0 deletions res/pages/ui/table/special-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@
cursor: pointer;
}

#pages_table tr:last-child td:first-child{
border-bottom-left-radius: var(--box-border-radius);
}
#pages_table tr:not(:first-child) td:first-child{
min-width: 200px;
cursor: pointer;
}

#pages-table-column>.box{
overflow: visible;
}
#pages-table-column tr:not(:first-child){
overflow: clip;
}
#pages_table tr:last-child td:last-child{
border-bottom-right-radius: var(--box-border-radius);
}

#pages_table tr:last-child .buttons>*:first-child button.button{
border-bottom-left-radius: var(--box-border-radius);
}

#pages_table div.buttons{
display: inline-block;
}
Expand Down
1 change: 0 additions & 1 deletion res/ui/box/box.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
border-radius: var(--box-border-radius);
box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.2);
background-color: var(--box-background);
overflow: hidden;
}
.box h2 {
user-select: none;
Expand Down
5 changes: 5 additions & 0 deletions res/ui/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@ kbd{
font-size: 0.9em;
padding: 0 0.2em;
}

abbr {
text-decoration: underline dotted 1px;
cursor: help !important;
}
25 changes: 15 additions & 10 deletions res/ui/css/tooltip.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
.tooltip {
position: relative;
display: inline-block;
}

.tooltip .tooltiptext {
display: none;
.tooltip>.tooltiptext {
display: none !important;
width: 120px;
background-color: var(--tooltip-color);
text-align: center;
Expand All @@ -22,11 +21,12 @@
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.1);
}

.tooltip:hover .tooltiptext {
display: block;
.tooltip:hover>.tooltiptext,
.tooltip>.tooltiptext.alwaysVisible {
display: block !important;
}

.tooltip .tooltiptext::after {
.tooltip>.tooltiptext::after {
content: " ";
position: absolute;
top: 100%;
Expand All @@ -39,14 +39,19 @@
}

.tooltiptext.bottom {
bottom: unset;
bottom: unset !important;
top: 100%;
margin-bottom: 0;
margin-bottom: 0 !important;
margin-top: 15px;
}

.tooltiptext.bottom::after {
bottom: 100%;
top: unset;
border-color: transparent transparent var(--tooltip-color) transparent;
top: unset !important;
border-color: transparent transparent var(--tooltip-color) transparent !important;
}

.tooltip>.tooltiptext.wide {
width: 240px;
margin-left: -120px;
}
68 changes: 68 additions & 0 deletions res/ui/hint/hint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
*
* @param {JQuery<HTMLElement>} element
* @param {string|HTMLElement|JQuery<HTMLElement>} html
*/
async function createHint(id,element, html, wide=true, direction="top") {
var storageObj=JSON.parse(localStorage.getItem("hints"));
if((storageObj[id])==true) {return;}
element.addClass("hint");
if(element.is("#toolbar .dropdown .toolbar-button")){
element.parent().parent().parent().parent().addClass("hashint");
}
var ttt= $("<div>").addClass(["tooltiptext",direction]);
var cont;
ttt.append($("<div>").append(html));
ttt.append($("<button>").addClass("button").text("OK").on("click",function (e) {
ttt.remove();
element.removeClass("hint");
if(element.is("#toolbar .dropdown .toolbar-button")){
element.parent().parent().parent().parent().removeClass("hashint");
}
cont();
}));
if(wide){
ttt.addClass("wide");
}
element.append(ttt);
var promise = new Promise((resolve) => { cont = resolve });
await promise.then((result) => {});
storageObj[id]=true;
localStorage.setItem("hints",JSON.stringify(storageObj));
}

async function LP_Hints() {
if(localStorage.getItem("hints")==null){
localStorage.setItem("hints","{}");
}
var hints= [
["elements" , "#elements-table-column section.box" , "Using the elements section, you can create, delete and re-order <abbr class='tooltip'>elements<span class='tooltiptext wide'>Elements are UI widgets on a page. They consist of buttons, labels, check-boxes, sliders and radio-buttons.</span></abbr>." , true ],
["newElement" , "#new_element_button" , "Hover over this button to see a list of element types. Click on any of them to create an element of that kind." , true ],
["pages" , "#pages-table-column" , "Using the pages section, you can create, re-order and delete pages." , true ],
["newPage" , "#new_page_button" , "Click on this to create a new page." , true ],
["selectPage" , "#pages_table tr.selected td:first-child" , "Click on the empty area here to select the page." , true ],
["movePageUp" , "#pages_table tr:last-child .buttons>*:first-child" , "Click on this to move this page above the page above it (move it up).<br> It's disabled for the first page." , true ,"right"],
["movePageDown" , "#pages_table tr:last-child .buttons>*:nth-child(2)" , "Click on this to move this page below the page below it (move it down).<br> It's disabled for the last page." , true ,"right"],
["deletePage" , "#pages_table tr:last-child .buttons>*:nth-child(3)" , "Click on this to delete the page.<br> Don't do it when there is only one page." , true ,"right"],
["codeEditor" , "#code-editor" , "Here you can write non-UI and handler code for this project." , true ],
["codeEditorFS" , "#code-editor" , "Double-click on the header to make the editor full-screen. Press <kbd>Esc</kbd> while editor is in focus to exit full-screen mode." , true ],
["codeEditorTabs" , "#codeParts-container" , "Code can be inserted in several locations. Each of these locations have a tab here." , true ],
["properties" , "#properties" , "Here you can change the options for elements (position, size, color, content, etc.). It's empty by default but options appear when you select an element." , true ,"left" ],
["preview" , "#preview" , "With the help of preview, you can see what the app looks like without leaving the app or using a real Arduino board" , true ,"right"],
["previewRefresh" , "#preview button" , "Click on this button to redraw the preview." , true , ],
["minimize" , "#pages-openclose-button" , "You can click this button on any box to minimize the box, to save space / remove distractions." , true ,"right"],
["projectSettings", "#toolbar>.menuitem:first-child>div>.dropdown>.menuitem:nth-child(4)>.toolbar-button" , "Here you can adjust different settings for the project." , true ,"right"],
["saveProject" , "#toolbar>.menuitem:first-child>div>.dropdown>.menuitem:nth-child(2)>.toolbar-button" , "Here you can save the project to a file, export it to JSON, or save it to the browser storage." , true ,"right"],
["openProject" , "#toolbar>.menuitem:first-child>div>.dropdown>.menuitem:first-child>.toolbar-button" , "Here you can open a previously saved file, import from JSON, or load the last saved project in browser storage." , true ,"right"],
["generateCode" , "#toolbar>.menuitem:first-child>div>.dropdown>.menuitem:nth-child(3)>.toolbar-button" , "This tool generates Arduino code to be used in production." , true ,"right"],
["changeTheme" , "#toolbar>.menuitem:first-child>div>.dropdown>.menuitem:nth-of-type(5)>.toolbar-button", "Change the editor theme here" , false,"right"],
]
for(var i=0;i<hints.length;i++){
var hint=hints[i];
await createHint(hint[0], $(hint[1]), hint[2], hint[3] || true, hint[4] || "top");
}
}

function resetHints() {
localStorage.setItem("hints","{}");
}
Loading

0 comments on commit 7fd494a

Please sign in to comment.