Skip to content

Instantly share code, notes, and snippets.

@sudara
Last active April 27, 2022 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudara/ea997bdc7c2ff6c9fb32b75cb915d30c to your computer and use it in GitHub Desktop.
Save sudara/ea997bdc7c2ff6c9fb32b75cb915d30c to your computer and use it in GitHub Desktop.
TextEditor, Cursor, and setOpaque
#pragma once
#include "juce_gui_extra/juce_gui_extra.h"
class Modal : public juce::Component
{
public:
Modal()
{
addAndMakeVisible (editor);
editor.setFont (editor.getFont().withPointHeight (50));
editor.setBorder (juce::BorderSize (5));
editor.setOpaque (true);
}
void paint (juce::Graphics& g) override
{
g.setColour (juce::Colours::darkblue.withAlpha (0.8f));
g.fillAll();
}
void resized() override
{
auto area = getLocalBounds();
editor.setBounds (area.reduced (50).removeFromTop (100));
}
private:
juce::TextEditor editor;
};
class Main : public juce::Component
{
public:
void mouseDown (const MouseEvent& event) override
{
repaint();
}
void paint (juce::Graphics& g) override
{
g.setColour ({ (uint8) rng.nextInt (255),
(uint8) rng.nextInt (255),
(uint8) rng.nextInt (255) });
g.fillRect (getLocalBounds());
}
private:
Random rng;
};
class TextEditorPlayground : public juce::Component
{
public:
TextEditorPlayground()
{
addAndMakeVisible (main);
addAndMakeVisible (modal);
}
void paint (juce::Graphics& g) override
{
g.fillAll (juce::Colours::grey);
}
void resized() override
{
auto area = getLocalBounds();
main.setBounds (area);
modal.setBounds (getLocalBounds().reduced (100));
}
private:
Main main;
Modal modal;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment