Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SplashKit Interface Functionality #176

Merged
merged 64 commits into from
Jul 4, 2024

Conversation

WhyPenguins
Copy link
Contributor

This PR is dependent/related to a couple of others, please make sure they get merged together! See bottom for details

Overview

This PR adds the ability to easily create and style user interfaces with SplashKit programmatically, with an immediate mode GUI (IMGUI) style API. It uses the MicroUI library to handle widget logic, and SplashKit's in-built routines to handle input/rendering.

It is hoped that this will allow students to begin visualizing variables using the interface functions, and develop more interactive graphical programs with ease.

The API has been designed such that only a basic understanding of calling functions with parameters, and storing the returned values in variables is required - unlike most IMGUI APIs, pointers and so on are avoided.

Demo

See below for a demo of the interfaces that can be created:
UIStylization

Simple usage example

#include "splashkit.h"

int main()
{
    // open a window
    open_window("My Interface!", 800, 600);

    // main loop
    while (!quit_requested())
    {
        // get user events
        process_events();

        // clear screen
        clear_screen(COLOR_WHITE);

        // place button on screen and test if clicked
        if (button("Write To Terminal!", rectangle_from(300, 260, 200, 24)))
        {
            write_line("Hello there!");
        }

        // finally draw interface, then refresh screen
        draw_interface();

        refresh_screen();
    }

    // program ends, and the window closes
    return 0;
}

Main Changes

  • Includ MicroUI in repository and integrat into input handling/rendering.
  • Create interface_driver backend for abstracting out MicroUI to a degree.
  • Expose UI elements, layout, and styling options to the user facing API.

With some miscellaneous additions:

  • Add user facing get_system_font() function
  • Add internal sk_draw_blurred_rect(...) function
  • Add new UI test

Feature overview

  • Containers: windows (referred to as 'panels'), popups, insets
  • Elements: labels, buttons, bitmap buttons, sliders, check boxes, text boxes, number boxes, HSVA/RGBA color sliders
    • Can be created directly on main window, or auto placed inside containers
    • Can be disabled/enabled
    • Also have 'with_label' versions that provide a label on the left
  • Layouting elements: treeviews, columns, headers
  • Styling functions
    • Various color customization options
    • Soft shadows from elements/panels
    • Preset interface styles
  • Error recovery and reporting
  • Documentation for all user facing API functions

Dependencies

Add MicroUI External - splashkit/splashkit-external#6

  • Adds the MicroUI dependency, important!

Related PRs

Tutorials on SplashKit's interface functionality - thoth-tech/splashkit.io-starlight#26

  • I imagine these will need to be made as a PR to the upstream repo, let me know if so!
  • One limitation of these tutorials is that they only have C++ examples. Once this PR is merged and C# binaries produced, it'll be easier for me to add C# examples, so perhaps the tutorials can be merged later once that's done. Or they could be merged along with this PR and C# examples can be added later instead.

 - panels
 - popups
 - labels
 - buttons
 - no more global font/font size
 - now the font/font size can be changed for portions of the interface
…tion

 - add sk_set_bitmap_pixel - sets a pixel on the bitmap's surface
 - add sk_refresh_bitmap - updates the textures from the surface
 - make get_ui_atlas use these
 - takes atlas initialization from 55ms to 1ms
 - adds insets, treenodes, columns and headers
 - functions for adjusting layout (row widths, heights, etc)
 - more sensible initial layout
 - documentation for all existing functions
 - provides warnings to the user when the API is misused
 - also rationalises layouting further
 - adds paragraphs, checkboxes, sliders, number boxes,
   text boxes, and 'with label' variants
 - adds functions to test if last element was changed/confirmed
 - updates demo to show all widgets + multi-lingual support
 - atlas based (see explanation in comment)
 - when called, generates an atlas for that sized blur
 - caches the last 20 of these for re-use
 - reduces duplication of logic
 - system font now has a name, '__system_font__'
 - rather than simply adjusting the brightness, increase
   saturation and adjust brightness to keep things perceptually
   sensible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants