<commit_before>#include <pebble.h>
#include "Logging.h"
#include "OptionsMenu.h"
#include "TextBox.h"
#include "Utils.h"

typedef struct TextBox
{
	int xoffset;
	int yoffset;
	GFont font;
	GRect frame;
    bool allowScroll;
    GTextAlignment align;
	Layer *mainLayer;
	TextLayer *textLayer;
    ScrollLayer *scrollLayer;
	bool initialized;
} TextBox;

bool TextBoxInitialized(TextBox *textBox)
{
	return textBox && textBox->initialized;
}

void TextBoxSetText(TextBox *textBox, const char *text)
{
	if(!textBox || !textBox->initialized)
		return;
	
    GRect bounds = {.origin = {0}, .size = {0}};

    if(textBox->scrollLayer)
    {
        bounds = layer_get_bounds((Layer*)textBox->scrollLayer);
        text_layer_set_size(textBox->textLayer, GSize(bounds.size.w, 2000));
    }
    
	text_layer_set_text(textBox->textLayer, text);
    if(textBox->scrollLayer)
    {
        GPoint offset = GPointZero;
        scroll_layer_set_content_offset(textBox->scrollLayer, offset, false);
        GSize max_size = text_layer_get_content_size(textBox->textLayer);
        text_layer_set_size(textBox->textLayer, max_size);
        scroll_layer_set_content_size(textBox->scrollLayer, GSize(bounds.size.w, max_size.h + 4));
    }
}

const char *TextBoxGetText(TextBox *textBox)
{
	if(!textBox || !textBox->initialized)
		return "";
	
	return text_layer_get_text(textBox->textLayer);
}

void RemoveTextBox(TextBox *textBox)
{
	if(!textBox || !textBox->initialized)
		return;

	layer_remove_from_parent(textBox->mainLayer);
}

TextBox *CreateTextBox(int xoffset, int yoffset, GFont font, GRect frame, GTextAlignment align, bool scroll)
{
	TextBox *textBox = calloc(sizeof(TextBox), 1);
	textBox->font = font;
	textBox->frame = frame;
	textBox->xoffset = xoffset;
	textBox->yoffset = yoffset;
    textBox->allowScroll = scroll;
    textBox->align = align;
	return textBox;
}<commit_msg>Fixing display of undersigning letters at the end of text boxes.<commit_after>#include <pebble.h>
#include "Logging.h"
#include "OptionsMenu.h"
#include "TextBox.h"
#include "Utils.h"

typedef struct TextBox
{
	int xoffset;
	int yoffset;
	GFont font;
	GRect frame;
    bool allowScroll;
    GTextAlignment align;
	Layer *mainLayer;
	TextLayer *textLayer;
    ScrollLayer *scrollLayer;
	bool initialized;
} TextBox;

bool TextBoxInitialized(TextBox *textBox)
{
	return textBox && textBox->initialized;
}

void TextBoxSetText(TextBox *textBox, const char *text)
{
	if(!textBox || !textBox->initialized)
		return;
	
    GRect bounds = {.origin = {0}, .size = {0}};

    if(textBox->scrollLayer)
    {
        bounds = layer_get_bounds((Layer*)textBox->scrollLayer);
        text_layer_set_size(textBox->textLayer, GSize(bounds.size.w, 2000));
    }
    
	text_layer_set_text(textBox->textLayer, text);
    if(textBox->scrollLayer)
    {
        GPoint offset = GPointZero;
        scroll_layer_set_content_offset(textBox->scrollLayer, offset, false);
        GSize max_size = text_layer_get_content_size(textBox->textLayer);
        max_size.h += 4;
        text_layer_set_size(textBox->textLayer, max_size);
        scroll_layer_set_content_size(textBox->scrollLayer, GSize(bounds.size.w, max_size.h));
    }
}

const char *TextBoxGetText(TextBox *textBox)
{
	if(!textBox || !textBox->initialized)
		return "";
	
	return text_layer_get_text(textBox->textLayer);
}

void RemoveTextBox(TextBox *textBox)
{
	if(!textBox || !textBox->initialized)
		return;

	layer_remove_from_parent(textBox->mainLayer);
}

TextBox *CreateTextBox(int xoffset, int yoffset, GFont font, GRect frame, GTextAlignment align, bool scroll)
{
	TextBox *textBox = calloc(sizeof(TextBox), 1);
	textBox->font = font;
	textBox->frame = frame;
	textBox->xoffset = xoffset;
	textBox->yoffset = yoffset;
    textBox->allowScroll = scroll;
    textBox->align = align;
	return textBox;
}
{'fraction_non_alphanumeric': 0.12343096234309624, 'fraction_numerical': 0.0041841004184100415, 'mean_word_length': 4.448717948717949, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5580160', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1304, 'n_words': 263}