Skip to content

Commit

Permalink
Adding some more docs about GUI, button is mostly done
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRainbowPhoenix committed Nov 20, 2023
1 parent 29e5d77 commit a5121df
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 10 deletions.
39 changes: 29 additions & 10 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,38 @@ export default defineConfig({
{ label: 'Building', link: '/getting-started/building/' },
],
},
{
label: 'Guides',
collapsed: true,
autogenerate: { directory: 'guides' },
items: [
// Each item here is one entry in the navigation menu.
{ label: 'Example Guide', link: '/guides/example/' },
],
},
// {
// label: 'Guides',
// collapsed: true,
// autogenerate: { directory: 'guides' },
// items: [
// // Each item here is one entry in the navigation menu.
// { label: 'Example Guide', link: '/guides/example/' },
// ],
// },
{
label: 'Reference',
collapsed: true,
autogenerate: { directory: 'reference' },
items: [
{
label: '📱 GUI',
collapsed: true,
autogenerate: { directory: 'reference/gui' },

},
{
label: '📟 OS',
collapsed: true,
autogenerate: { directory: 'reference/os' },

},
{
label: '🧮 CPU',
collapsed: true,
autogenerate: { directory: 'reference/cpu' },

}
]
},
{
label: 'Tutorials',
Expand Down
Binary file added public/img/gui/button_clickme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/gui/dialog_label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/content/docs/reference/cpu/ubc.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: UBC (User Break Controller)
description: User Break Controller
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/cpu/ubc.hpp)
:::
83 changes: 83 additions & 0 deletions src/content/docs/reference/gui/button.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: Button
description: GUIButton
---

Buttons are a fundamental GUI element that provides a clickable area with an associated action. They are commonly used in dialogs and serve as a convenient way for users to interact with the touchscreen. Below is a simplified documentation for the `GUIButton` class.

:::tip[Need code ?]
You can jump right to the [👨‍💻 Usage](#usage) or can refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/button.hpp) if you need more details.
:::

## Constructor

```c
GUIButton(
uint16_t leftX, uint16_t topY, uint16_t rightX, uint16_t bottomY,
const char *text,
uint16_t eventID
)
```

Creates a **basic button** with the specified dimensions and text.

- `leftX`: x-coordinate of the left side of the button.
- `topY`: y-coordinate of the top side of the button.
- `rightX`: x-coordinate of the right side of the button.
- `bottomY`: y-coordinate of the bottom side of the button.
- `text`: text displayed on the button, indicating the action it performs.
- `eventID`: A unique identifier associated with the button, typically used to handle button clicks.

### Optional "flags"

```c
GUIButton(
uint16_t leftX, uint16_t topY, uint16_t rightX, uint16_t bottomY,
const char *text,
uint16_t eventID, int flags
)
```

Creates a **basic button** with the flag capacity. *For now*, the only flag known is the "FlagEnabled" and could be found on the [GUIButton.Flag](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/button.hpp#L7) enum.


## Usage

Let's create a button that says "Click Me !" :

![A button that says "Click Me !"](/wiki/img/gui/button_clickme.png)


```c++
// parent is the dialog or parent container

// the BUTTON_CLICK_EVENT_ID on click
const uint16_t BUTTON_CLICK_EVENT_ID = 1;

GUIButton m_buttonOK = new GUIButton(
parent.GetLeftX() + 10,
parent.GetTopY() + 40,
parent.GetLeftX() + 10 + 95, // width of 95
parent.GetTopY() + 40 + 30 // height of 30
"Click Me !",
BUTTON_CLICK_EVENT_ID
);

// ...

// On the parent.OnEvent, here a GUIDialog :
virtual int OnEvent(struct GUIDialog_Wrapped *dialog, struct GUIDialog_OnEvent_Data *event) {
if (event->GetEventID() == BUTTON_CLICK_EVENT_ID) {
// TODO: do some action
return 0;
}
// If we don't process the event, let the base class process it.
return GUIDialog::OnEvent(dialog, event);
}
```
### Use in C++ dialog
:::caution
This section is **not finished**, but you can take a look at the [👨‍💻 demo gui](https://github.com/SnailMath/hollyhock-2/blob/04a4c086e1145a89d79dfe65158558398da6d8b1/demos/demo_gui/main.cpp#L21) for a complete example
:::
8 changes: 8 additions & 0 deletions src/content/docs/reference/gui/dialog.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Dialog
description: GUIDialog
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/dialog.hpp)
:::
8 changes: 8 additions & 0 deletions src/content/docs/reference/gui/dropDown.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Drop Down Menu
description: GUIDropDownMenuItem
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/dropDown.hpp)
:::
8 changes: 8 additions & 0 deletions src/content/docs/reference/gui/label.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Label
description: GUILabel
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/label.hpp)
:::
8 changes: 8 additions & 0 deletions src/content/docs/reference/gui/longLabel.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: longLabel
description: GUILongLabel
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/longLabel.hpp)
:::
8 changes: 8 additions & 0 deletions src/content/docs/reference/gui/radioButton.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: radioButton
description: GUIRadioButton
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/radioButton.hpp)
:::
8 changes: 8 additions & 0 deletions src/content/docs/reference/gui/textBox.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: textBox
description: GUITextBox
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/textBox.hpp)
:::
8 changes: 8 additions & 0 deletions src/content/docs/reference/gui/util.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Primitives & Utils
description: GUIElement
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui/util.hpp)
:::
34 changes: 34 additions & 0 deletions src/content/docs/reference/os/debug.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Debug
description: Functions useful during debugging
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/debug.hpp)
:::


It can be useful to print text or numbers to the screen whilst debugging, without creating a full GUI, or pause execution and wait for a key press.
Thoroughly recommended only for debugging - prefer GUI elements for user-facing input/output!
```cpp
// Print "Hello, world!" at 0, 0 in black on white
Debug_SetCursorPosition(0, 0);
Debug_PrintString("Hello, world!", false);

// Print "Inverted text" at 1, 1 in white on black
Debug_SetCursorPosition(1, 1);
Debug_PrintString("Inverted text", true);

// Print the number 0x1322 at 3, 7
Debug_PrintNumberHex_Word(0x1322, 3, 7);

// Print small text with a format string
Debug_Printf(20, 20, false, 0, "Format strings are %s in %d!", "cool", 2018);

// Draw the changes we made to VRAM onto the LCD
// Defined in sdk/os/lcd.hpp
LCD_Refresh();

// Block until the user presses a key
Debug_WaitKey();
```
35 changes: 35 additions & 0 deletions src/content/docs/reference/os/gui.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: GUI
description: Functions and classes to create/display GUI elements.
---

:::caution
This doc is **WIP**, please refer to its [original SDK Code](https://github.com/SnailMath/hollyhock-2/blob/master/sdk/include/sdk/os/gui.hpp)
:::


__Example:__ Display a simple dialog with a label

![The dialog as shown on the calculator, with "Dialog Title" as title and "Label Text" as body](/wiki/img/gui/dialog_label.png)

Here we are using a [GUIDialog](../../gui/dialog/) that's wrapping a [GUILabel](../../gui/label/). The code should look like this :

```cpp
GUIDialog dialog(
GUIDialog::Height25,
GUIDialog::AlignTop,
"Dialog Title",
GUIDialog::KeyboardStateABC
);

GUILabel label(
dialog.GetLeftX() + 10,
dialog.GetTopY() + 10,
"Label Text"
);
dialog.AddElement(label);

dialog.ShowDialog();
```
Where the [Height25](../../gui/dialog/#Height25) means 1/4 of the screen height, and [AlignTop](../../gui/dialog/#AlignTop) that it'll be top-aligned, fixed to screen top.
The [KeyboardStateABC](../../gui/dialog/#KeyboardStateABC) is a flag indicating what the keyboard should display if called on this dialog. Here the "ABC" tells it'll be the standard "abc" keyboard when pressing the "Keyboard" key.

0 comments on commit a5121df

Please sign in to comment.