forked from splashkit/splashkit.io-starlight
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Utilities Usage Examples #288
Open
breezy-codes
wants to merge
1
commit into
thoth-tech:usage-examples
Choose a base branch
from
breezy-codes:final-utilities
base: usage-examples
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
public/usage-examples/utilities/display_dialog/display_dialog-1-show-sizes-oop.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using SplashKitSDK; | ||
|
||
namespace Program | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
// Display a dialog to the user | ||
SplashKit.DisplayDialog("Welcome!", "Hello, this is a simple dialog message.", SplashKit.GetSystemFont(), 20); | ||
|
||
// Display another dialog with a different message and font size | ||
SplashKit.DisplayDialog("Second Message", "This is another dialog with a different message.", SplashKit.GetSystemFont(), 25); | ||
|
||
// Display a dialog with a different title and message | ||
SplashKit.DisplayDialog("Third Message", "This is a dialog with BIG TEXT!", SplashKit.GetSystemFont(), 40); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
public/usage-examples/utilities/display_dialog/display_dialog-1-show-sizes-top-level.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using static SplashKitSDK.SplashKit; | ||
|
||
// Display a dialog to the user | ||
DisplayDialog("Welcome!", "Hello, this is a simple dialog message.", GetSystemFont(), 20); | ||
|
||
// Display another dialog with a different message and font size | ||
DisplayDialog("Second Message", "This is another dialog with a different message.", GetSystemFont(), 25); | ||
|
||
// Display a dialog with a different title and message | ||
DisplayDialog("Third Message", "This is a dialog with BIG TEXT!", GetSystemFont(), 40); |
13 changes: 13 additions & 0 deletions
13
public/usage-examples/utilities/display_dialog/display_dialog-1-show-sizes.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "splashkit.h" | ||
|
||
int main() | ||
{ | ||
// Display a dialog to the user | ||
display_dialog("Welcome!", "Hello, this is a simple dialog message.", get_system_font(), 20); | ||
|
||
// Display another dialog with a different message and font size | ||
display_dialog("Second Message", "This is another dialog with a different message.", get_system_font(), 25); | ||
|
||
// Display a dialog with a different title and message | ||
display_dialog("Third Message", "This is a dialog with BIG TEXT!", get_system_font(), 40); | ||
} |
Binary file added
BIN
+72.3 KB
public/usage-examples/utilities/display_dialog/display_dialog-1-show-sizes.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions
10
public/usage-examples/utilities/display_dialog/display_dialog-1-show-sizes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from splashkit import * | ||
|
||
# Display a dialog to the user | ||
display_dialog("Welcome!", "Hello, this is a simple dialog message.", get_system_font(), 20) | ||
|
||
# Display another dialog with a different message and font size | ||
display_dialog("Second Message", "This is another dialog with a different message.", get_system_font(), 25) | ||
|
||
# Display a dialog with a different title and message | ||
display_dialog("Third Message", "This is a dialog with BIG TEXT!", get_system_font(), 40) |
3 changes: 3 additions & 0 deletions
3
public/usage-examples/utilities/display_dialog/display_dialog-1-show-sizes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Display Dialog Boxes | ||
|
||
The following code shows an example of using [display dialog](/api/utilities/#display-dialog) to show 3 different dialog boxes, each with the font size increasing to show how they can be used to display different sizes of text or messages. |
79 changes: 79 additions & 0 deletions
79
public/usage-examples/utilities/is_number/is_number-1-calculator-oop.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using SplashKitSDK; | ||
|
||
namespace Program | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
SplashKit.WriteLine("Welcome to the Simple Calculator!"); | ||
SplashKit.WriteLine("You can add or subtract two numbers.\n"); | ||
|
||
while (true) | ||
{ | ||
SplashKit.WriteLine("Enter the first number (or type 'exit' to quit):"); | ||
string input1 = SplashKit.ReadLine(); | ||
|
||
// Check for exit condition | ||
if (SplashKit.ToLowercase(input1) == "exit") | ||
{ | ||
break; | ||
} | ||
|
||
// Validate the first number | ||
if (!SplashKit.IsNumber(input1)) | ||
{ | ||
SplashKit.WriteLine("Oops! That's not a valid number. Please try again.\n"); | ||
continue; | ||
} | ||
|
||
string input2 = ""; | ||
|
||
// Loop until the second number is valid | ||
bool validSecondNumber = false; | ||
|
||
while (!validSecondNumber) | ||
{ | ||
SplashKit.WriteLine("Enter the second number:"); | ||
input2 = SplashKit.ReadLine(); | ||
|
||
// Validate the second number | ||
if (!SplashKit.IsNumber(input2)) | ||
{ | ||
SplashKit.WriteLine("Oops! That's not a valid number. Please try again.\n"); | ||
} | ||
else | ||
{ | ||
validSecondNumber = true; | ||
} | ||
} | ||
|
||
SplashKit.WriteLine("Enter the operation (+ or -):"); | ||
string operation = SplashKit.ReadLine(); | ||
|
||
// Check for valid operation | ||
if (operation != "+" && operation != "-") | ||
{ | ||
SplashKit.WriteLine("Invalid operation. Please enter '+' or '-' only.\n"); | ||
continue; | ||
} | ||
|
||
// Convert inputs to double | ||
double num1 = SplashKit.ConvertToDouble(input1); | ||
double num2 = SplashKit.ConvertToDouble(input2); | ||
|
||
// Perform the operation | ||
if (operation == "+") | ||
{ | ||
SplashKit.WriteLine("Result: " + (num1 + num2) + "\n"); | ||
} | ||
else if (operation == "-") | ||
{ | ||
SplashKit.WriteLine("Result: " + (num1 - num2) + "\n"); | ||
} | ||
} | ||
|
||
SplashKit.WriteLine("Thank you for using the Simple Calculator!"); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
public/usage-examples/utilities/is_number/is_number-1-calculator-top-level.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using static SplashKitSDK.SplashKit; | ||
|
||
WriteLine("Welcome to the Simple Calculator!"); | ||
WriteLine("You can add or subtract two numbers.\n"); | ||
|
||
while (true) | ||
{ | ||
WriteLine("Enter the first number (or type 'exit' to quit):"); | ||
string input1 = ReadLine(); | ||
|
||
// Check for exit condition | ||
if (input1.ToLower() == "exit") | ||
{ | ||
break; | ||
} | ||
|
||
// Validate the first number | ||
if (!IsNumber(input1)) | ||
{ | ||
WriteLine("Oops! That's not a valid number. Please try again.\n"); | ||
continue; | ||
} | ||
|
||
string input2 = ""; | ||
|
||
// Loop until the second number is valid | ||
bool validSecondNumber = false; | ||
while (!validSecondNumber) | ||
{ | ||
WriteLine("Enter the second number:"); | ||
input2 = ReadLine(); | ||
|
||
// Validate the second number | ||
if (!IsNumber(input2)) | ||
{ | ||
WriteLine("Oops! That's not a valid number. Please try again.\n"); | ||
} | ||
else | ||
{ | ||
validSecondNumber = true; | ||
} | ||
} | ||
|
||
WriteLine("Enter the operation (+ or -):"); | ||
string operation = ReadLine(); | ||
|
||
// Check for valid operation | ||
if (operation != "+" && operation != "-") | ||
{ | ||
WriteLine("Invalid operation. Please enter '+' or '-' only.\n"); | ||
continue; | ||
} | ||
|
||
// Convert inputs to double | ||
double num1 = ConvertToDouble(input1); | ||
double num2 = ConvertToDouble(input2); | ||
|
||
// Perform the operation | ||
if (operation == "+") | ||
{ | ||
WriteLine("Result: " + (num1 + num2) + "\n"); | ||
} | ||
else if (operation == "-") | ||
{ | ||
WriteLine("Result: " + (num1 - num2) + "\n"); | ||
} | ||
} | ||
|
||
WriteLine("Thank you for using the Simple Calculator!"); |
72 changes: 72 additions & 0 deletions
72
public/usage-examples/utilities/is_number/is_number-1-calculator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "splashkit.h" | ||
|
||
int main() | ||
{ | ||
write_line("Welcome to the Simple Calculator!"); | ||
write_line("You can add or subtract two numbers.\n"); | ||
|
||
string input1, input2, operation; | ||
|
||
while (true) | ||
{ | ||
write_line("Enter the first number (or type 'exit' to quit):"); | ||
input1 = read_line(); | ||
|
||
// Check for exit condition | ||
if (to_lowercase(input1) == "exit") | ||
{ | ||
break; | ||
} | ||
|
||
// Validate the first number | ||
if (!is_number(input1)) | ||
{ | ||
write_line("Oops! That's not a valid number. Please try again.\n"); | ||
continue; | ||
} | ||
|
||
// Loop until the second number is valid | ||
bool valid_second_number = false; | ||
while (!valid_second_number) | ||
{ | ||
write_line("Enter the second number:"); | ||
input2 = read_line(); | ||
|
||
// Validate the second number | ||
if (!is_number(input2)) | ||
{ | ||
write_line("Oops! That's not a valid number. Please try again.\n"); | ||
} | ||
else | ||
{ | ||
valid_second_number = true; | ||
} | ||
} | ||
|
||
write_line("Enter the operation (+ or -):"); | ||
operation = read_line(); | ||
|
||
// Check for valid operation | ||
if (operation != "+" && operation != "-") | ||
{ | ||
write_line("Invalid operation. Please enter '+' or '-' only.\n"); | ||
continue; | ||
} | ||
|
||
// Convert inputs to double | ||
double num1 = convert_to_double(input1); | ||
double num2 = convert_to_double(input2); | ||
|
||
// Perform the operation | ||
if (operation == "+") | ||
{ | ||
write_line("Result: " + std::to_string(num1 + num2)+ "\n"); | ||
} | ||
else if (operation == "-") | ||
{ | ||
write_line("Result: " + std::to_string(num1 - num2)+ "\n"); | ||
} | ||
} | ||
|
||
write_line("Thank you for using the Simple Calculator!"); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions
49
public/usage-examples/utilities/is_number/is_number-1-calculator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from splashkit import * | ||
|
||
write_line("Welcome to the Simple Calculator!") | ||
write_line("You can add or subtract two numbers.\n") | ||
|
||
while True: | ||
write_line("Enter the first number (or type 'exit' to quit):") | ||
input1 = read_line() | ||
|
||
# Check for exit condition | ||
if to_lowercase(input1) == "exit": | ||
break | ||
|
||
# Validate the first number | ||
if not is_number(input1): | ||
write_line("Oops! That's not a valid number. Please try again.\n") | ||
continue | ||
|
||
# Loop until the second number is valid | ||
valid_second_number = False | ||
while not valid_second_number: | ||
write_line("Enter the second number:") | ||
input2 = read_line() | ||
|
||
# Validate the second number | ||
if not is_number(input2): | ||
write_line("Oops! That's not a valid number. Please try again.\n") | ||
else: | ||
valid_second_number = True | ||
|
||
write_line("Enter the operation (+ or -):") | ||
operation = read_line() | ||
|
||
# Check for valid operation | ||
if operation != "+" and operation != "-": | ||
write_line("Invalid operation. Please enter '+' or '-' only.\n") | ||
continue | ||
|
||
# Convert inputs to double | ||
num1 = convert_to_double(input1) | ||
num2 = convert_to_double(input2) | ||
|
||
# Perform the operation | ||
if operation == "+": | ||
write_line("Result: " + str(num1 + num2) + "\n") | ||
elif operation == "-": | ||
write_line("Result: " + str(num1 - num2) + "\n") | ||
|
||
write_line("Thank you for using the Simple Calculator!") |
3 changes: 3 additions & 0 deletions
3
public/usage-examples/utilities/is_number/is_number-1-calculator.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Number Calculator | ||
|
||
The following code shows examples of using [is number](/api/utilities/#is-number) function to perform addition and subtraction operations. It includes input validation to ensure that the entered values are numbers. |
37 changes: 37 additions & 0 deletions
37
public/usage-examples/utilities/split/split-1-sentence-oop.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using SplashKitSDK; | ||
|
||
namespace Program | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
// Prompt user for input string and delimiter | ||
SplashKit.Write("Enter a string to split: "); | ||
string text = SplashKit.ReadLine(); | ||
|
||
SplashKit.Write("Enter a delimiter character: "); | ||
string delimiterInput = SplashKit.ReadLine(); | ||
|
||
// Ensure the delimiter is a single character | ||
if (delimiterInput.Length != 1) | ||
{ | ||
SplashKit.WriteLine("Please enter a single character as the delimiter."); | ||
} | ||
else | ||
{ | ||
char delimiter = delimiterInput[0]; | ||
|
||
// Split the input string | ||
List<string> result = SplashKit.Split(text, delimiter); | ||
|
||
// Display the split substrings | ||
SplashKit.WriteLine("Split result:"); | ||
foreach (string part in result) | ||
{ | ||
SplashKit.WriteLine($"- {part}"); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some sort of issue with the display_dialog function that isn't showing the last dialog box. I've tested a few things and I think it has something to do with the length of the message because when I put in a few more characters in like "This is another dialog with BIG TEXT!" it works fine.