Loading...
Searching...
No Matches
element.c
Go to the documentation of this file.
#include "arc/console/element.h"
#include "arc/console/view.h"
#include <stdlib.h>
#include <ncurses.h>
void ARC_ConsoleElement_Create(ARC_ConsoleElement **element, uint32_t type, uint8_t flags, ARC_String *string, ARC_Point pos, ARC_ConsoleElement_RenderFn renderFn){
*element = (ARC_ConsoleElement *)malloc(sizeof(ARC_ConsoleElement));
(*element)->type = type;
(*element)->flags = flags;
(*element)->string = string;
(*element)->pos = pos;
(*element)->renderFn = renderFn;
}
void ARC_ConsoleElement_Destroy(ARC_ConsoleElement *element){
free(element);
}
void ARC_ConsoleElement_DefaultRenderFn(ARC_ConsoleView *view, ARC_ConsoleElement *element){
if(element->flags & ARC_CONSOLE_ELEMENT_FLAG_SELECTED){
ARC_ConsoleView_SetAttribute(view, ARC_CONSOLE_VIEW_ATTRIBUTE_REVERSE);
}
ARC_ConsoleView_RenderStringAt(view, element->string, element->pos);
if(element->flags & ARC_CONSOLE_ELEMENT_FLAG_SELECTED){
ARC_ConsoleView_SetAttribute(view, ARC_CONSOLE_VIEW_ATTRIBUTE_NONE);
}
}
ARC_Bool ARC_ConsoleElement_IsSelectable(ARC_ConsoleElement *element){
if(element->flags & ARC_CONSOLE_ELEMENT_FLAG_SELECTABLE){
return ARC_True;
}
return ARC_False;
}
void ARC_ConsoleElement_SetSelected(ARC_ConsoleElement *element, ARC_Bool selected){
if(selected){
element->flags |= ARC_CONSOLE_ELEMENT_FLAG_SELECTED;
return;
}
element->flags &= ~ARC_CONSOLE_ELEMENT_FLAG_SELECTED;
}
void ARC_NCursesElement_ToggleSelected(ARC_ConsoleElement *element){
element->flags ^= ARC_CONSOLE_ELEMENT_FLAG_SELECTED;
}
ARC_False
#define ARC_False
Definition bool.h:12
ARC_True
#define ARC_True
Definition bool.h:11
ARC_Bool
#define ARC_Bool
Definition bool.h:10
view.h
ARC_ConsoleView_RenderStringAt
void ARC_ConsoleView_RenderStringAt(ARC_ConsoleView *view, ARC_String *text, ARC_Point pos)
Definition view.c:109
ARC_CONSOLE_VIEW_ATTRIBUTE_REVERSE
#define ARC_CONSOLE_VIEW_ATTRIBUTE_REVERSE
Definition view.h:253
ARC_CONSOLE_VIEW_ATTRIBUTE_NONE
#define ARC_CONSOLE_VIEW_ATTRIBUTE_NONE
border options
Definition view.h:252
ARC_ConsoleView_SetAttribute
void ARC_ConsoleView_SetAttribute(ARC_ConsoleView *view, uint32_t attribute)
sets a border on the ARC_ConsoleView
Definition view.c:259
ARC_ConsoleElement_DefaultRenderFn
void ARC_ConsoleElement_DefaultRenderFn(ARC_ConsoleView *view, ARC_ConsoleElement *element)
Definition element.c:21
ARC_ConsoleElement_SetSelected
void ARC_ConsoleElement_SetSelected(ARC_ConsoleElement *element, ARC_Bool selected)
Definition element.c:41
ARC_ConsoleElement_IsSelectable
ARC_Bool ARC_ConsoleElement_IsSelectable(ARC_ConsoleElement *element)
Definition element.c:33
ARC_ConsoleElement_Create
void ARC_ConsoleElement_Create(ARC_ConsoleElement **element, uint32_t type, uint8_t flags, ARC_String *string, ARC_Point pos, ARC_ConsoleElement_RenderFn renderFn)
Definition element.c:7
ARC_NCursesElement_ToggleSelected
void ARC_NCursesElement_ToggleSelected(ARC_ConsoleElement *element)
Definition element.c:50
ARC_ConsoleElement_Destroy
void ARC_ConsoleElement_Destroy(ARC_ConsoleElement *element)
Definition element.c:17
element.h
ARC_CONSOLE_ELEMENT_FLAG_SELECTED
#define ARC_CONSOLE_ELEMENT_FLAG_SELECTED
Definition element.h:42
ARC_CONSOLE_ELEMENT_FLAG_SELECTABLE
#define ARC_CONSOLE_ELEMENT_FLAG_SELECTABLE
Definition element.h:41
ARC_ConsoleElement_RenderFn
void(* ARC_ConsoleElement_RenderFn)(ARC_ConsoleView *view, ARC_ConsoleElement *element)
Definition element.h:22
ARC_ConsoleElement
Definition element.h:27
ARC_ConsoleElement::type
uint32_t type
Definition element.h:28
ARC_ConsoleElement::string
ARC_String * string
Definition element.h:30
ARC_ConsoleElement::pos
ARC_Point pos
Definition element.h:32
ARC_ConsoleElement::flags
uint8_t flags
Definition element.h:29
ARC_ConsoleView
Definition view.c:15
ARC_Point
Definition point.h:10
ARC_String
substring position within a string
Definition string.h:14