-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathctrlEdit.h
More file actions
85 lines (70 loc) · 2.19 KB
/
Copy pathctrlEdit.h
File metadata and controls
85 lines (70 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "Window.h"
#include <string>
struct MouseCoords;
class glFont;
class ctrlTextDeepening;
struct KeyEvent;
enum class EditType
{
Text,
Number,
Filename
};
enum class FileNameStatus
{
Empty,
Invalid,
Valid
};
struct GetFileNameResult
{
FileNameStatus status;
std::string name; // only set when status == Valid
};
class ctrlEdit : public Window
{
public:
ctrlEdit(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font,
unsigned short maxlength = 0, bool password = false, bool disabled = false, bool notify = false);
/// setzt den Text.
void SetText(const std::string& text);
void SetText(unsigned text);
std::string GetText() const;
/// Trims leading whitespace (and trailing whitespace only if ext is empty), appends a non-empty ext,
/// validates; returns Empty/Invalid/Valid with filename. Requires EditType::Filename.
GetFileNameResult GetFileName(const std::string& ext = "") const;
void SetFocus(bool focus = true);
bool HasFocus() const { return focus_; }
void SetDisabled(bool disabled = true) { this->isDisabled_ = disabled; }
void SetNotify(bool notify = true) { this->notify_ = notify; }
void SetType(EditType type) { this->editType_ = type; }
void Resize(const Extent& newSize) override;
bool Msg_LeftDown(const MouseCoords& mc) override;
bool Msg_KeyDown(const KeyEvent& ke) override;
protected:
void Draw_() override;
private:
void AddChar(char32_t c);
void RemoveChar();
void Notify();
void UpdateInternalText();
void CursorLeft();
void CursorRight();
unsigned short maxLength_;
ctrlTextDeepening* txtCtrl;
bool isPassword_;
bool isDisabled_;
bool focus_ = false;
bool notify_;
std::u32string text_;
/// Position of cursor in text (in UTF32 chars)
unsigned cursorPos_ = 0;
/// Offset of the cursor from the start of the text start position
unsigned cursorOffsetX_ = 0;
unsigned viewStart_ = 0;
EditType editType_ = EditType::Text;
};