improve style naming
This commit is contained in:
parent
e8f095bfc4
commit
a4e5d47690
7 changed files with 44 additions and 21 deletions
|
@ -18,7 +18,11 @@ void Button::set_text(std::string text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::on_init() {
|
void Button::on_init() {
|
||||||
set_style_pure(&default_button_style);
|
if (m_button_type == ButtonType::Flat) {
|
||||||
|
set_style_pure(&flat_button_style);
|
||||||
|
} else if (m_button_type == ButtonType::Accent) {
|
||||||
|
set_style_pure(&accent_button_style);
|
||||||
|
}
|
||||||
|
|
||||||
set_did_init(true);
|
set_did_init(true);
|
||||||
if (!fit_text(m_text)) {
|
if (!fit_text(m_text)) {
|
||||||
|
|
|
@ -11,9 +11,15 @@ namespace Raven {
|
||||||
|
|
||||||
class Button : public Widget {
|
class Button : public Widget {
|
||||||
public:
|
public:
|
||||||
Button(std::string text)
|
enum class ButtonType {
|
||||||
|
Flat,
|
||||||
|
Accent
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
Button(std::string text, ButtonType button_type = ButtonType::Flat)
|
||||||
: Widget(WidgetType::Button)
|
: Widget(WidgetType::Button)
|
||||||
, m_text(text) {}
|
, m_text(text)
|
||||||
|
, m_button_type(button_type) {}
|
||||||
|
|
||||||
void set_text(std::string text);
|
void set_text(std::string text);
|
||||||
std::string &text() { return m_text; }
|
std::string &text() { return m_text; }
|
||||||
|
@ -22,6 +28,7 @@ protected:
|
||||||
void on_init();
|
void on_init();
|
||||||
private:
|
private:
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
|
ButtonType m_button_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ void Label::set_text(std::string text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::on_init() {
|
void Label::on_init() {
|
||||||
set_style_pure(&default_label_style);
|
set_style_pure(&flat_label_style);
|
||||||
|
|
||||||
set_did_init(true);
|
set_did_init(true);
|
||||||
if (!fit_text(m_text)) {
|
if (!fit_text(m_text)) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ RGB accent0 = RGB(0x7f465f);
|
||||||
RGB accent1 = RGB(0x995473);
|
RGB accent1 = RGB(0x995473);
|
||||||
RGB accent2 = RGB(0xb16286);
|
RGB accent2 = RGB(0xb16286);
|
||||||
|
|
||||||
GenericStyle default_widget_style {
|
GenericStyle flat_widget_style {
|
||||||
pango_font_description_from_string("sans-serif"),
|
pango_font_description_from_string("sans-serif"),
|
||||||
black6,
|
black6,
|
||||||
white3,
|
white3,
|
||||||
|
@ -36,7 +36,7 @@ GenericStyle default_widget_style {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
GenericStyle accent_widget_style {
|
GenericStyle raised_widget_style {
|
||||||
pango_font_description_from_string("sans-serif"),
|
pango_font_description_from_string("sans-serif"),
|
||||||
black6,
|
black6,
|
||||||
white2,
|
white2,
|
||||||
|
@ -58,7 +58,18 @@ GenericStyle clear_widget_style {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
GenericStyle default_button_style {
|
GenericStyle flat_button_style {
|
||||||
|
pango_font_description_from_string("sans-serif"),
|
||||||
|
black6,
|
||||||
|
white3,
|
||||||
|
white2,
|
||||||
|
white1,
|
||||||
|
5.0,
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
GenericStyle raised_button_style {
|
||||||
pango_font_description_from_string("sans-serif"),
|
pango_font_description_from_string("sans-serif"),
|
||||||
black6,
|
black6,
|
||||||
white2,
|
white2,
|
||||||
|
@ -80,7 +91,7 @@ GenericStyle accent_button_style {
|
||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
GenericStyle default_label_style {
|
GenericStyle flat_label_style {
|
||||||
pango_font_description_from_string("sans-serif"),
|
pango_font_description_from_string("sans-serif"),
|
||||||
black6,
|
black6,
|
||||||
unused,
|
unused,
|
||||||
|
|
|
@ -24,11 +24,12 @@ extern RGB accent0;
|
||||||
extern RGB accent1;
|
extern RGB accent1;
|
||||||
extern RGB accent2;
|
extern RGB accent2;
|
||||||
|
|
||||||
extern GenericStyle default_widget_style;
|
extern GenericStyle flat_widget_style;
|
||||||
extern GenericStyle accent_widget_style;
|
extern GenericStyle raised_widget_style;
|
||||||
extern GenericStyle clear_widget_style;
|
extern GenericStyle clear_widget_style;
|
||||||
extern GenericStyle default_button_style;
|
extern GenericStyle flat_button_style;
|
||||||
|
extern GenericStyle raised_button_style;
|
||||||
extern GenericStyle accent_button_style;
|
extern GenericStyle accent_button_style;
|
||||||
extern GenericStyle default_label_style;
|
extern GenericStyle flat_label_style;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ private:
|
||||||
std::vector<std::shared_ptr<Widget>> m_children;
|
std::vector<std::shared_ptr<Widget>> m_children;
|
||||||
Widget *m_parent { nullptr };
|
Widget *m_parent { nullptr };
|
||||||
Window *m_window { nullptr };
|
Window *m_window { nullptr };
|
||||||
GenericStyle *m_style { &default_widget_style };
|
GenericStyle *m_style { &flat_widget_style };
|
||||||
std::shared_ptr<Layout> m_layout { nullptr };
|
std::shared_ptr<Layout> m_layout { nullptr };
|
||||||
bool m_did_init { false };
|
bool m_did_init { false };
|
||||||
bool m_is_focused { false };
|
bool m_is_focused { false };
|
||||||
|
|
14
src/main.cpp
14
src/main.cpp
|
@ -25,23 +25,23 @@ int main() {
|
||||||
main_layout->slot_pixel(30); // top bar
|
main_layout->slot_pixel(30); // top bar
|
||||||
|
|
||||||
auto top_bar = main_widget->add<Raven::Widget>();
|
auto top_bar = main_widget->add<Raven::Widget>();
|
||||||
top_bar->set_style(&Raven::accent_widget_style);
|
top_bar->set_style(&Raven::raised_widget_style);
|
||||||
top_bar->set_layout<Raven::BoxLayout>(Raven::Direction::Horizontal);
|
top_bar->set_layout<Raven::BoxLayout>(Raven::Direction::Horizontal);
|
||||||
|
|
||||||
auto container_widget = main_widget->add<Raven::Widget>();
|
auto container_widget = main_widget->add<Raven::Widget>();
|
||||||
container_widget->set_layout<Raven::DocumentLayout>();
|
container_widget->set_style(&Raven::raised_widget_style);
|
||||||
|
auto container_widget_layout = container_widget->set_layout<Raven::BoxLayout>(Raven::Direction::Vertical);
|
||||||
|
container_widget_layout->set_margin(24.0);
|
||||||
|
container_widget_layout->set_spacing(8.0);
|
||||||
|
|
||||||
auto new_button = top_bar->add<Raven::Button>("add");
|
auto new_button = top_bar->add<Raven::Button>("add", Raven::Button::ButtonType::Accent);
|
||||||
new_button->rect().set_max_width(50);
|
|
||||||
new_button->on_click = [&window, container_widget]() {
|
new_button->on_click = [&window, container_widget]() {
|
||||||
window.queue_microtask([container_widget]() {
|
window.queue_microtask([container_widget]() {
|
||||||
for (int i = 0; i < 5000; i++) {
|
|
||||||
container_widget->add<Raven::Button>("hello");
|
container_widget->add<Raven::Button>("hello");
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
auto remove_button = top_bar->add<Raven::Button>("remove");
|
auto remove_button = top_bar->add<Raven::Button>("remove", Raven::Button::ButtonType::Flat);
|
||||||
remove_button->on_click = [container_widget]() {
|
remove_button->on_click = [container_widget]() {
|
||||||
container_widget->clear_children();
|
container_widget->clear_children();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue