neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
text_field.hpp
Go to the documentation of this file.
1// text_field.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include "label.hpp"
24#include "line_edit.hpp"
25
26namespace neogfx
27{
28 enum class text_field_placement : uint32_t
29 {
30 NoLabel = 0x00000000,
31 LabelLeft = 0x00000001,
32 LabelAbove = 0x00000002
33 };
34}
35
41
42namespace neogfx
43{
44 class text_field : public widget<>
45 {
46 meta_object(widget<>)
47 private:
48 class input_box_container : public framed_widget<>
49 {
50 typedef framed_widget<> base_type;
51 public:
52 input_box_container(text_field& aParent, i_layout& aParentLayout, frame_style aFrameStyle);
53 public:
54 color frame_color() const override;
55 public:
56 color palette_color(color_role aColorRole) const override;
57 private:
58 text_field& iParent;
59 };
60 public:
61 struct no_label : std::logic_error { no_label() : std::logic_error{ "neogfx::text_field::no_label" } {} };
62 public:
63 text_field(std::string const& aLabel = std::string{}, std::string const& aHint = std::string{}, text_field_placement aPlacement = text_field_placement::LabelAbove, frame_style aFrameStyle = frame_style::SolidFrame);
64 text_field(i_widget& aParent, std::string const& aLabel = std::string{}, std::string const& aHint = std::string{}, text_field_placement aPlacement = text_field_placement::LabelAbove, frame_style aFrameStyle = frame_style::SolidFrame);
65 text_field(i_layout& aLayout, std::string const& aLabel = std::string{}, std::string const& aHint = std::string{}, text_field_placement aPlacement = text_field_placement::LabelAbove, frame_style aFrameStyle = frame_style::SolidFrame);
66 public:
67 i_string const& text() const;
68 void set_text(i_string const& aText);
69 bool has_label() const;
70 const neogfx::label& label() const;
71 neogfx::label& label();
72 const line_edit& input_box() const;
73 line_edit& input_box();
74 const text_widget& hint() const;
75 text_widget& hint();
76 text_field_placement placement() const;
77 void set_placement(text_field_placement aPlacement);
78 const text_widget& help() const;
79 text_widget& help();
80 protected:
81 neogfx::size_policy size_policy() const override;
82 protected:
83 size minimum_size(optional_size const& aAvailableSpace = optional_size{}) const override;
84 size maximum_size(optional_size const& aAvailableSpace = optional_size{}) const override;
85 protected:
86 void focus_gained(focus_reason aFocusReason) override;
87 private:
88 void init();
89 private:
90 sink iSink;
91 text_field_placement iPlacement;
92 vertical_layout iLayout;
93 std::optional<neogfx::label> iLabel;
94 horizontal_layout iInputLayout;
95 input_box_container iInputBoxContainer;
96 horizontal_layout iInputBoxContainerLayout;
97 line_edit iInputBox;
98 horizontal_layout iInputBoxLayout;
99 text_widget iHint;
100 text_widget iHelp;
101 };
102}
#define end_declare_enum(enumName)
Definition i_enum.hpp:62
#define declare_enum_string(enumName, enumEnumerator)
Definition i_enum.hpp:59
#define begin_declare_enum(enumName)
Definition i_enum.hpp:52
text_field_placement
sRGB_color color
Definition color.hpp:1067
basic_size< coordinate > size
Definition plf_hive.h:79
#define meta_object(...)
Definition i_object.hpp:28