From 1030e6b84887544063429f141e65c30668165e4f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 20 Mar 2019 22:01:02 +0100 Subject: [PATCH] FileManager: Add a "Location:" label. --- Applications/FileManager/main.cpp | 6 ++++++ LibGUI/GLabel.cpp | 6 ++++++ LibGUI/GLabel.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 2fa31f2dc2..0c4bd56dd6 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,12 @@ int main(int argc, char** argv) auto* main_toolbar = new GToolBar(widget); auto* location_toolbar = new GToolBar(widget); + location_toolbar->layout()->set_margins({ 8, 3, 8, 3 }); location_toolbar->set_preferred_size({ 0, 21 }); + + auto* location_label = new GLabel("Location: ", location_toolbar); + location_label->size_to_fit(); + auto* location_textbox = new GTextEditor(GTextEditor::SingleLine, location_toolbar); auto* directory_table_view = new DirectoryTableView(widget); diff --git a/LibGUI/GLabel.cpp b/LibGUI/GLabel.cpp index c674a674a6..dea72b00f3 100644 --- a/LibGUI/GLabel.cpp +++ b/LibGUI/GLabel.cpp @@ -43,3 +43,9 @@ void GLabel::paint_event(GPaintEvent& event) if (!text().is_empty()) painter.draw_text({ 0, 0, width(), height() }, text(), m_text_alignment, foreground_color()); } + +void GLabel::size_to_fit() +{ + set_size_policy(SizePolicy::Fixed, SizePolicy::Fill); + set_preferred_size({ font().width(m_text), 0 }); +} diff --git a/LibGUI/GLabel.h b/LibGUI/GLabel.h index 1b886c7981..ff65ded4b1 100644 --- a/LibGUI/GLabel.h +++ b/LibGUI/GLabel.h @@ -22,6 +22,8 @@ public: TextAlignment text_alignment() const { return m_text_alignment; } void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; } + void size_to_fit(); + virtual const char* class_name() const override { return "GLabel"; } private: