Added breakpoints code.

This commit is contained in:
2021-09-13 09:51:16 -07:00
parent e6ef96ae78
commit 9dd9ce7cbd
4 changed files with 114 additions and 1 deletions

View File

@ -69,9 +69,9 @@
#include "poker/turn.h"
#include "poker/winner.h"
// User Interface Objects
#include "ui/align.h"
#include "ui/breakpoint.h"
#include "ui/frame.h"
#include "ui/framedtextmenu.h"
#include "ui/grid.h"

View File

@ -0,0 +1,30 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
/** Maximum breakpoints that the list can support. */
#define BREAKPOINT_COUNT_MAX 0x04
/** Callback for when a new breakpint is reached. */
typedef void breakpointcallback_t(void *user, uint8_t i, float breakpoint);
typedef struct {
/** List of breakpoints */
float breakpoints[BREAKPOINT_COUNT_MAX];
uint8_t breakpointCount;
/** Which breakpoint is current */
uint8_t breakpointCurrent;
/** Pointer to any custom user data. */
void *user;
/** Callback for when a breakpoint is reached */
breakpointcallback_t *onBreakpoint;
} breakpointlist_t;

44
src/ui/breakpoint.c Normal file
View File

@ -0,0 +1,44 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "breakpoint.h"
void breakpointListInit(breakpointlist_t *list) {
list->breakpointCount = 0;
list->user = NULL;
list->onBreakpoint = NULL;
list->breakpointCurrent = 0x00;
}
uint8_t breakpointGet(breakpointlist_t *list, float width) {
uint8_t bp, i;
bp = 0xFF;
for(i = 0; i < list->breakpointCount; i++) {
if(list->breakpoints[i] > width) break;
bp = i;
}
if(bp == 0xFF) bp = 0;
return bp;
}
void breakpointAdd(breakpointlist_t *list, float width) {
list->breakpoints[list->breakpointCount++] = width;
}
void breakpointResize(breakpointlist_t *list, float width) {
uint8_t bp;
// Determine breakpoint
bp = breakpointGet(list, width);
if(list->breakpointCurrent == bp) return;
list->breakpointCurrent = bp;
// Fire event.
if(list->onBreakpoint != NULL) {
list->onBreakpoint(list->user, bp, list->breakpoints[bp]);
}
}

39
src/ui/breakpoint.h Normal file
View File

@ -0,0 +1,39 @@
// Copyright (c) 2021 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
/**
* Initialize a breakpoint.
*
* @param list List to initialize.
*/
void breakpointInit(breakpointlist_t *list);
/**
* Get the breakpoint for a given width set.
*
* @param list List to get from.
* @param width Width to use.
* @return The breakpoint (index) for this screen size.
*/
uint8_t breakpointGet(breakpointlist_t *list, float width);
/**
* Add a breakpoint definition to a breakpoint list.
*
* @param list List to add to.
* @param width Width of the breakpoint.
*/
void breakpointAdd(breakpointlist_t *list, float width);
/**
* Resize a breakpoint list, which (in turn) will fire the necessary events.
*
* @param list List to resize.
* @param width Width to use.
*/
void breakpointResize(breakpointlist_t *list, float width);