Merge pull request #10096 from toger5/label_stylebox
fixed Import LineEdit to label + label stylebox
This commit is contained in:
commit
b7f4dcbdd1
4 changed files with 19 additions and 13 deletions
|
@ -28,6 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "import_dock.h"
|
||||
#include "editor_node.h"
|
||||
|
||||
class ImportDockParameters : public Object {
|
||||
GDCLASS(ImportDockParameters, Object)
|
||||
|
@ -365,8 +366,8 @@ void ImportDock::initialize_import_options() const {
|
|||
|
||||
ImportDock::ImportDock() {
|
||||
|
||||
imported = memnew(LineEdit);
|
||||
imported->set_editable(false);
|
||||
imported = memnew(Label);
|
||||
imported->add_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_stylebox("normal", "LineEdit"));
|
||||
add_child(imported);
|
||||
HBoxContainer *hb = memnew(HBoxContainer);
|
||||
add_margin_child(TTR("Import As:"), hb);
|
||||
|
|
|
@ -41,7 +41,7 @@ class ImportDockParameters;
|
|||
class ImportDock : public VBoxContainer {
|
||||
GDCLASS(ImportDock, VBoxContainer)
|
||||
|
||||
LineEdit *imported;
|
||||
Label *imported;
|
||||
OptionButton *import_as;
|
||||
MenuButton *preset;
|
||||
PropertyEditor *import_opts;
|
||||
|
|
|
@ -85,7 +85,7 @@ void Label::_notification(int p_what) {
|
|||
|
||||
Size2 string_size;
|
||||
Size2 size = get_size();
|
||||
|
||||
Ref<StyleBox> style = get_stylebox("normal");
|
||||
Ref<Font> font = get_font("font");
|
||||
Color font_color = get_color("font_color");
|
||||
Color font_color_shadow = get_color("font_color_shadow");
|
||||
|
@ -93,6 +93,8 @@ void Label::_notification(int p_what) {
|
|||
Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y"));
|
||||
int line_spacing = get_constant("line_spacing");
|
||||
|
||||
style->draw(ci, Rect2(Point2(0, 0), get_size()));
|
||||
|
||||
VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint());
|
||||
|
||||
int font_h = font->get_height() + line_spacing;
|
||||
|
@ -193,21 +195,20 @@ void Label::_notification(int p_what) {
|
|||
case ALIGN_FILL:
|
||||
case ALIGN_LEFT: {
|
||||
|
||||
x_ofs = 0;
|
||||
x_ofs = style->get_offset().x;
|
||||
} break;
|
||||
case ALIGN_CENTER: {
|
||||
|
||||
x_ofs = int(size.width - (taken + spaces * space_w)) / 2;
|
||||
|
||||
} break;
|
||||
case ALIGN_RIGHT: {
|
||||
|
||||
x_ofs = int(size.width - (taken + spaces * space_w));
|
||||
|
||||
x_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (taken + spaces * space_w));
|
||||
} break;
|
||||
}
|
||||
|
||||
int y_ofs = (line - lines_skipped) * font_h + font->get_ascent();
|
||||
int y_ofs = style->get_offset().y;
|
||||
y_ofs += (line - lines_skipped) * font_h + font->get_ascent();
|
||||
y_ofs += vbegin + line * vsep;
|
||||
|
||||
while (from != to) {
|
||||
|
@ -288,8 +289,10 @@ void Label::_notification(int p_what) {
|
|||
|
||||
Size2 Label::get_minimum_size() const {
|
||||
|
||||
Size2 min_style = get_stylebox("normal")->get_minimum_size();
|
||||
|
||||
if (autowrap)
|
||||
return Size2(1, clip ? 1 : minsize.height);
|
||||
return Size2(1, clip ? 1 : minsize.height) + min_style;
|
||||
else {
|
||||
|
||||
// don't want to mutable everything
|
||||
|
@ -299,7 +302,7 @@ Size2 Label::get_minimum_size() const {
|
|||
Size2 ms = minsize;
|
||||
if (clip)
|
||||
ms.width = 1;
|
||||
return ms;
|
||||
return ms + min_style;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,7 +353,7 @@ int Label::get_visible_line_count() const {
|
|||
|
||||
int line_spacing = get_constant("line_spacing");
|
||||
int font_h = get_font("font")->get_height() + line_spacing;
|
||||
int lines_visible = (get_size().y + line_spacing) / font_h;
|
||||
int lines_visible = (get_size().height - get_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h;
|
||||
|
||||
if (lines_visible > line_count)
|
||||
lines_visible = line_count;
|
||||
|
@ -370,7 +373,8 @@ void Label::regenerate_word_cache() {
|
|||
memdelete(current);
|
||||
}
|
||||
|
||||
int width = autowrap ? get_size().width : get_longest_line_width();
|
||||
Ref<StyleBox> style = get_stylebox("normal");
|
||||
int width = autowrap ? (get_size().width - style->get_minimum_size().width) : get_longest_line_width();
|
||||
Ref<Font> font = get_font("font");
|
||||
|
||||
int current_word_size = 0;
|
||||
|
|
|
@ -408,6 +408,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
|||
|
||||
// Label
|
||||
|
||||
theme->set_stylebox("normal", "Label", memnew(StyleBoxEmpty));
|
||||
theme->set_font("font", "Label", default_font);
|
||||
|
||||
theme->set_color("font_color", "Label", Color(1, 1, 1));
|
||||
|
|
Loading…
Reference in a new issue