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

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);