Skip to content

Commit

Permalink
Merge pull request #54 from beyluta/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
beyluta authored Oct 28, 2023
2 parents 9f211c3 + e0d72fa commit c87ace3
Show file tree
Hide file tree
Showing 21 changed files with 532 additions and 53 deletions.
212 changes: 212 additions & 0 deletions Assets/Templates/calculator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<!-- Sample HTML Template made for the Open-Source software WinWidgets -->
<style>
@import url("https://fonts.googleapis.com/css2?family=Jaldi&display=swap");

body,
html {
background: rgb(19, 19, 19);
display: flex;
justify-content: center;
align-items: center;
font-family: Jaldi, sans-serif, monospace;
overflow: hidden;
user-select: none;
-moz-user-select: none;
}

.calculator-body {
display: flex;
flex-direction: column;
gap: 8px;
width: 360px;
z-index: 1;
font-weight: semibold;
}

.buttons {
display: flex;
flex-direction: row;
gap: 8px;
}

.button {
display: flex;
justify-content: center;
align-items: center;
background: black;
opacity: 0.8;
color: white;
padding: 10px 0;
width: 0.5rem;
border-radius: 10px;
flex: 1 1 10px;
transition: background-color 0.1s ease-in-out, border 0.1s ease-in-out;
cursor: pointer;
border: 1px solid black;
}

.button:hover {
background-color: rgb(19, 19, 19);
border: 1px solid rgb(209, 67, 15);
}

.display {
background: black;
opacity: 0.8;
color: white;
width: 100%;
padding: 20px;
border-radius: 10px;
min-height: 20px;
display: flex;
align-items: center;
}

.equals {
background: rgb(209, 67, 15);
}
</style>

<script>
var isMouseOverDOM = false;

var keyPressTime = new Date();

var toExec = " ";

var expressionRegistry = {
"tan(":"Math.tan(",
"sin(":"Math.sin(",
"cos(":"Math.cos(",
"deg":"*Math.PI/180",
"ln(":"Math.log(",
"lg(":"Math.log10(",
"^":"**",
"°":"*Math.PI*180",
"rad":"*180/Math.PI",
"e":"Math.E",
"π":"Math.PI",
"abs(":"Math.abs(",
"^3":"**3",
"^-1":"**-1",
"√(":"Math.sqrt(",
"%":"/100"
};

document.addEventListener('mouseover', () => isMouseOverDOM = true);

document.addEventListener('mouseout', () => isMouseOverDOM = false);

function onClear() {
document.getElementById("calculation").innerText = "";
toExec = "";
document.getElementById("toExec").innerText = toExec;
}

function onEqualsClicked() {
const calc = document.getElementById("calculation");
calc.innerText = eval(toExec);
toExec = calc.innerText;
}

function onButtonClicked(e) {
document.getElementById("calculation").innerText += e;
toExec += e;
//document.getElementById("toExec").innerText = toExec;
}

function onSpecialClicked(e){
document.getElementById("calculation").innerText += e;
toExec += expressionRegistry[e];
//document.getElementById("toExec").innerText = toExec;
}

function onNativeKeyEvents(key) {
/*
** 1- Checking if the input type is a keyboard event
** 2- Checking if the time between the last key press and the current one is greater than 150ms
** 3- Checking if the mouse is over the DOM
*/
if (key.eventType == "keyboardEvent" && (new Date() - keyPressTime) > 150 && isMouseOverDOM) {
//Getting the key code
var code = parseInt(key.keycode);
// Just input validation
if ((code >= 40 && code <= 43)||(code >= 47 && code <= 57)) {
const char = String.fromCharCode(parseInt(key.keycode));
keyPressTime = new Date();
onButtonClicked(char);
}
}
}



</script>

<!DOCTYPE html>
<html>
<head>
<meta name="applicationTitle" content="Calculator" />
<meta name="windowSize" content="450 500" />x
<meta name="windowBorderRadius" content="10" />
<meta name="previewSize" content="450 400" />
<meta name="windowOpacity" content="240" />
</head>
<body>
<div class="calculator-body">
<div class="display" id="calculation"></div>
<div class="buttons">
<div class="button" onclick="onSpecialClicked('abs(')">abs</div>
<div class="button" onclick="onSpecialClicked('^3')">^3</div>
<div class="button" onclick="onSpecialClicked('^-1')">^-1</div>
<div class="button" onclick="onSpecialClicked('√(')"></div>
<div class="button" onclick="onSpecialClicked('^2')">x^2</div>
<div class="button" onclick="onSpecialClicked('^')">^x</sup></div>
</div>
<div class="buttons">
<div class="button" onclick="onSpecialClicked('lg(')">lg</div>
<div class="button" onclick="onSpecialClicked('ln(')">ln</div>
<div class="button" onclick="onSpecialClicked('sin(')">sin</div>
<div class="button" onclick="onSpecialClicked('cos(')">cos</div>
<div class="button" onclick="onSpecialClicked('tan(')">tan</div>
<div class="button" onclick="onSpecialClicked('°')">°</div>
</div>
<div class="buttons">
<div class="button" onclick="onSpecialClicked('asin(')">asin</div>
<div class="button" onclick="onSpecialClicked('acos(')">acos</div>
<div class="button" onclick="onSpecialClicked('atan(')">atan</div>
<div class="button" onclick="onButtonClicked('(')">(</div>
<div class="button" onclick="onButtonClicked(')')">)</div>
<div class="button" onclick="onSpecialClicked('rad')">rad</div>
</div>
<div class="buttons">
<div class="button" onclick="onButtonClicked('7')">7</div>
<div class="button" onclick="onButtonClicked('8')">8</div>
<div class="button" onclick="onButtonClicked('9')">9</div>
<div class="button" onclick="onSpecialClicked('%')">%</div>
<div class="button" onclick="onClear()">C</div>
</div>
<div class="buttons">
<div class="button" onclick="onButtonClicked('4')">4</div>
<div class="button" onclick="onButtonClicked('5')">5</div>
<div class="button" onclick="onButtonClicked('6')">6</div>
<div class="button" onclick="onButtonClicked('*')">*</div>
<div class="button" onclick="onButtonClicked('/')">/</div>
</div>
<div class="buttons">
<div class="button" onclick="onButtonClicked('1')">1</div>
<div class="button" onclick="onButtonClicked('2')">2</div>
<div class="button" onclick="onButtonClicked('3')">3</div>
<div class="button" onclick="onButtonClicked('+')">+</div>
<div class="button" onclick="onButtonClicked('-')">-</div>
</div>
<div class="buttons">
<div class="button" onclick="onButtonClicked('0')">0</div>
<div class="button" onclick="onButtonClicked('.')">.</div>
<div class="button" onclick="onButtonClicked('π')">π</div>
<div class="button" onclick="onButtonClicked('e')">e</div>
<div class="button equals" onclick="onEqualsClicked()">=</div>
</div>
</div>
</body>
</html>
45 changes: 42 additions & 3 deletions Assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ <h3>Application</h3>
<div class="setting flex-row">
<div
class="switch flex-row"
onclick="changeStartup(this)"
onclick="setOptionState(this)"
setting="startup"
>
<div class="circle"></div>
</div>
<p>Run the application on startup</p>
<p>Run the Application on Startup</p>
</div>

<div class="setting flex-row">
<div
class="switch flex-row"
onclick="changeStartupWidgets(this)"
onclick="setOptionState(this)"
setting="widgetStartup"
>
<div class="circle"></div>
Expand All @@ -136,6 +136,45 @@ <h3>Application</h3>
Run Widgets on Startup
</p>
</div>

<div class="setting flex-row">
<div
class="switch flex-row"
onclick="setOptionState(this)"
setting="managerHideOnStart"
>
<div class="circle"></div>
</div>
<p class="hideWidgetManagerOnStart">
<svg
xmlns="http://www.w3.org/2000/svg"
height="1em"
viewBox="0 0 512 512"
>
<path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>
Hide Widget-Manager when WinWidgets starts
</p>
</div>

<div class="setting flex-row">
<div
class="switch flex-row"
onclick="setOptionState(this)"
setting="widgetHideOnFullscreenApplication"
>
<div class="circle"></div>
</div>
<p class="hideWidgetsOnFullscreenApplication">
<svg
xmlns="http://www.w3.org/2000/svg"
height="1em"
viewBox="0 0 512 512"
>
<path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>

Close Widgets when other Application is in Fullscreen
</p>
</div>
</div>
</div>

Expand Down
7 changes: 1 addition & 6 deletions Assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,11 @@ function setSwitchState(element) {
}
}

function changeStartup(element) {
function setOptionState(element) {
setSwitchState(element);
CefSharp.PostMessage(element.getAttribute("setting"));
}

function changeStartupWidgets(element) {
setSwitchState(element);
CefSharp.PostMessage(element.getAttribute("setting"));
}

window.onload = () => {
const searchWidget = document.getElementById("searchwidget");

Expand Down
33 changes: 33 additions & 0 deletions Assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,39 @@ svg {
position: absolute;
bottom: 0;
left: 0;
z-index: 999;
}

.setting > .hideWidgetsOnFullscreenApplication:hover::after {
content: "Widgets will be closed to save computer resources. They will be reopened when the fullscreen application is closed.";
color: white;
padding: 8px 10px;
width: max-content;
max-width: 400px;
border-radius: 4px;
transform: translateY(90px);
background: var(--black);
display: block;
position: absolute;
bottom: 0;
left: 0;
z-index: 999;
}

.setting > .hideWidgetManagerOnStart:hover::after {
content: "The main Widget-Manager window will be hidden by default when the application starts.";
color: white;
padding: 8px 10px;
width: max-content;
max-width: 400px;
border-radius: 4px;
transform: translateY(70px);
background: var(--black);
display: block;
position: absolute;
bottom: 0;
left: 0;
z-index: 999;
}

.switch {
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
Beyluta | <[email protected]> - <https://pedroribeiro.site> - <https://github.com/beyluta>
mateuszstalmach | <https://github.com/mateuszstalmach>
EPICTROLLTOAST | <https://github.com/EPICTROLLTOAST>
Yopai | <https://github.com/Yopai>
6 changes: 3 additions & 3 deletions Components/MenuHandler.Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public MenuHandlerComponent(WidgetComponent widget)
public void OnBeforeContextMenu(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
{
this.menuHandlerService.ClearModel(model);
this.menuHandlerService.AddOption("Toggle Move", 0, model);
this.menuHandlerService.AddOption("Toggle Always on Top", 1, model);
this.menuHandlerService.AddOption("Close Widget", 2, model);
this.menuHandlerService.AddOption("Move", 0, false, model);
this.menuHandlerService.AddOption("Always on Top", 1, widgetComponent.window.TopMost, model);
this.menuHandlerService.AddOption("Close Widget", 2, false, model);
}

public bool OnContextMenuCommand(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
Expand Down
Loading

0 comments on commit c87ace3

Please sign in to comment.