widget: new label widget
This commit is contained in:
parent
62a47e236d
commit
12bd750d73
@ -1,20 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "holly/ta_parameter.hpp"
|
#include "holly/ta_parameter.hpp"
|
||||||
#include "ta_multiwriter.hpp"
|
|
||||||
#include "widget/button.hpp"
|
#include "widget/button.hpp"
|
||||||
|
|
||||||
namespace widget {
|
namespace widget {
|
||||||
|
|
||||||
constexpr inline int str_length(const char * s)
|
|
||||||
{
|
|
||||||
int l = 0;
|
|
||||||
while (*s++) {
|
|
||||||
l += 1;
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct button_label : button {
|
struct button_label : button {
|
||||||
const char * const label;
|
const char * const label;
|
||||||
const int label_length;
|
const int label_length;
|
||||||
|
@ -32,8 +32,8 @@ namespace widget {
|
|||||||
|
|
||||||
inline widget * pick(float _x, float _y)
|
inline widget * pick(float _x, float _y)
|
||||||
{
|
{
|
||||||
if (!inside(_x, _y))
|
//if (!inside(_x, _y))
|
||||||
return nullptr;
|
//return nullptr;
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
widget * w = children[i]->pick(_x, _y);
|
widget * w = children[i]->pick(_x, _y);
|
||||||
|
32
src/widget/label.cpp
Normal file
32
src/widget/label.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "widget/label.hpp"
|
||||||
|
|
||||||
|
#include "ta_parameter.hpp"
|
||||||
|
#include "graphics_primitive.hpp"
|
||||||
|
|
||||||
|
namespace widget {
|
||||||
|
|
||||||
|
const static float label_depth = 1.0 / 5.0;
|
||||||
|
const static int label_color = 0xa7a7a7;
|
||||||
|
|
||||||
|
const static float label_shadow_depth = 1.0 / 6.0;
|
||||||
|
const static int label_shadow_color = 0x000000;
|
||||||
|
|
||||||
|
void label::draw_label(ta_parameter_writer& writer) const
|
||||||
|
{
|
||||||
|
float y_offset = 0;
|
||||||
|
|
||||||
|
float cx = x() + width / 2 - (glyph::hori_advance * value_length) / 2;
|
||||||
|
float cy = y() + height / 2 - glyph::vert_advance / 2 + y_offset;
|
||||||
|
|
||||||
|
transfer_string(writer, value, cx, cy, label_depth, label_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void label::draw(ta_multiwriter& multi)
|
||||||
|
{
|
||||||
|
transfer_global_polygon_glyph(multi.pt);
|
||||||
|
|
||||||
|
draw_label(multi.pt);
|
||||||
|
|
||||||
|
widget::draw(multi);
|
||||||
|
}
|
||||||
|
}
|
23
src/widget/label.hpp
Normal file
23
src/widget/label.hpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "holly/ta_parameter.hpp"
|
||||||
|
#include "ta_multiwriter.hpp"
|
||||||
|
#include "widget/widget.hpp"
|
||||||
|
|
||||||
|
namespace widget {
|
||||||
|
struct label : widget {
|
||||||
|
const char * const value;
|
||||||
|
const int value_length;
|
||||||
|
|
||||||
|
inline label(float _width, float _height, const char * value)
|
||||||
|
: widget(0, 0, _width, _height), value(value), value_length(str_length(value))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
inline label(float _x, float _y, float _width, float _height, const char * value)
|
||||||
|
: widget(_x, _y, _width, _height), value(value), value_length(str_length(value))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void draw_label(ta_parameter_writer& writer) const;
|
||||||
|
void draw(ta_multiwriter& multi) override;
|
||||||
|
};
|
||||||
|
}
|
@ -11,8 +11,8 @@ namespace widget {
|
|||||||
{
|
{
|
||||||
float xi = 0;
|
float xi = 0;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
children[i]->_x = xi;
|
children[i]->_x += xi;
|
||||||
children[i]->_y = 0;
|
children[i]->_y += 0;
|
||||||
xi += children[i]->width + gap;
|
xi += children[i]->width + gap;
|
||||||
if (children[i]->height > height)
|
if (children[i]->height > height)
|
||||||
height = children[i]->height;
|
height = children[i]->height;
|
||||||
|
@ -11,8 +11,8 @@ namespace widget {
|
|||||||
{
|
{
|
||||||
float yi = 0;
|
float yi = 0;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
children[i]->_x = 0;
|
children[i]->_x += 0;
|
||||||
children[i]->_y = yi;
|
children[i]->_y += yi;
|
||||||
yi += children[i]->height + gap;
|
yi += children[i]->height + gap;
|
||||||
if (children[i]->width > width)
|
if (children[i]->width > width)
|
||||||
width = children[i]->width;
|
width = children[i]->width;
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "widget/bounding_box.hpp"
|
#include "widget/bounding_box.hpp"
|
||||||
#include "ta_multiwriter.hpp"
|
#include "ta_multiwriter.hpp"
|
||||||
|
|
||||||
#include "printf/printf.h"
|
#include "printf/printf.h"
|
||||||
|
|
||||||
namespace widget {
|
namespace widget {
|
||||||
|
constexpr inline int str_length(const char * s)
|
||||||
|
{
|
||||||
|
int l = 0;
|
||||||
|
while (*s++) {
|
||||||
|
l += 1;
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
enum class click_type {
|
enum class click_type {
|
||||||
press,
|
press,
|
||||||
@ -16,6 +26,10 @@ namespace widget {
|
|||||||
click_type click_state;
|
click_type click_state;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
inline widget(float _width, float _height)
|
||||||
|
: bounding_box(0, 0, _width, _height), click_state(click_type::release)
|
||||||
|
{ }
|
||||||
|
|
||||||
inline widget(float _x, float _y, float _width, float _height)
|
inline widget(float _x, float _y, float _width, float _height)
|
||||||
: bounding_box(_x, _y, _width, _height), click_state(click_type::release)
|
: bounding_box(_x, _y, _width, _height), click_state(click_type::release)
|
||||||
{ }
|
{ }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user