wlmaker
Loading...
Searching...
No Matches
menu_item.c File Reference
#include "menu_item.h"
#include <libbase/libbase.h>
#include "config.h"
#include "toolkit/toolkit.h"
Include dependency graph for menu_item.c:

Classes

struct  _wlmaker_menu_item_t
 

Enumerations

enum  wlmaker_menu_item_state_t { WLMAKER_MENU_ITEM_STATE_UNDEFINED = 0 , WLMAKER_MENU_ITEM_STATE_DISABLED , WLMAKER_MENU_ITEM_STATE_ENABLED , WLMAKER_MENU_ITEM_STATE_SELECTED }
 

Functions

wlmaker_menu_item_twlmaker_menu_item_create (const wlmaker_menu_item_descriptor_t *desc_ptr, void *callback_ud_ptr)
 
void wlmaker_menu_item_destroy (wlmaker_menu_item_t *menu_item_ptr)
 
void wlmaker_menu_item_get_desired_size (const wlmaker_menu_item_t *menu_item_ptr, uint32_t *width_ptr, uint32_t *height_ptr)
 
void wlmaker_menu_item_set_size (wlmaker_menu_item_t *menu_item_ptr, uint32_t width, uint32_t height)
 
void wlmaker_menu_item_set_position (wlmaker_menu_item_t *menu_item_ptr, uint32_t x, uint32_t y)
 
void wlmaker_menu_item_draw (wlmaker_menu_item_t *menu_item_ptr, cairo_t *cairo_ptr)
 
bs_dllist_node_t * wlmaker_dlnode_from_menu_item (wlmaker_menu_item_t *item_ptr)
 
wlmaker_menu_item_twlmaker_menu_item_from_dlnode (bs_dllist_node_t *dlnode_ptr)
 
void wlmaker_menu_item_set_focus (wlmaker_menu_item_t *menu_item_ptr, bool focussed)
 
bool wlmaker_menu_item_contains (const wlmaker_menu_item_t *menu_item_ptr, double x, double y)
 
bool wlmaker_menu_item_redraw_needed (const wlmaker_menu_item_t *menu_item_ptr)
 
void wlmaker_menu_item_execute (const wlmaker_menu_item_t *menu_item_ptr)
 
static void test_draw (bs_test_t *test_ptr)
 
static void test_contains (bs_test_t *test_ptr)
 

Variables

const bs_test_case_t wlmaker_menu_item_test_cases []
 
static const wlmaker_menu_item_descriptor_t test_descriptor
 
static const wlmtk_style_fill_t test_fill
 

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.

Enumeration Type Documentation

◆ wlmaker_menu_item_state_t

State of a menu item.

Enumerator
WLMAKER_MENU_ITEM_STATE_UNDEFINED 

Undefined: May not have been drawn or is initializing.

WLMAKER_MENU_ITEM_STATE_DISABLED 

Disabled: Cannot be clicked or selected.

WLMAKER_MENU_ITEM_STATE_ENABLED 

Enabled: Can be clicked or selected, but is currently not selected.

WLMAKER_MENU_ITEM_STATE_SELECTED 

Selected: Currently under the pointer.

Function Documentation

◆ test_contains()

void test_contains ( bs_test_t * test_ptr)
static

Verifies the contains function.

◆ test_draw()

void test_draw ( bs_test_t * test_ptr)
static

Verifies the menu item is drawn as desired.

◆ wlmaker_dlnode_from_menu_item()

bs_dllist_node_t * wlmaker_dlnode_from_menu_item ( wlmaker_menu_item_t * item_ptr)

Cast: Returns the a pointer to the bs_dllist_node_t of |item_ptr|.

Parameters
item_ptr
Returns
The pointer.

◆ wlmaker_menu_item_contains()

bool wlmaker_menu_item_contains ( const wlmaker_menu_item_t * menu_item_ptr,
double x,
double y )

Returns whether the menu item contains |x|, |y|.

This is satisfied if |x| is in [item.x, item.x + width) and |y| is in [item.y, item.y + height).

Parameters
menu_item_ptr
x
y

◆ wlmaker_menu_item_create()

wlmaker_menu_item_t * wlmaker_menu_item_create ( const wlmaker_menu_item_descriptor_t * desc_ptr,
void * callback_ud_ptr )

Creates a menu item from the given descriptor.

Parameters
desc_ptr
callback_ud_ptrArgument to provide to item's callbacks.
Returns
A pointer to a wlmaker_menu_item_t or NULL on error. Must be destroyed by calling wlmaker_menu_item_destroy().

◆ wlmaker_menu_item_destroy()

void wlmaker_menu_item_destroy ( wlmaker_menu_item_t * menu_item_ptr)

Destroys a menu item previously created by wlmaker_menu_item_create().

Parameters
menu_item_ptr

◆ wlmaker_menu_item_draw()

void wlmaker_menu_item_draw ( wlmaker_menu_item_t * menu_item_ptr,
cairo_t * cairo_ptr )

Draws the menu item. Uses the position and size set previously.

Parameters
menu_item_ptr
cairo_ptr

◆ wlmaker_menu_item_execute()

void wlmaker_menu_item_execute ( const wlmaker_menu_item_t * menu_item_ptr)

Executes the action associated with the menu item, ie. call the callback.

Parameters
menu_item_ptr

◆ wlmaker_menu_item_from_dlnode()

wlmaker_menu_item_t * wlmaker_menu_item_from_dlnode ( bs_dllist_node_t * dlnode_ptr)

Cast: Returns the wlmaker_menu_item_t holding the |dlnode_ptr|.

Parameters
dlnode_ptr
Returns
The pointer.

◆ wlmaker_menu_item_get_desired_size()

void wlmaker_menu_item_get_desired_size ( const wlmaker_menu_item_t * menu_item_ptr,
uint32_t * width_ptr,
uint32_t * height_ptr )

Retrieves the desired size by the menu item.

This provides the size sufficient to show the full menu item information. If the menu opts to draw the item with a smaller size, some information may be omitted, eg. the label might get clipped.

Parameters
menu_item_ptr
width_ptrMay be NULL.
height_ptrMay be NULL.

◆ wlmaker_menu_item_redraw_needed()

bool wlmaker_menu_item_redraw_needed ( const wlmaker_menu_item_t * menu_item_ptr)

Returns whether the menu item should be redrawn.

This is the case when the state becomes different from the drawn state.

Parameters
menu_item_ptr

◆ wlmaker_menu_item_set_focus()

void wlmaker_menu_item_set_focus ( wlmaker_menu_item_t * menu_item_ptr,
bool focussed )

Sets the pointer focus state of the menu item (show as selected).

Parameters
menu_item_ptr
focussed

◆ wlmaker_menu_item_set_position()

void wlmaker_menu_item_set_position ( wlmaker_menu_item_t * menu_item_ptr,
uint32_t x,
uint32_t y )

Sets the size of this menu item, relative to the cairo_t it will draw in.

Parameters
menu_item_ptr
x
y

◆ wlmaker_menu_item_set_size()

void wlmaker_menu_item_set_size ( wlmaker_menu_item_t * menu_item_ptr,
uint32_t width,
uint32_t height )

Sets the size of the menu item. Will be used throughout subsequent draw operations.

Parameters
menu_item_ptr
width
height

Variable Documentation

◆ test_descriptor

const wlmaker_menu_item_descriptor_t test_descriptor
static
Initial value:
= {
.type = WLMAKER_MENU_ITEM_ENTRY,
.param.entry = { .label_ptr = "Label", .callback = NULL }
}

Descriptor of the menu item used in the unit test.

◆ test_fill

const wlmtk_style_fill_t test_fill
static
Initial value:
= {
.param = { .hgradient = { .from = 0xffa6a6b6,.to = 0xff515561 }}
}
@ WLMTK_STYLE_COLOR_DGRADIENT
Definition style.h:36

Properties of the fill, used for the unit test.

◆ wlmaker_menu_item_test_cases

const bs_test_case_t wlmaker_menu_item_test_cases[]
Initial value:
= {
{ 1, "draw", test_draw },
{ 1, "contains", test_contains },
{ 0, NULL, NULL }
}
static void test_contains(bs_test_t *test_ptr)
Definition menu_item.c:291
static void test_draw(bs_test_t *test_ptr)
Definition menu_item.c:252

Unit tests.