wlmaker
Loading...
Searching...
No Matches
box.c File Reference
#include "box.h"
#include <stdint.h>
#include <string.h>
#include "libbase/libbase.h"
#include "container.h"
#include "rectangle.h"
Include dependency graph for box.c:

Functions

static void _wlmtk_box_element_layout (wlmtk_element_t *element_ptr)
static bs_dllist_node_t * create_margin (wlmtk_box_t *box_ptr)
static void _wlmtk_box_margin_set_color (bs_dllist_node_t *dlnode_ptr, void *ud_ptr)
bool wlmtk_box_init (wlmtk_box_t *box_ptr, wlmtk_box_orientation_t orientation, const struct wlmtk_margin_style *style_ptr)
void wlmtk_box_fini (wlmtk_box_t *box_ptr)
void wlmtk_box_add_element_front (wlmtk_box_t *box_ptr, wlmtk_element_t *element_ptr)
void wlmtk_box_add_element_back (wlmtk_box_t *box_ptr, wlmtk_element_t *element_ptr)
void wlmtk_box_remove_element (wlmtk_box_t *box_ptr, wlmtk_element_t *element_ptr)
wlmtk_element_twlmtk_box_element (wlmtk_box_t *box_ptr)
void wlmtk_box_set_style (wlmtk_box_t *box_ptr, const struct wlmtk_margin_style *style_ptr)
static void test_init_fini (bs_test_t *test_ptr)
static void test_layout_horizontal (bs_test_t *test_ptr)
static void test_layout_vertical (bs_test_t *test_ptr)

Variables

static const wlmtk_element_vmt_t box_element_vmt
static const bs_test_case_t _wlmtk_box_test_cases []
const bs_test_set_t wlmtk_box_test_set
static const struct wlmtk_margin_style test_style

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _wlmtk_box_element_layout()

void _wlmtk_box_element_layout ( wlmtk_element_t * element_ptr)
static

Lays out the elements of the box.

Steps through all visible elements, and sets their position to be left-to-right. Also updates and repositions all margin elements.

Parameters
element_ptr

◆ _wlmtk_box_margin_set_color()

void _wlmtk_box_margin_set_color ( bs_dllist_node_t * dlnode_ptr,
void * ud_ptr )
static

Sets the color in each margin rectangle.

◆ create_margin()

bs_dllist_node_t * create_margin ( wlmtk_box_t * box_ptr)
static

Creates a new margin element, and returns the dlnode.

◆ test_init_fini()

void test_init_fini ( bs_test_t * test_ptr)
static

Exercises setup and teardown.

◆ test_layout_horizontal()

void test_layout_horizontal ( bs_test_t * test_ptr)
static

Tests layouting horizontally

◆ test_layout_vertical()

void test_layout_vertical ( bs_test_t * test_ptr)
static

Tests layouting vertically

◆ wlmtk_box_add_element_back()

void wlmtk_box_add_element_back ( wlmtk_box_t * box_ptr,
wlmtk_element_t * element_ptr )

Adds element_ptr to the back of the box.

Parameters
box_ptr
element_ptr

◆ wlmtk_box_add_element_front()

void wlmtk_box_add_element_front ( wlmtk_box_t * box_ptr,
wlmtk_element_t * element_ptr )

Adds element_ptr to the front of the box.

Parameters
box_ptr
element_ptr

◆ wlmtk_box_element()

wlmtk_element_t * wlmtk_box_element ( wlmtk_box_t * box_ptr)
Returns
Pointer to the superclass' wlmtk_element_t of box_ptr.

◆ wlmtk_box_fini()

void wlmtk_box_fini ( wlmtk_box_t * box_ptr)

Un-initializes the box.

Parameters
box_ptr

◆ wlmtk_box_init()

bool wlmtk_box_init ( wlmtk_box_t * box_ptr,
wlmtk_box_orientation_t orientation,
const struct wlmtk_margin_style * style_ptr )

Initializes the box with the provided virtual method table.

Parameters
box_ptr
orientation
style_ptr
Returns
true on success.

◆ wlmtk_box_remove_element()

void wlmtk_box_remove_element ( wlmtk_box_t * box_ptr,
wlmtk_element_t * element_ptr )

Removes element_ptr from the box.

Requires that element_ptr is an element of the box.

Parameters
box_ptr
element_ptr

◆ wlmtk_box_set_style()

void wlmtk_box_set_style ( wlmtk_box_t * box_ptr,
const struct wlmtk_margin_style * style_ptr )

Updates the box style and updates the layout of the contained elements.

Variable Documentation

◆ _wlmtk_box_test_cases

const bs_test_case_t _wlmtk_box_test_cases[]
static
Initial value:
= {
{ 1, "init_fini", test_init_fini },
{ 1, "layout_horizontal", test_layout_horizontal },
{ 1, "layout_vertical", test_layout_vertical },
}
static void test_init_fini(bs_test_t *test_ptr)
Definition base.c:167
static void test_layout_horizontal(bs_test_t *test_ptr)
Definition box.c:311
static void test_layout_vertical(bs_test_t *test_ptr)
Definition box.c:379

Test cases

◆ box_element_vmt

const wlmtk_element_vmt_t box_element_vmt
static
Initial value:
= {
}
static void _wlmtk_box_element_layout(wlmtk_element_t *element_ptr)
Definition box.c:160

Virtual method table: wlmtk_element_t at wlmtk_box_t level.

◆ test_style

const struct wlmtk_margin_style test_style
static
Initial value:
= {
.width = 2,
.color = 0xff000000
}

Style used for tests.

◆ wlmtk_box_test_set

const bs_test_set_t wlmtk_box_test_set
Initial value:
= BS_TEST_SET(
true, "box", _wlmtk_box_test_cases)
static const bs_test_case_t _wlmtk_box_test_cases[]
Definition box.c:277

Unit tests.