wlmaker
Loading...
Searching...
No Matches
Functions | Variables
menu_item.c File Reference
#include "menu_item.h"
#include "gfxbuf.h"
#include "primitives.h"
Include dependency graph for menu_item.c:

Functions

static bool _wlmtk_menu_item_redraw (wlmtk_menu_item_t *menu_item_ptr)
 
static void _wlmtk_menu_item_apply_state (wlmtk_menu_item_t *menu_item_ptr)
 
static struct wlr_buffer * _wlmtk_menu_item_create_buffer (wlmtk_menu_item_t *menu_item_ptr, wlmtk_menu_item_state_t state)
 
static bool _wlmtk_menu_item_element_pointer_button (wlmtk_element_t *element_ptr, const wlmtk_button_event_t *button_event_ptr)
 
static void _wlmtk_menu_item_element_pointer_enter (wlmtk_element_t *element_ptr)
 
static void _wlmtk_menu_item_element_pointer_leave (wlmtk_element_t *element_ptr)
 
bool wlmtk_menu_item_init (wlmtk_menu_item_t *menu_item_ptr, const wlmtk_menu_item_style_t *style_ptr, wlmtk_env_t *env_ptr)
 
wlmtk_menu_item_vmt_t wlmtk_menu_item_extend (wlmtk_menu_item_t *menu_item_ptr, const wlmtk_menu_item_vmt_t *menu_item_vmt_ptr)
 
void wlmtk_menu_item_fini (wlmtk_menu_item_t *menu_item_ptr)
 
bool wlmtk_menu_item_set_text (wlmtk_menu_item_t *menu_item_ptr, const char *text_ptr)
 
void wlmtk_menu_item_set_enabled (wlmtk_menu_item_t *menu_item_ptr, bool enabled)
 
bs_dllist_node_t * wlmtk_dlnode_from_menu_item (wlmtk_menu_item_t *menu_item_ptr)
 
wlmtk_menu_item_twlmtk_menu_item_from_dlnode (bs_dllist_node_t *dlnode_ptr)
 
wlmtk_element_twlmtk_menu_item_element (wlmtk_menu_item_t *menu_item_ptr)
 
static void _wlmtk_fake_menu_item_element_destroy (wlmtk_element_t *element_ptr)
 
static void _wlmtk_fake_menu_item_clicked (wlmtk_menu_item_t *menu_item_ptr)
 
wlmtk_fake_menu_item_twlmtk_fake_menu_item_create (void)
 
void wlmtk_fake_menu_item_destroy (wlmtk_fake_menu_item_t *fake_menu_item_ptr)
 
static void test_init_fini (bs_test_t *test_ptr)
 
static void test_buffers (bs_test_t *test_ptr)
 
static void test_pointer (bs_test_t *test_ptr)
 
static void test_clicked (bs_test_t *test_ptr)
 

Variables

static const wlmtk_element_vmt_t _wlmtk_menu_item_element_vmt
 
static const wlmtk_menu_item_style_t _wlmtk_menu_item_test_style
 
static const wlmtk_menu_item_vmt_t _wlmtk_fake_menu_item_vmt
 
static const wlmtk_element_vmt_t _wlmtk_fake_menu_item_element_vmt
 
const bs_test_case_t wlmtk_menu_item_test_cases []
 

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_fake_menu_item_clicked()

void _wlmtk_fake_menu_item_clicked ( wlmtk_menu_item_t * menu_item_ptr)
static

Implements wlmtk_menu_item_vmt_t::clicked for the fake menu item.

◆ _wlmtk_fake_menu_item_element_destroy()

void _wlmtk_fake_menu_item_element_destroy ( wlmtk_element_t * element_ptr)
static

Dtor: Implements wlmtk_element_vmt_t::destroy.

◆ _wlmtk_menu_item_apply_state()

void _wlmtk_menu_item_apply_state ( wlmtk_menu_item_t * menu_item_ptr)
static

Applies the state: Sets the parent buffer's content accordingly.

◆ _wlmtk_menu_item_create_buffer()

struct wlr_buffer * _wlmtk_menu_item_create_buffer ( wlmtk_menu_item_t * menu_item_ptr,
wlmtk_menu_item_state_t state )
static

Creates a wlr_buffer with the menu item drawn for the given state.

Parameters
menu_item_ptr
state
Returns
A wlr_buffer, or NULL on error.

◆ _wlmtk_menu_item_element_pointer_button()

bool _wlmtk_menu_item_element_pointer_button ( wlmtk_element_t * element_ptr,
const wlmtk_button_event_t * button_event_ptr )
static

Checks if the button event is a click, and calls the handler.

◆ _wlmtk_menu_item_element_pointer_enter()

void _wlmtk_menu_item_element_pointer_enter ( wlmtk_element_t * element_ptr)
static

Handles when the pointer enters the element: Highlights, if enabled.

◆ _wlmtk_menu_item_element_pointer_leave()

void _wlmtk_menu_item_element_pointer_leave ( wlmtk_element_t * element_ptr)
static

Handles when the pointer leaves the element: Ends highlight.

◆ _wlmtk_menu_item_redraw()

bool _wlmtk_menu_item_redraw ( wlmtk_menu_item_t * menu_item_ptr)
static

Redraws the buffers for the menu item. Also updates the buffer state.

◆ test_buffers()

void test_buffers ( bs_test_t * test_ptr)
static

Exercises drawing.

◆ test_clicked()

void test_clicked ( bs_test_t * test_ptr)
static

Verifies desired clicks are passed to the handler.

◆ test_init_fini()

void test_init_fini ( bs_test_t * test_ptr)
static

Exercises setup and teardown and a few accessors.

◆ test_pointer()

void test_pointer ( bs_test_t * test_ptr)
static

Tests pointer entering & leaving.

◆ wlmtk_dlnode_from_menu_item()

bs_dllist_node_t * wlmtk_dlnode_from_menu_item ( wlmtk_menu_item_t * menu_item_ptr)

Returns pointer to wlmtk_menu_item_t::dlnode.

◆ wlmtk_fake_menu_item_create()

wlmtk_fake_menu_item_t * wlmtk_fake_menu_item_create ( void )

Ctor for the fake menu item.

◆ wlmtk_fake_menu_item_destroy()

void wlmtk_fake_menu_item_destroy ( wlmtk_fake_menu_item_t * fake_menu_item_ptr)

Dtor for the fake menu item.

◆ wlmtk_menu_item_element()

wlmtk_element_t * wlmtk_menu_item_element ( wlmtk_menu_item_t * menu_item_ptr)

Returns a pointer to the superclass wlmtk_element_t.

◆ wlmtk_menu_item_extend()

wlmtk_menu_item_vmt_t wlmtk_menu_item_extend ( wlmtk_menu_item_t * menu_item_ptr,
const wlmtk_menu_item_vmt_t * menu_item_vmt_ptr )

Extends the menu item's virtual methods.

Parameters
menu_item_ptr
menu_item_vmt_ptr
Returns
The previous virtual method table.

◆ wlmtk_menu_item_fini()

void wlmtk_menu_item_fini ( wlmtk_menu_item_t * menu_item_ptr)

Un-initializes the menu item.

Parameters
menu_item_ptr

◆ wlmtk_menu_item_from_dlnode()

wlmtk_menu_item_t * wlmtk_menu_item_from_dlnode ( bs_dllist_node_t * dlnode_ptr)

Returns the base wlmtk_menu_item_t from dlnode_ptr.

◆ wlmtk_menu_item_init()

bool wlmtk_menu_item_init ( wlmtk_menu_item_t * menu_item_ptr,
const wlmtk_menu_item_style_t * style_ptr,
wlmtk_env_t * env_ptr )

Initializes the menu item.

Note: Menu items are created as visible elements.

Parameters
menu_item_ptr
style_ptr
env_ptr
Returns
true iff the initialization succeeded.

◆ wlmtk_menu_item_set_enabled()

void wlmtk_menu_item_set_enabled ( wlmtk_menu_item_t * menu_item_ptr,
bool enabled )

Sets whether the menu item is enabled or disabled.

Parameters
menu_item_ptr
enabled

◆ wlmtk_menu_item_set_text()

bool wlmtk_menu_item_set_text ( wlmtk_menu_item_t * menu_item_ptr,
const char * text_ptr )

Sets or updates the text for the menu item.

Parameters
menu_item_ptr
text_ptr

Variable Documentation

◆ _wlmtk_fake_menu_item_element_vmt

const wlmtk_element_vmt_t _wlmtk_fake_menu_item_element_vmt
static
Initial value:
= {
}
static void _wlmtk_fake_menu_item_element_destroy(wlmtk_element_t *element_ptr)
Definition menu_item.c:390

Virtual method table for the fake menu item's element superclass.

◆ _wlmtk_fake_menu_item_vmt

const wlmtk_menu_item_vmt_t _wlmtk_fake_menu_item_vmt
static
Initial value:
= {
}
static void _wlmtk_fake_menu_item_clicked(wlmtk_menu_item_t *menu_item_ptr)
Definition menu_item.c:400

Virtual method table for the fake menu item.

◆ _wlmtk_menu_item_element_vmt

const wlmtk_element_vmt_t _wlmtk_menu_item_element_vmt
static
Initial value:
= {
}
static void _wlmtk_menu_item_element_pointer_enter(wlmtk_element_t *element_ptr)
Definition menu_item.c:315
static bool _wlmtk_menu_item_element_pointer_button(wlmtk_element_t *element_ptr, const wlmtk_button_event_t *button_event_ptr)
Definition menu_item.c:294
static void _wlmtk_menu_item_element_pointer_leave(wlmtk_element_t *element_ptr)
Definition menu_item.c:330

Virtual method table for the menu item's super class: Element.

◆ _wlmtk_menu_item_test_style

const wlmtk_menu_item_style_t _wlmtk_menu_item_test_style
static
Initial value:
= {
.fill = {
.param = { .dgradient = { .from = 0xff102040, .to = 0xff4080ff }}
},
.highlighted_fill = {
.param = { .solid = { .color = 0xffc0d0e0 } }
},
.font = { .face = "Helvetica", .size = 14 },
.height = 24,
.bezel_width = 1,
.enabled_text_color = 0xfff0f060,
.highlighted_text_color = 0xff204080,
.disabled_text_color = 0xff807060,
}
@ WLMTK_STYLE_COLOR_SOLID
Definition style.h:33
@ WLMTK_STYLE_COLOR_DGRADIENT
Definition style.h:45

Style definition used for unit tests.

◆ wlmtk_menu_item_test_cases

const bs_test_case_t wlmtk_menu_item_test_cases[]
Initial value:
= {
{ 1, "init_fini", test_init_fini },
{ 0, "buffers", test_buffers },
{ 1, "pointer", test_pointer },
{ 1, "clicked", test_clicked },
{ 0, NULL, NULL }
}
static void test_clicked(bs_test_t *test_ptr)
Definition menu_item.c:544
static void test_buffers(bs_test_t *test_ptr)
Definition menu_item.c:452
static void test_pointer(bs_test_t *test_ptr)
Definition menu_item.c:481
static void test_init_fini(bs_test_t *test_ptr)
Definition menu_item.c:426

Unit test cases.